blob: 41a6e2ba7e6929684a1047ff5e475f234cf7efe4 [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;
Craig Mautner59c00972012-07-30 12:10:24 -0700157
Robert Carr3b716242016-08-16 16:02:21 -0700158import java.io.FileDescriptor;
Craig Mautner59c00972012-07-30 12:10:24 -0700159import java.io.PrintWriter;
160import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700161import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700162import java.util.HashMap;
163import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700164import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700165import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100166import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800167import java.util.function.Consumer;
168import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700169
Craig Mautner59c00972012-07-30 12:10:24 -0700170/**
171 * Utility class for keeping track of the WindowStates and other pertinent contents of a
172 * particular Display.
173 *
174 * IMPORTANT: No method from this class should ever be used without holding
175 * WindowManagerService.mWindowMap.
176 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700177class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700178 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700179
180 /** Unique identifier of this stack. */
181 private final int mDisplayId;
182
Wale Ogunwale3a931692016-11-02 16:49:48 -0700183 /** The containers below are the only child containers the display can have. */
184 // Contains all window containers that are related to apps (Activities)
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100185 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700186 // Contains all non-app window containers that should be displayed above the app containers
187 // (e.g. Status bar)
Robert Carree4d4b92017-11-22 12:21:46 -0800188 private final AboveAppWindowContainers mAboveAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100189 new AboveAppWindowContainers("mAboveAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700190 // Contains all non-app window containers that should be displayed below the app containers
191 // (e.g. Wallpaper).
192 private final NonAppWindowContainers mBelowAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100193 new NonAppWindowContainers("mBelowAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700194 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
195 // on the IME target. We mainly have this container grouping so we can keep track of all the IME
Robert Carr9034d962018-01-04 18:27:42 -0800196 // window containers together and move them in-sync if/when needed. We use a subclass of
197 // WindowContainer which is omitted from screen magnification, as the IME is never magnified.
198 private final NonMagnifiableWindowContainers mImeWindowsContainers =
199 new NonMagnifiableWindowContainers("mImeWindowsContainers", mService);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700200
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000201 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800202 private WindowState mTmpWindow2;
203 private WindowAnimator mTmpWindowAnimator;
204 private boolean mTmpRecoveringMemory;
205 private boolean mUpdateImeTarget;
206 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700207 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700208
Wale Ogunwale02319a62016-09-26 15:21:22 -0700209 // Mapping from a token IBinder to a WindowToken object on this display.
210 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
211
Andrii Kuliancd097992017-03-23 18:31:59 -0700212 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700213 int mInitialDisplayWidth = 0;
214 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700215 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700216
Adrian Roos1cf585052018-01-03 18:43:27 +0100217 DisplayCutout mInitialDisplayCutout;
218 DisplayCutout mDisplayCutoutOverride;
219
Andrii Kuliancd097992017-03-23 18:31:59 -0700220 /**
221 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
222 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
223 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
224 */
Craig Mautner59c00972012-07-30 12:10:24 -0700225 int mBaseDisplayWidth = 0;
226 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700227 /**
228 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
229 * but can be set from Settings or via shell command "adb shell wm density".
230 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
231 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700232 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700233 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700234 private final DisplayInfo mDisplayInfo = new DisplayInfo();
235 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700236 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000237 DisplayFrames mDisplayFrames;
238
Andrii Kulian06d07d62017-03-14 11:11:47 -0700239 /**
240 * For default display it contains real metrics, empty for others.
241 * @see WindowManagerService#createWatermarkInTransaction()
242 */
243 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
244 /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */
245 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700246
Andrii Kulian06d07d62017-03-14 11:11:47 -0700247 /**
248 * Compat metrics computed based on {@link #mDisplayMetrics}.
249 * @see #updateDisplayAndOrientation(int)
250 */
251 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
252
253 /** The desired scaling factor for compatible apps. */
254 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700255
Andrii Kulian8ee72852017-03-10 10:36:45 -0800256 /**
257 * Current rotation of the display.
258 * Constants as per {@link android.view.Surface.Rotation}.
259 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700260 * @see #updateRotationUnchecked(boolean)
Andrii Kulian8ee72852017-03-10 10:36:45 -0800261 */
262 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700263
Andrii Kulian8ee72852017-03-10 10:36:45 -0800264 /**
265 * Last applied orientation of the display.
266 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
267 *
268 * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int)
269 */
270 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700271
Andrii Kulian8ee72852017-03-10 10:36:45 -0800272 /**
273 * Flag indicating that the application is receiving an orientation that has different metrics
274 * than it expected. E.g. Portrait instead of Landscape.
275 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700276 * @see #updateRotationUnchecked(boolean)
Andrii Kulian8ee72852017-03-10 10:36:45 -0800277 */
278 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700279
Andrii Kulian8ee72852017-03-10 10:36:45 -0800280 /**
281 * Orientation forced by some window. If there is no visible window that specifies orientation
282 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
283 *
284 * @see NonAppWindowContainers#getOrientation()
285 */
286 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700287
Andrii Kulian8ee72852017-03-10 10:36:45 -0800288 /**
289 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
290 * occluded.
291 *
292 * @see NonAppWindowContainers#getOrientation()
293 */
294 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
295
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700296 /**
297 * Keep track of wallpaper visibility to notify changes.
298 */
299 private boolean mLastWallpaperVisible = false;
300
Andrii Kulian06d07d62017-03-14 11:11:47 -0700301 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700302
Craig Mautner39834192012-09-02 07:47:24 -0700303 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700304 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700305 int pendingLayoutChanges;
Andrii Kulian839def92016-11-02 10:58:58 -0700306 // TODO(multi-display): remove some of the usages.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800307 boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700308
Craig Mautnerdc548482014-02-05 13:35:24 -0800309 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700310 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800311
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700312 /** Detect user tapping outside of current focused task bounds .*/
313 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700314
Craig Mautner6601b7b2013-04-29 10:29:11 -0700315 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700316 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700317
Craig Mautner6601b7b2013-04-29 10:29:11 -0700318 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800319 private final Rect mTmpRect = new Rect();
320 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700321 private final RectF mTmpRectF = new RectF();
322 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800323 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700324
Bryce Leef3c6a472017-11-14 14:53:06 -0800325 /** Used for handing back size of display */
326 private final Rect mTmpBounds = new Rect();
327
Craig Mautner95da1082014-02-24 17:54:35 -0800328 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700329 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800330
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700331 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700332 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700333
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800334 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800335 /** A collection of windows that provide tap exclude regions inside of them. */
336 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800337
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000338 private boolean mHaveBootMsg = false;
339 private boolean mHaveApp = false;
340 private boolean mHaveWallpaper = false;
341 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700342
343 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
344
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700345 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
346 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000347 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
348 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700349
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700350 // True if this display is in the process of being removed. Used to determine if the removal of
351 // the display's direct children should be allowed.
352 private boolean mRemovingDisplay = false;
353
Bryce Leed1871262017-06-12 14:12:29 -0700354 // {@code false} if this display is in the processing of being created.
355 private boolean mDisplayReady = false;
356
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800357 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700358
Robert Carrb1579c82017-09-05 14:54:47 -0700359 private final SurfaceSession mSession = new SurfaceSession();
360
361 /**
362 * We organize all top-level Surfaces in to the following layers.
363 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800364 * and omitted from Screen-Magnification, for example the strict mode flash or
365 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700366 * {@link #mWindowingLayer} contains everything else.
367 */
368 private SurfaceControl mOverlayLayer;
369
370 /**
371 * See {@link #mOverlayLayer}
372 */
373 private SurfaceControl mWindowingLayer;
374
375 /**
376 * Specifies the size of the surfaces in {@link #mOverlayLayer} and {@link #mWindowingLayer}.
377 * <p>
378 * For these surfaces currently we use a surface based on the larger of width or height so we
379 * don't have to resize when rotating the display.
380 */
381 private int mSurfaceSize;
382
Chavi Weingarten38804382018-02-15 21:00:15 +0000383 /**
384 * A list of surfaces to be destroyed after {@link #mPendingTransaction} is applied.
385 */
386 private final ArrayList<SurfaceControl> mPendingDestroyingSurfaces = new ArrayList<>();
387
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100388 /** Temporary float array to retrieve 3x3 matrix values. */
389 private final float[] mTmpFloats = new float[9];
390
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800391 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
392 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800393 final AppWindowToken atoken = w.mAppToken;
394 if (winAnimator.mDrawState == READY_TO_SHOW) {
395 if (atoken == null || atoken.allDrawn) {
396 if (w.performShowLocked()) {
397 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
398 if (DEBUG_LAYOUT_REPEATS) {
399 mService.mWindowPlacerLocked.debugLayoutRepeats(
400 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
401 }
402 }
403 }
404 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800405 };
406
407 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
408 final WindowStateAnimator winAnimator = w.mWinAnimator;
409 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
410 return;
411 }
412
413 final int flags = w.mAttrs.flags;
414
415 // If this window is animating, make a note that we have an animating window and take
416 // care of a request to run a detached wallpaper animation.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100417 if (winAnimator.isAnimationSet()) {
418 final AnimationAdapter anim = w.getAnimation();
419 if (anim != null) {
420 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && anim.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800421 mTmpWindow = w;
422 }
Jorim Jaggia5e10572017-11-15 14:36:26 +0100423 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800424 if (color != 0) {
425 final TaskStack stack = w.getStack();
426 if (stack != null) {
427 stack.setAnimationBackground(winAnimator, color);
428 }
429 }
430 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800431 }
432
433 // If this window's app token is running a detached wallpaper animation, make a note so
434 // we can ensure the wallpaper is displayed behind it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200435 final AppWindowToken atoken = winAnimator.mWin.mAppToken;
436 final AnimationAdapter animation = atoken != null ? atoken.getAnimation() : null;
437 if (animation != null) {
438 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && animation.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800439 mTmpWindow = w;
440 }
441
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200442 final int color = animation.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800443 if (color != 0) {
444 final TaskStack stack = w.getStack();
445 if (stack != null) {
446 stack.setAnimationBackground(winAnimator, color);
447 }
448 }
449 }
450 };
451
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800452 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
453 final int lostFocusUid = mTmpWindow.mOwnerUid;
454 final Handler handler = mService.mH;
455 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
456 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
457 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
458 w.mAttrs.hideTimeoutMilliseconds);
459 }
460 }
461 };
462
463 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
464 final AppWindowToken focusedApp = mService.mFocusedApp;
465 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
466 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
467
468 if (!w.canReceiveKeys()) {
469 return false;
470 }
471
472 final AppWindowToken wtoken = w.mAppToken;
473
474 // If this window's application has been removed, just skip it.
475 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
476 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
477 + (wtoken.removed ? "removed" : "sendingToBottom"));
478 return false;
479 }
480
481 if (focusedApp == null) {
482 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
483 + " using new focus @ " + w);
484 mTmpWindow = w;
485 return true;
486 }
487
488 if (!focusedApp.windowsAreFocusable()) {
489 // Current focused app windows aren't focusable...
490 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
491 + " focusable using new focus @ " + w);
492 mTmpWindow = w;
493 return true;
494 }
495
496 // Descend through all of the app tokens and find the first that either matches
497 // win.mAppToken (return win) or mFocusedApp (return null).
498 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
499 if (focusedApp.compareTo(wtoken) > 0) {
500 // App stack below focused app stack. No focus for you!!!
501 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
502 "findFocusedWindow: Reached focused app=" + focusedApp);
503 mTmpWindow = null;
504 return true;
505 }
506 }
507
508 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
509 mTmpWindow = w;
510 return true;
511 };
512
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800513 private final Consumer<WindowState> mPerformLayout = w -> {
514 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
515 // wasting time and funky changes while a window is animating away.
516 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
517 || w.isGoneForLayoutLw();
518
519 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
520 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
521 + " mLayoutAttached=" + w.mLayoutAttached
522 + " screen changed=" + w.isConfigChanged());
523 final AppWindowToken atoken = w.mAppToken;
524 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200525 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800526 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
527 + " parentHidden=" + w.isParentWindowHidden());
528 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200529 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800530 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
531 + " parentHidden=" + w.isParentWindowHidden());
532 }
533
534 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
535 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
536 // since that means "perform layout as normal, just don't display").
537 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
538 || ((w.isConfigChanged() || w.setReportResizeHints())
539 && !w.isGoneForLayoutLw() &&
540 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
541 (w.mHasSurface && w.mAppToken != null &&
542 w.mAppToken.layoutConfigChanges)))) {
543 if (!w.mLayoutAttached) {
544 if (mTmpInitial) {
545 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
546 w.mContentChanged = false;
547 }
548 if (w.mAttrs.type == TYPE_DREAM) {
549 // Don't layout windows behind a dream, so that if it does stuff like hide
550 // the status bar we won't get a bad transition when it goes away.
551 mTmpWindow = w;
552 }
553 w.mLayoutNeeded = false;
554 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200555 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000556 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800557 w.mLayoutSeq = mService.mLayoutSeq;
558
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200559 // If this is the first layout, we need to initialize the last inset values as
560 // otherwise we'd immediately cause an unnecessary resize.
561 if (firstLayout) {
562 w.updateLastInsetValues();
563 }
564
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800565 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
566 + " mContainingFrame=" + w.mContainingFrame
567 + " mDisplayFrame=" + w.mDisplayFrame);
568 }
569 }
570 };
571
572 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
573 if (w.mLayoutAttached) {
574 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
575 + " mViewVisibility=" + w.mViewVisibility
576 + " mRelayoutCalled=" + w.mRelayoutCalled);
577 // If this view is GONE, then skip it -- keep the current frame, and let the caller
578 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
579 // windows, since that means "perform layout as normal, just don't display").
580 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
581 return;
582 }
583 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
584 || w.mLayoutNeeded) {
585 if (mTmpInitial) {
586 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
587 w.mContentChanged = false;
588 }
589 w.mLayoutNeeded = false;
590 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000591 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800592 w.mLayoutSeq = mService.mLayoutSeq;
593 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
594 + " mContainingFrame=" + w.mContainingFrame
595 + " mDisplayFrame=" + w.mDisplayFrame);
596 }
597 } else if (w.mAttrs.type == TYPE_DREAM) {
598 // Don't layout windows behind a dream, so that if it does stuff like hide the
599 // status bar we won't get a bad transition when it goes away.
600 mTmpWindow = mTmpWindow2;
601 }
602 };
603
604 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
605 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
606 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
607 return w.canBeImeTarget();
608 };
609
610 private final Consumer<WindowState> mApplyPostLayoutPolicy =
611 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
612 mService.mInputMethodTarget);
613
614 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
615 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
616 final boolean obscuredChanged = w.mObscured !=
617 mTmpApplySurfaceChangesTransactionState.obscured;
618 final RootWindowContainer root = mService.mRoot;
619 // Only used if default window
620 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
621
622 // Update effect.
623 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
624 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
625 final boolean isDisplayed = w.isDisplayedLw();
626
627 if (isDisplayed && w.isObscuringDisplay()) {
628 // This window completely covers everything behind it, so we want to leave all
629 // of them as undimmed (for performance reasons).
630 root.mObscuringWindow = w;
631 mTmpApplySurfaceChangesTransactionState.obscured = true;
632 }
633
634 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
635 root.handleNotObscuredLocked(w,
636 mTmpApplySurfaceChangesTransactionState.obscured,
637 mTmpApplySurfaceChangesTransactionState.syswin);
638
639 if (w.mHasSurface && isDisplayed) {
640 final int type = w.mAttrs.type;
641 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
642 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
643 mTmpApplySurfaceChangesTransactionState.syswin = true;
644 }
645 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
646 && w.mAttrs.preferredRefreshRate != 0) {
647 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
648 = w.mAttrs.preferredRefreshRate;
649 }
650 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
651 && w.mAttrs.preferredDisplayModeId != 0) {
652 mTmpApplySurfaceChangesTransactionState.preferredModeId
653 = w.mAttrs.preferredDisplayModeId;
654 }
655 }
656 }
657
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800658 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
659 && mWallpaperController.isWallpaperTarget(w)) {
660 // This is the wallpaper target and its obscured state changed... make sure the
661 // current wallpaper's visibility has been updated accordingly.
662 mWallpaperController.updateWallpaperVisibility();
663 }
664
chaviw161ea3e2018-01-31 12:01:12 -0800665 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800666
667 final WindowStateAnimator winAnimator = w.mWinAnimator;
668
669 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
670 w.mContentChanged = false;
671
672 // Moved from updateWindowsAndWallpaperLocked().
673 if (w.mHasSurface) {
674 // Take care of the window being ready to display.
675 final boolean committed = winAnimator.commitFinishDrawingLocked();
676 if (isDefaultDisplay && committed) {
677 if (w.mAttrs.type == TYPE_DREAM) {
678 // HACK: When a dream is shown, it may at that point hide the lock screen.
679 // So we need to redo the layout to let the phone window manager make this
680 // happen.
681 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
682 if (DEBUG_LAYOUT_REPEATS) {
683 surfacePlacer.debugLayoutRepeats(
684 "dream and commitFinishDrawingLocked true",
685 pendingLayoutChanges);
686 }
687 }
688 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
689 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
690 "First draw done in potential wallpaper target " + w);
691 root.mWallpaperMayChange = true;
692 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
693 if (DEBUG_LAYOUT_REPEATS) {
694 surfacePlacer.debugLayoutRepeats(
695 "wallpaper and commitFinishDrawingLocked true",
696 pendingLayoutChanges);
697 }
698 }
699 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800700 }
701
702 final AppWindowToken atoken = w.mAppToken;
703 if (atoken != null) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100704 atoken.updateLetterbox(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800705 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
706 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
707 mTmpUpdateAllDrawn.add(atoken);
708 }
709 }
710
711 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
712 && w.isDisplayedLw()) {
713 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
714 }
715
716 w.updateResizingWindowIfNeeded();
717 };
718
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800719 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800720 * Create new {@link DisplayContent} instance, add itself to the root window container and
721 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700722 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800723 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700724 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
725 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700726 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700727 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800728 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100729 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800730 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800731 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
732 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
733 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
734 + " new=" + display);
735 }
736
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700737 mDisplay = display;
738 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700739 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700740 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700741 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700742 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000743 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700744 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800745 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700746 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700747
Robert Carrb1579c82017-09-05 14:54:47 -0700748 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth);
749
750 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
751 .setSize(mSurfaceSize, mSurfaceSize)
752 .setOpaque(true);
753 mWindowingLayer = b.setName("Display Root").build();
754 mOverlayLayer = b.setName("Display Overlays").build();
755
Robert Carrf59b8dd2017-10-02 18:58:36 -0700756 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700757 .setLayerStack(mWindowingLayer, mDisplayId)
758 .show(mWindowingLayer)
759 .setLayer(mOverlayLayer, 1)
760 .setLayerStack(mOverlayLayer, mDisplayId)
761 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700762 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700763
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700764 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700765 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700766 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700767 super.addChild(mAboveAppWindowsContainers, null);
768 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800769
770 // Add itself as a child to the root container.
771 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700772
773 // TODO(b/62541591): evaluate whether this is the best spot to declare the
774 // {@link DisplayContent} ready for use.
775 mDisplayReady = true;
776 }
777
778 boolean isReady() {
779 // The display is ready when the system and the individual display are both ready.
780 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700781 }
782
783 int getDisplayId() {
784 return mDisplayId;
785 }
786
Wale Ogunwale02319a62016-09-26 15:21:22 -0700787 WindowToken getWindowToken(IBinder binder) {
788 return mTokenMap.get(binder);
789 }
790
791 AppWindowToken getAppWindowToken(IBinder binder) {
792 final WindowToken token = getWindowToken(binder);
793 if (token == null) {
794 return null;
795 }
796 return token.asAppWindowToken();
797 }
798
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700799 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700800 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
801 if (dc != null) {
802 // We currently don't support adding a window token to the display if the display
803 // already has the binder mapped to another token. If there is a use case for supporting
804 // this moving forward we will either need to merge the WindowTokens some how or have
805 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700806 throw new IllegalArgumentException("Can't map token=" + token + " to display="
807 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700808 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700809 if (binder == null) {
810 throw new IllegalArgumentException("Can't map token=" + token + " to display="
811 + getName() + " binder is null");
812 }
813 if (token == null) {
814 throw new IllegalArgumentException("Can't map null token to display="
815 + getName() + " binder=" + binder);
816 }
817
Wale Ogunwale02319a62016-09-26 15:21:22 -0700818 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700819
820 if (token.asAppWindowToken() == null) {
821 // Add non-app token to container hierarchy on the display. App tokens are added through
822 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700823 switch (token.windowType) {
824 case TYPE_WALLPAPER:
825 mBelowAppWindowsContainers.addChild(token);
826 break;
827 case TYPE_INPUT_METHOD:
828 case TYPE_INPUT_METHOD_DIALOG:
829 mImeWindowsContainers.addChild(token);
830 break;
831 default:
832 mAboveAppWindowsContainers.addChild(token);
833 break;
834 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700835 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700836 }
837
838 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700839 final WindowToken token = mTokenMap.remove(binder);
840 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800841 token.setExiting();
842 }
843 return token;
844 }
845
846 /** Changes the display the input window token is housed on to this one. */
847 void reParentWindowToken(WindowToken token) {
848 final DisplayContent prevDc = token.getDisplayContent();
849 if (prevDc == this) {
850 return;
851 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800852 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
853 && token.asAppWindowToken() == null) {
854 // Removed the token from the map, but made sure it's not an app token before removing
855 // from parent.
856 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700857 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800858
859 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700860 }
861
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700862 void removeAppToken(IBinder binder) {
863 final WindowToken token = removeWindowToken(binder);
864 if (token == null) {
865 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
866 return;
867 }
868
869 final AppWindowToken appToken = token.asAppWindowToken();
870
871 if (appToken == null) {
872 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
873 return;
874 }
875
876 appToken.onRemovedFromDisplay();
877 }
878
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700879 Display getDisplay() {
880 return mDisplay;
881 }
882
Craig Mautner59c00972012-07-30 12:10:24 -0700883 DisplayInfo getDisplayInfo() {
884 return mDisplayInfo;
885 }
886
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700887 DisplayMetrics getDisplayMetrics() {
888 return mDisplayMetrics;
889 }
890
Andrii Kulian8ee72852017-03-10 10:36:45 -0800891 int getRotation() {
892 return mRotation;
893 }
894
895 void setRotation(int newRotation) {
896 mRotation = newRotation;
897 }
898
899 int getLastOrientation() {
900 return mLastOrientation;
901 }
902
903 void setLastOrientation(int orientation) {
904 mLastOrientation = orientation;
905 }
906
907 boolean getAltOrientation() {
908 return mAltOrientation;
909 }
910
911 void setAltOrientation(boolean altOrientation) {
912 mAltOrientation = altOrientation;
913 }
914
915 int getLastWindowForcedOrientation() {
916 return mLastWindowForcedOrientation;
917 }
918
Andrii Kulian06d07d62017-03-14 11:11:47 -0700919 /**
920 * Update rotation of the display.
921 *
922 * Returns true if the rotation has been changed. In this case YOU MUST CALL
923 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
924 */
925 boolean updateRotationUnchecked(boolean inTransaction) {
926 if (mService.mDeferredRotationPauseCount > 0) {
927 // Rotation updates have been paused temporarily. Defer the update until
928 // updates have been resumed.
929 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
930 return false;
931 }
932
933 ScreenRotationAnimation screenRotationAnimation =
934 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
935 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
936 // Rotation updates cannot be performed while the previous rotation change
937 // animation is still in progress. Skip this update. We will try updating
938 // again after the animation is finished and the display is unfrozen.
939 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
940 return false;
941 }
942 if (mService.mDisplayFrozen) {
943 // Even if the screen rotation animation has finished (e.g. isAnimating
944 // returns false), there is still some time where we haven't yet unfrozen
945 // the display. We also need to abort rotation here.
946 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
947 "Deferring rotation, still finishing previous rotation");
948 return false;
949 }
950
951 if (!mService.mDisplayEnabled) {
952 // No point choosing a rotation if the display is not enabled.
953 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
954 return false;
955 }
956
957 final int oldRotation = mRotation;
958 final int lastOrientation = mLastOrientation;
959 final boolean oldAltOrientation = mAltOrientation;
960 int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation);
Robert Carr0e007272017-10-02 13:00:55 -0700961 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation,
Robert Carr897215d2017-03-29 12:25:50 -0700962 rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -0700963
Robert Carr0e007272017-10-02 13:00:55 -0700964 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700965 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
966 if (seamlessRotated != null) {
967 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
968 // to complete (that is, waiting for windows to redraw). It's tempting to check
969 // w.mSeamlessRotationCount but that could be incorrect in the case of
970 // window-removal.
971 return false;
972 }
Robert Carr0e007272017-10-02 13:00:55 -0700973
974 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700975 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -0700976 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -0700977 mayRotateSeamlessly = false;
978 }
979 for (int i = 0; i < mService.mSessions.size(); i++) {
980 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
981 mayRotateSeamlessly = false;
982 break;
983 }
984 }
Andrii Kulian06d07d62017-03-14 11:11:47 -0700985 }
Robert Carr0e007272017-10-02 13:00:55 -0700986 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700987
988 // TODO: Implement forced rotation changes.
989 // Set mAltOrientation to indicate that the application is receiving
990 // an orientation that has different metrics than it expected.
991 // eg. Portrait instead of Landscape.
992
993 final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw(
994 lastOrientation, rotation);
995
996 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Selected orientation " + lastOrientation
997 + ", got rotation " + rotation + " which has "
998 + (altOrientation ? "incompatible" : "compatible") + " metrics");
999
1000 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1001 // No change.
1002 return false;
1003 }
1004
1005 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Rotation changed to " + rotation
1006 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1007 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1008
1009 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1010 mService.mWaitingForConfig = true;
1011 }
1012
1013 mRotation = rotation;
1014 mAltOrientation = altOrientation;
1015 if (isDefaultDisplay) {
1016 mService.mPolicy.setRotationLw(rotation);
1017 }
1018
1019 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1020 mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
1021 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1022 WINDOW_FREEZE_TIMEOUT_DURATION);
1023
1024 setLayoutNeeded();
1025 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001026 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001027
1028 if (!rotateSeamlessly) {
Bryce Lee8f853582017-06-05 17:25:59 -07001029 mService.startFreezingDisplayLocked(inTransaction, anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001030 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1031 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1032 mDisplayId);
1033 } else {
1034 // The screen rotation animation uses a screenshot to freeze the screen
1035 // while windows resize underneath.
1036 // When we are rotating seamlessly, we allow the elements to transition
1037 // to their rotated state independently and without a freeze required.
1038 screenRotationAnimation = null;
1039
1040 // We have to reset this in case a window was removed before it
1041 // finished seamless rotation.
1042 mService.mSeamlessRotationCount = 0;
1043 }
1044
1045 // We need to update our screen size information to match the new rotation. If the rotation
1046 // has actually changed then this method will return true and, according to the comment at
1047 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1048 // By updating the Display info here it will be available to
1049 // #computeScreenConfiguration() later.
1050 updateDisplayAndOrientation(getConfiguration().uiMode);
1051
1052 if (!inTransaction) {
1053 if (SHOW_TRANSACTIONS) {
1054 Slog.i(TAG_WM, ">>> OPEN TRANSACTION setRotationUnchecked");
1055 }
1056 mService.openSurfaceTransaction();
1057 }
1058 try {
1059 // NOTE: We disable the rotation in the emulator because
1060 // it doesn't support hardware OpenGL emulation yet.
1061 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1062 && screenRotationAnimation.hasScreenshot()) {
Robert Carrb1579c82017-09-05 14:54:47 -07001063 if (screenRotationAnimation.setRotationInTransaction(rotation,
Andrii Kulian06d07d62017-03-14 11:11:47 -07001064 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1065 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1066 mService.scheduleAnimationLocked();
1067 }
1068 }
1069
1070 if (rotateSeamlessly) {
1071 forAllWindows(w -> {
1072 w.mWinAnimator.seamlesslyRotateWindow(oldRotation, rotation);
1073 }, true /* traverseTopToBottom */);
1074 }
1075
1076 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
1077 } finally {
1078 if (!inTransaction) {
Adrian Roos111aff92017-09-27 18:11:46 +02001079 mService.closeSurfaceTransaction("setRotationUnchecked");
Andrii Kulian06d07d62017-03-14 11:11:47 -07001080 if (SHOW_LIGHT_TRANSACTIONS) {
1081 Slog.i(TAG_WM, "<<< CLOSE TRANSACTION setRotationUnchecked");
1082 }
1083 }
1084 }
1085
1086 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001087 if (w.mHasSurface && !rotateSeamlessly) {
1088 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001089 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001090 mService.mRoot.mOrientationChangeComplete = false;
1091 w.mLastFreezeDuration = 0;
1092 }
1093 w.mReportOrientationChanged = true;
1094 }, true /* traverseTopToBottom */);
1095
1096 if (rotateSeamlessly) {
1097 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1098 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1099 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1100 }
1101
1102 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1103 final WindowManagerService.RotationWatcher rotationWatcher
1104 = mService.mRotationWatchers.get(i);
1105 if (rotationWatcher.mDisplayId == mDisplayId) {
1106 try {
1107 rotationWatcher.mWatcher.onRotationChanged(rotation);
1108 } catch (RemoteException e) {
1109 // Ignore
1110 }
1111 }
1112 }
1113
1114 // TODO (multi-display): Magnification is supported only for the default display.
1115 // Announce rotation only if we will not animate as we already have the
1116 // windows in final state. Otherwise, we make this call at the rotation end.
1117 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1118 && isDefaultDisplay) {
1119 mService.mAccessibilityController.onRotationChangedLocked(this);
1120 }
1121
1122 return true;
1123 }
1124
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001125 void configureDisplayPolicy() {
1126 mService.mPolicy.setInitialDisplaySize(getDisplay(),
1127 mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1128
1129 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
1130 }
1131
Andrii Kulian06d07d62017-03-14 11:11:47 -07001132 /**
1133 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1134 * changed.
1135 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1136 */
1137 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1138 // Use the effective "visual" dimensions based on current rotation
1139 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1140 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1141 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1142 int dw = realdw;
1143 int dh = realdh;
1144
1145 if (mAltOrientation) {
1146 if (realdw > realdh) {
1147 // Turn landscape into portrait.
1148 int maxw = (int)(realdh/1.3f);
1149 if (maxw < realdw) {
1150 dw = maxw;
1151 }
1152 } else {
1153 // Turn portrait into landscape.
1154 int maxh = (int)(realdw/1.3f);
1155 if (maxh < realdh) {
1156 dh = maxh;
1157 }
1158 }
1159 }
1160
1161 // Update application display metrics.
1162 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
1163 mDisplayId);
1164 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
1165 mDisplayId);
1166 mDisplayInfo.rotation = mRotation;
1167 mDisplayInfo.logicalWidth = dw;
1168 mDisplayInfo.logicalHeight = dh;
1169 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1170 mDisplayInfo.appWidth = appWidth;
1171 mDisplayInfo.appHeight = appHeight;
1172 if (isDefaultDisplay) {
1173 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1174 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1175 }
Adrian Roos1cf585052018-01-03 18:43:27 +01001176 mDisplayInfo.displayCutout = calculateDisplayCutoutForCurrentRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001177 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1178 if (mDisplayScalingDisabled) {
1179 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1180 } else {
1181 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1182 }
1183
1184 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
1185 mDisplayInfo);
1186
1187 mBaseDisplayRect.set(0, 0, dw, dh);
1188
1189 if (isDefaultDisplay) {
1190 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1191 mCompatDisplayMetrics);
1192 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001193
1194 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001195 return mDisplayInfo;
1196 }
1197
Adrian Roos1cf585052018-01-03 18:43:27 +01001198 DisplayCutout calculateDisplayCutoutForCurrentRotation() {
1199 final DisplayCutout cutout = mInitialDisplayCutout;
1200 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT || mRotation == ROTATION_0) {
1201 return cutout;
1202 }
1203 final Path bounds = cutout.getBounds().getBoundaryPath();
1204 transformPhysicalToLogicalCoordinates(mRotation, mInitialDisplayWidth,
1205 mInitialDisplayHeight, mTmpMatrix);
1206 bounds.transform(mTmpMatrix);
1207 return DisplayCutout.fromBounds(bounds);
1208 }
1209
Andrii Kulian06d07d62017-03-14 11:11:47 -07001210 /**
1211 * Compute display configuration based on display properties and policy settings.
1212 * Do not call if mDisplayReady == false.
1213 */
1214 void computeScreenConfiguration(Configuration config) {
1215 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1216
1217 final int dw = displayInfo.logicalWidth;
1218 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001219 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
1220 // TODO: Probably best to set this based on some setting in the display content object,
1221 // so the display can be configured for things like fullscreen.
1222 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001223
Andrii Kulian06d07d62017-03-14 11:11:47 -07001224 config.screenWidthDp =
1225 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
1226 config.uiMode, mDisplayId) / mDisplayMetrics.density);
1227 config.screenHeightDp =
1228 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
1229 config.uiMode, mDisplayId) / mDisplayMetrics.density);
Bryce Lee7566d762017-03-30 09:34:15 -07001230
1231 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh, mTmpRect);
1232 final int leftInset = mTmpRect.left;
1233 final int topInset = mTmpRect.top;
1234 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001235 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1236 leftInset + displayInfo.appWidth /* right */,
1237 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001238 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1239 || displayInfo.rotation == Surface.ROTATION_270);
1240
1241 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
1242 mDisplayMetrics.density, config);
1243
1244 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1245 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1246 ? Configuration.SCREENLAYOUT_ROUND_YES
1247 : Configuration.SCREENLAYOUT_ROUND_NO);
1248
1249 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1250 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1251 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1252 dh, mDisplayId);
1253 config.densityDpi = displayInfo.logicalDensityDpi;
1254
1255 config.colorMode =
1256 (displayInfo.isHdr()
1257 ? Configuration.COLOR_MODE_HDR_YES
1258 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001259 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001260 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1261 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1262
1263 // Update the configuration based on available input devices, lid switch,
1264 // and platform configuration.
1265 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1266 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1267 config.navigation = Configuration.NAVIGATION_NONAV;
1268
1269 int keyboardPresence = 0;
1270 int navigationPresence = 0;
1271 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1272 final int len = devices != null ? devices.length : 0;
1273 for (int i = 0; i < len; i++) {
1274 InputDevice device = devices[i];
1275 if (!device.isVirtual()) {
1276 final int sources = device.getSources();
1277 final int presenceFlag = device.isExternal() ?
1278 WindowManagerPolicy.PRESENCE_EXTERNAL :
1279 WindowManagerPolicy.PRESENCE_INTERNAL;
1280
1281 // TODO(multi-display): Configure on per-display basis.
1282 if (mService.mIsTouchDevice) {
1283 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1284 InputDevice.SOURCE_TOUCHSCREEN) {
1285 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1286 }
1287 } else {
1288 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1289 }
1290
1291 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1292 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1293 navigationPresence |= presenceFlag;
1294 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1295 && config.navigation == Configuration.NAVIGATION_NONAV) {
1296 config.navigation = Configuration.NAVIGATION_DPAD;
1297 navigationPresence |= presenceFlag;
1298 }
1299
1300 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1301 config.keyboard = Configuration.KEYBOARD_QWERTY;
1302 keyboardPresence |= presenceFlag;
1303 }
1304 }
1305 }
1306
1307 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1308 config.navigation = Configuration.NAVIGATION_DPAD;
1309 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1310 }
1311
1312 // Determine whether a hard keyboard is available and enabled.
1313 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1314 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1315 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1316 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1317 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1318 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1319 }
1320
1321 // Let the policy update hidden states.
1322 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1323 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1324 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1325 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1326 }
1327
1328 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1329 int displayId) {
1330 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1331 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1332 final int unrotDw, unrotDh;
1333 if (rotated) {
1334 unrotDw = dh;
1335 unrotDh = dw;
1336 } else {
1337 unrotDw = dw;
1338 unrotDh = dh;
1339 }
1340 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1341 displayId);
1342 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1343 displayId);
1344 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1345 displayId);
1346 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1347 displayId);
1348 return sw;
1349 }
1350
1351 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1352 DisplayMetrics dm, int dw, int dh, int displayId) {
1353 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
1354 displayId);
1355 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
1356 uiMode, displayId);
1357 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1358 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1359 if (curSize == 0 || size < curSize) {
1360 curSize = size;
1361 }
1362 return curSize;
1363 }
1364
1365 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1366 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1367
1368 // We need to determine the smallest width that will occur under normal
1369 // operation. To this, start with the base screen size and compute the
1370 // width under the different possible rotations. We need to un-rotate
1371 // the current screen dimensions before doing this.
1372 int unrotDw, unrotDh;
1373 if (rotated) {
1374 unrotDw = dh;
1375 unrotDh = dw;
1376 } else {
1377 unrotDw = dw;
1378 unrotDh = dh;
1379 }
1380 displayInfo.smallestNominalAppWidth = 1<<30;
1381 displayInfo.smallestNominalAppHeight = 1<<30;
1382 displayInfo.largestNominalAppWidth = 0;
1383 displayInfo.largestNominalAppHeight = 0;
1384 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1385 unrotDh);
1386 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1387 unrotDw);
1388 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1389 unrotDh);
1390 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1391 unrotDw);
1392 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1393 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1394 displayId);
1395 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1396 displayId);
1397 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1398 displayId);
1399 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1400 displayId);
1401 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1402 outConfig.screenLayout = sl;
1403 }
1404
1405 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1406 int uiMode, int displayId) {
1407 // Get the app screen size at this rotation.
1408 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId);
1409 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId);
1410
1411 // Compute the screen layout size class for this rotation.
1412 int longSize = w;
1413 int shortSize = h;
1414 if (longSize < shortSize) {
1415 int tmp = longSize;
1416 longSize = shortSize;
1417 shortSize = tmp;
1418 }
1419 longSize = (int)(longSize/density);
1420 shortSize = (int)(shortSize/density);
1421 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1422 }
1423
1424 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1425 int uiMode, int dw, int dh) {
1426 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
1427 displayId);
1428 if (width < displayInfo.smallestNominalAppWidth) {
1429 displayInfo.smallestNominalAppWidth = width;
1430 }
1431 if (width > displayInfo.largestNominalAppWidth) {
1432 displayInfo.largestNominalAppWidth = width;
1433 }
1434 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
1435 displayId);
1436 if (height < displayInfo.smallestNominalAppHeight) {
1437 displayInfo.smallestNominalAppHeight = height;
1438 }
1439 if (height > displayInfo.largestNominalAppHeight) {
1440 displayInfo.largestNominalAppHeight = height;
1441 }
1442 }
1443
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001444 DockedStackDividerController getDockedDividerController() {
1445 return mDividerControllerLocked;
1446 }
1447
Winson Chung655332c2016-10-31 13:14:28 -07001448 PinnedStackController getPinnedStackController() {
1449 return mPinnedStackControllerLocked;
1450 }
1451
Jeff Browna506a6e2013-06-04 00:02:38 -07001452 /**
1453 * Returns true if the specified UID has access to this display.
1454 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001455 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001456 return mDisplay.hasAccess(uid);
1457 }
1458
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001459 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001460 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001461 }
1462
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001463 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001464 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001465 }
1466
Wale Ogunwale61911492017-10-11 08:50:50 -07001467 /**
1468 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1469 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001470 TaskStack getSplitScreenPrimaryStack() {
1471 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001472 return (stack != null && stack.isVisible()) ? stack : null;
1473 }
1474
1475 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001476 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001477 * not visible.
1478 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001479 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1480 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001481 }
1482
1483 TaskStack getPinnedStack() {
1484 return mTaskStackContainers.getPinnedStack();
1485 }
1486
1487 private boolean hasPinnedStack() {
1488 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001489 }
1490
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001491 /**
1492 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1493 * Null is no compatible stack on the display.
1494 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001495 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001496 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1497 }
1498
1499 /**
1500 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1501 * activity type. Null is no compatible stack on the display.
1502 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001503 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001504 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001505 }
1506
Bryce Lee48f4b572017-04-10 10:54:15 -07001507 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001508 TaskStack getTopStack() {
1509 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001510 }
1511
Winson Chunge2d72172018-01-25 17:46:20 +00001512 ArrayList<Task> getVisibleTasks() {
1513 return mTaskStackContainers.getVisibleTasks();
1514 }
1515
Wale Ogunwale61911492017-10-11 08:50:50 -07001516 void onStackWindowingModeChanged(TaskStack stack) {
1517 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001518 }
1519
Andrii Kulian441e4492016-09-29 15:25:00 -07001520 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001521 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001522 super.onConfigurationChanged(newParentConfig);
1523
Andrii Kulian3a507b52016-09-19 18:14:12 -07001524 // The display size information is heavily dependent on the resources in the current
1525 // configuration, so we need to reconfigure it every time the configuration changes.
1526 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1527 mService.reconfigureDisplayLocked(this);
1528
Bryce Leef3c6a472017-11-14 14:53:06 -08001529 final DockedStackDividerController dividerController = getDockedDividerController();
1530
1531 if (dividerController != null) {
1532 getDockedDividerController().onConfigurationChanged();
1533 }
1534
1535 final PinnedStackController pinnedStackController = getPinnedStackController();
1536
1537 if (pinnedStackController != null) {
1538 getPinnedStackController().onConfigurationChanged();
1539 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001540 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001541
Andrii Kulian441e4492016-09-29 15:25:00 -07001542 /**
1543 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1544 * bounds were updated.
1545 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001546 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001547 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1548 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001549 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001550 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001551 }
1552 }
Winson Chung32c566f2017-04-11 18:31:21 -07001553
1554 // If there was no pinned stack, we still need to notify the controller of the display info
1555 // update as a result of the config change. We do this here to consolidate the flow between
1556 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001557 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001558 mPinnedStackControllerLocked.onDisplayInfoChanged();
1559 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001560 }
1561
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001562 @Override
1563 boolean fillsParent() {
1564 return true;
1565 }
1566
1567 @Override
1568 boolean isVisible() {
1569 return true;
1570 }
1571
1572 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001573 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001574 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001575 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001576 }
1577
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001578 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001579 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1580 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1581 // target, or here in order if there isn't an IME target.
1582 if (traverseTopToBottom) {
1583 for (int i = mChildren.size() - 1; i >= 0; --i) {
1584 final DisplayChildWindowContainer child = mChildren.get(i);
1585 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1586 // In this case the Ime windows will be processed above their target so we skip
1587 // here.
1588 continue;
1589 }
1590 if (child.forAllWindows(callback, traverseTopToBottom)) {
1591 return true;
1592 }
1593 }
1594 } else {
1595 final int count = mChildren.size();
1596 for (int i = 0; i < count; i++) {
1597 final DisplayChildWindowContainer child = mChildren.get(i);
1598 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1599 // In this case the Ime windows will be processed above their target so we skip
1600 // here.
1601 continue;
1602 }
1603 if (child.forAllWindows(callback, traverseTopToBottom)) {
1604 return true;
1605 }
1606 }
1607 }
1608 return false;
1609 }
1610
1611 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1612 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1613 }
1614
Wale Ogunwale399c8692017-05-08 14:22:42 -07001615 @Override
1616 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001617 final WindowManagerPolicy policy = mService.mPolicy;
1618
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001619 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001620 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001621 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08001622 "Display is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001623 // If the display is frozen, some activities may be in the middle of restarting, and
1624 // thus have removed their old window. If the window has the flag to hide the lock
1625 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1626 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001627 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001628 } else if (policy.isKeyguardLocked()) {
1629 // Use the last orientation the while the display is frozen with the keyguard
1630 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1631 // window. We don't want to check the show when locked window directly though as
1632 // things aren't stable while the display is frozen, for example the window could be
1633 // momentarily unavailable due to activity relaunch.
1634 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
Andrii Kulian8ee72852017-03-10 10:36:45 -08001635 + "return " + mLastOrientation);
1636 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001637 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001638 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001639 final int orientation = mAboveAppWindowsContainers.getOrientation();
1640 if (orientation != SCREEN_ORIENTATION_UNSET) {
1641 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001642 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001643 }
1644
Wale Ogunwale399c8692017-05-08 14:22:42 -07001645 // Top system windows are not requesting an orientation. Start searching from apps.
1646 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001647 }
1648
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001649 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001650 // Check if display metrics changed and update base values if needed.
1651 updateBaseDisplayMetricsIfNeeded();
1652
Craig Mautner722285e2012-09-07 13:55:58 -07001653 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001654 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001655
Wale Ogunwale61911492017-10-11 08:50:50 -07001656 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1657 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001658 }
Craig Mautner722285e2012-09-07 13:55:58 -07001659 }
1660
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001661 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001662 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1663 if (displayManagerInternal != null) {
1664 // Bootstrap the default logical display from the display manager.
1665 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1666 if (newDisplayInfo != null) {
1667 mDisplayInfo.copyFrom(newDisplayInfo);
1668 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001669 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001670
Andrii Kuliancd097992017-03-23 18:31:59 -07001671 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1672 mDisplayInfo.logicalDensityDpi);
1673 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1674 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1675 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001676 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001677 }
1678
Andrii Kuliancd097992017-03-23 18:31:59 -07001679 /**
1680 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1681 * values.
1682 */
1683 private void updateBaseDisplayMetricsIfNeeded() {
1684 // Get real display metrics without overrides from WM.
1685 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1686 final int orientation = mDisplayInfo.rotation;
1687 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1688 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1689 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1690 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001691 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001692
1693 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1694 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001695 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1696 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001697
1698 if (displayMetricsChanged) {
1699 // Check if display size or density is forced.
1700 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1701 || mBaseDisplayHeight != mInitialDisplayHeight;
1702 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1703
1704 // If there is an override set for base values - use it, otherwise use new values.
1705 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1706 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1707 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1708
1709 // Real display metrics changed, so we should also update initial values.
1710 mInitialDisplayWidth = newWidth;
1711 mInitialDisplayHeight = newHeight;
1712 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001713 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001714 mService.reconfigureDisplayLocked(this);
1715 }
1716 }
1717
Bryce Lee27cec322017-03-21 09:41:37 -07001718 /** Sets the maximum width the screen resolution can be */
1719 void setMaxUiWidth(int width) {
1720 if (DEBUG_DISPLAY) {
1721 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1722 }
1723
1724 mMaxUiWidth = width;
1725
1726 // Update existing metrics.
1727 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1728 }
1729
1730 /** Update base (override) display metrics. */
1731 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1732 mBaseDisplayWidth = baseWidth;
1733 mBaseDisplayHeight = baseHeight;
1734 mBaseDisplayDensity = baseDensity;
1735
1736 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1737 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1738 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1739 mBaseDisplayWidth = mMaxUiWidth;
1740
1741 if (DEBUG_DISPLAY) {
1742 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1743 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1744 + " on display:" + getDisplayId());
1745 }
1746 }
1747
1748 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001749
1750 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001751 }
1752
Wale Ogunwaledb506192017-12-08 10:57:32 -08001753 void getStableRect(Rect out) {
1754 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001755 }
1756
Wale Ogunwale61911492017-10-11 08:50:50 -07001757 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001758 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1759 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001760
Wale Ogunwale61911492017-10-11 08:50:50 -07001761 final TaskStack stack = new TaskStack(mService, stackId, controller);
1762 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001763 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001764 }
1765
Andrii Kulian51c1b672017-04-07 18:39:32 -07001766 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001767 final DisplayContent prevDc = stack.getDisplayContent();
1768 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001769 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1770 + " which is not currently attached to any display");
1771 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001772 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001773 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1774 + " to its current displayId=" + mDisplayId);
1775 }
1776
Wale Ogunwale61911492017-10-11 08:50:50 -07001777 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001778 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001779 }
1780
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001781 @Override
1782 protected void addChild(DisplayChildWindowContainer child,
1783 Comparator<DisplayChildWindowContainer> comparator) {
1784 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1785 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001786
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001787 @Override
1788 protected void addChild(DisplayChildWindowContainer child, int index) {
1789 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1790 }
1791
1792 @Override
1793 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001794 // Only allow removal of direct children from this display if the display is in the process
1795 // of been removed.
1796 if (mRemovingDisplay) {
1797 super.removeChild(child);
1798 return;
1799 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001800 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001801 }
1802
Andrii Kuliand2765632016-12-12 22:26:34 -08001803 @Override
1804 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1805 // Children of the display are statically ordered, so the real intention here is to perform
1806 // the operation on the display and not the static direct children.
1807 getParent().positionChildAt(position, this, includingParents);
1808 }
1809
Winson Chung59a47ded2018-01-25 17:46:06 +00001810 void positionStackAt(int position, TaskStack child) {
1811 mTaskStackContainers.positionChildAt(position, child, false /* includingParents */);
1812 layoutAndAssignWindowLayersIfNeeded();
1813 }
1814
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001815 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001816 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1817 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001818 final int taskId = stack.taskIdFromPoint(x, y);
1819 if (taskId != -1) {
1820 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001821 }
1822 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001823 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001824 }
1825
Chong Zhang8e89b312015-09-09 15:09:30 -07001826 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001827 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001828 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001829 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001830 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001831 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001832 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07001833 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1834 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001835 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001836 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001837 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001838
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001839 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1840 if (mTmpTaskForResizePointSearchResult.searchDone) {
1841 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001842 }
1843 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001844 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001845 }
1846
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001847 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001848 // The provided task is the task on this display with focus, so if WindowManagerService's
1849 // focused app is not on this display, focusedTask will be null.
1850 if (focusedTask == null) {
1851 mTouchExcludeRegion.setEmpty();
1852 } else {
1853 mTouchExcludeRegion.set(mBaseDisplayRect);
1854 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1855 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07001856 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1857 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001858 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
1859 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08001860 }
1861 // If we removed the focused task above, add it back and only leave its
1862 // outside touch area in the exclusion. TapDectector is not interested in
1863 // any touch inside the focused task itself.
1864 if (!mTmpRect2.isEmpty()) {
1865 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1866 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001867 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001868 final WindowState inputMethod = mService.mInputMethodWindow;
1869 if (inputMethod != null && inputMethod.isVisibleLw()) {
1870 // If the input method is visible and the user is typing, we don't want these touch
1871 // events to be intercepted and used to change focus. This would likely cause a
1872 // disappearance of the input method.
1873 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001874 if (inputMethod.getDisplayId() == mDisplayId) {
1875 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1876 } else {
1877 // IME is on a different display, so we need to update its tap detector.
1878 // TODO(multidisplay): Remove when IME will always appear on same display.
1879 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1880 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001881 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001882 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001883 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001884 win.getTouchableRegion(mTmpRegion);
1885 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1886 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001887 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
1888 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
1889 win.amendTapExcludeRegion(mTouchExcludeRegion);
1890 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001891 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07001892 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001893 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001894 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001895 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1896 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001897 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001898 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001899 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001900 }
1901
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001902 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001903 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001904 super.switchUser();
1905 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001906 }
1907
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001908 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001909 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1910 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001911 }
1912 }
1913
Wale Ogunwale10124582016-09-15 20:25:50 -07001914 @Override
1915 void removeIfPossible() {
1916 if (isAnimating()) {
1917 mDeferredRemoval = true;
1918 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001919 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001920 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001921 }
1922
Wale Ogunwale10124582016-09-15 20:25:50 -07001923 @Override
1924 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001925 mRemovingDisplay = true;
1926 try {
1927 super.removeImmediately();
1928 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07001929 if (mService.canDispatchPointerEvents()) {
1930 if (mTapDetector != null) {
1931 mService.unregisterPointerEventListener(mTapDetector);
1932 }
1933 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
1934 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1935 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001936 }
Jorim Jaggia3844032018-01-03 15:54:43 +01001937 mService.mAnimator.removeDisplayLocked(mDisplayId);
Chavi Weingarten38804382018-02-15 21:00:15 +00001938
1939 // The pending transaction won't be applied so we should
1940 // just clean up any surfaces pending destruction.
1941 onPendingTransactionApplied();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001942 } finally {
1943 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001944 }
Bryce Leef19cbe22018-02-02 15:09:21 -08001945
1946 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08001947 }
1948
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001949 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001950 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001951 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001952 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1953
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001954 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001955 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001956 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001957 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001958 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001959 }
1960
Andrii Kulian0214ed92017-05-16 13:44:05 -07001961 /** @return 'true' if removal of this display content is deferred due to active animation. */
1962 boolean isRemovalDeferred() {
1963 return mDeferredRemoval;
1964 }
1965
Wale Ogunwale10124582016-09-15 20:25:50 -07001966 boolean animateForIme(float interpolatedValue, float animationTarget,
1967 float dividerAnimationTarget) {
1968 boolean updated = false;
1969
Wale Ogunwale61911492017-10-11 08:50:50 -07001970 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1971 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001972 if (stack == null || !stack.isAdjustedForIme()) {
1973 continue;
1974 }
1975
1976 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
1977 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1978 updated = true;
1979 } else {
1980 mDividerControllerLocked.mLastAnimationProgress =
1981 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
1982 mDividerControllerLocked.mLastDividerProgress =
1983 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
1984 updated |= stack.updateAdjustForIme(
1985 mDividerControllerLocked.mLastAnimationProgress,
1986 mDividerControllerLocked.mLastDividerProgress,
1987 false /* force */);
1988 }
1989 if (interpolatedValue >= 1f) {
1990 stack.endImeAdjustAnimation();
1991 }
1992 }
1993
1994 return updated;
1995 }
1996
1997 boolean clearImeAdjustAnimation() {
1998 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07001999 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2000 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002001 if (stack != null && stack.isAdjustedForIme()) {
2002 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2003 changed = true;
2004 }
2005 }
2006 return changed;
2007 }
2008
2009 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002010 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2011 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002012 if (stack.isVisible() && stack.isAdjustedForIme()) {
2013 stack.beginImeAdjustAnimation();
2014 }
2015 }
2016 }
2017
2018 void adjustForImeIfNeeded() {
2019 final WindowState imeWin = mService.mInputMethodWindow;
2020 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2021 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002022 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002023 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2024 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2025 imeTargetStack.getDockSide() : DOCKED_INVALID;
2026 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2027 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2028 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002029 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002030 final boolean imeHeightChanged = imeVisible &&
2031 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2032
2033 // The divider could be adjusted for IME position, or be thinner than usual,
2034 // or both. There are three possible cases:
2035 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2036 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2037 // - If IME is not visible, divider is not moved and is normal width.
2038
2039 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002040 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2041 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002042 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002043 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2044 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002045 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2046 } else {
2047 stack.resetAdjustedForIme(false);
2048 }
2049 }
2050 mDividerControllerLocked.setAdjustedForIme(
2051 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2052 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002053 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2054 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002055 stack.resetAdjustedForIme(!dockVisible);
2056 }
2057 mDividerControllerLocked.setAdjustedForIme(
2058 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2059 }
Winson Chung655332c2016-10-31 13:14:28 -07002060 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002061 }
2062
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002063 /**
2064 * If a window that has an animation specifying a colored background and the current wallpaper
2065 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2066 * suddenly disappear.
2067 */
2068 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002069 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2070 w -> w.mIsWallpaper && w.isVisibleNow());
2071
2072 if (visibleWallpaper != null) {
2073 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002074 }
2075 return winAnimator.mAnimLayer;
2076 }
2077
Wale Ogunwale10124582016-09-15 20:25:50 -07002078 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002079 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2080 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002081 stack.prepareFreezingTaskBounds();
2082 }
2083 }
2084
Wale Ogunwale94744212015-09-21 19:01:47 -07002085 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002086 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002087
2088 // Compute a transform matrix to undo the coordinate space transformation,
2089 // and present the window at the same physical position it previously occupied.
2090 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2091 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2092
2093 mTmpRectF.set(bounds);
2094 mTmpMatrix.mapRect(mTmpRectF);
2095 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002096 }
2097
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002098 static int deltaRotation(int oldRotation, int newRotation) {
2099 int delta = newRotation - oldRotation;
2100 if (delta < 0) delta += 4;
2101 return delta;
2102 }
2103
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002104 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002105 Matrix outMatrix) {
2106 // For rotations without Z-ordering we don't need the target rectangle's position.
2107 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2108 displayHeight, outMatrix);
2109 }
2110
2111 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2112 float displayWidth, float displayHeight, Matrix outMatrix) {
2113 switch (rotation) {
2114 case ROTATION_0:
2115 outMatrix.reset();
2116 break;
2117 case ROTATION_270:
2118 outMatrix.setRotate(270, 0, 0);
2119 outMatrix.postTranslate(0, displayHeight);
2120 outMatrix.postTranslate(rectTop, 0);
2121 break;
2122 case ROTATION_180:
2123 outMatrix.reset();
2124 break;
2125 case ROTATION_90:
2126 outMatrix.setRotate(90, 0, 0);
2127 outMatrix.postTranslate(displayWidth, 0);
2128 outMatrix.postTranslate(-rectTop, rectLeft);
2129 break;
2130 }
2131 }
2132
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002133 @CallSuper
2134 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002135 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002136 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002137 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002138 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002139 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2140 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002141 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002142 }
2143 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2144 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002145 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2146 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002147 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002148 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002149 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2150 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002151 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002152 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002153 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2154 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002155 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002156 }
2157 proto.write(DPI, mBaseDisplayDensity);
2158 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002159 proto.write(ROTATION, mRotation);
2160 final ScreenRotationAnimation screenRotationAnimation =
2161 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2162 if (screenRotationAnimation != null) {
2163 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2164 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002165 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002166 proto.end(token);
2167 }
2168
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002169 @Override
2170 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2171 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002172 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2173 final String subPrefix = " " + prefix;
2174 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2175 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2176 pw.print("dpi");
2177 if (mInitialDisplayWidth != mBaseDisplayWidth
2178 || mInitialDisplayHeight != mBaseDisplayHeight
2179 || mInitialDisplayDensity != mBaseDisplayDensity) {
2180 pw.print(" base=");
2181 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2182 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2183 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002184 if (mDisplayScalingDisabled) {
2185 pw.println(" noscale");
2186 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002187 pw.print(" cur=");
2188 pw.print(mDisplayInfo.logicalWidth);
2189 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2190 pw.print(" app=");
2191 pw.print(mDisplayInfo.appWidth);
2192 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2193 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2194 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2195 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2196 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002197 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002198 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002199 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002200
Craig Mautnerdc548482014-02-05 13:35:24 -08002201 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002202 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002203 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2204 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002205 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002206 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002207
Craig Mautnerdc548482014-02-05 13:35:24 -08002208 pw.println();
2209 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002210 pw.println();
2211 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002212 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002213 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002214 pw.print(" Exiting #"); pw.print(i);
2215 pw.print(' '); pw.print(token);
2216 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002217 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002218 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002219 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002220
Jorim Jaggi31f71702016-05-04 16:43:04 -07002221 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002222
2223 // Dump stack references
2224 final TaskStack homeStack = getHomeStack();
2225 if (homeStack != null) {
2226 pw.println(prefix + "homeStack=" + homeStack.getName());
2227 }
2228 final TaskStack pinnedStack = getPinnedStack();
2229 if (pinnedStack != null) {
2230 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2231 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002232 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002233 if (splitScreenPrimaryStack != null) {
2234 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2235 }
2236
2237 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002238 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002239 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002240 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002241
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002242 pw.println();
2243 mDisplayFrames.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002244 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002245
2246 @Override
2247 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002248 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002249 }
2250
2251 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002252 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002253 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002254
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002255 /** Returns true if the stack in the windowing mode is visible. */
2256 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002257 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002258 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002259 }
2260
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002261 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002262 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002263 final int x = (int) xf;
2264 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002265 final WindowState touchedWin = getWindow(w -> {
2266 final int flags = w.mAttrs.flags;
2267 if (!w.isVisibleLw()) {
2268 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002269 }
2270 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002271 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002272 }
2273
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002274 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002275 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002276 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002277 }
2278
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002279 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002280
2281 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002282 return mTmpRegion.contains(x, y) || touchFlags == 0;
2283 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002284
2285 return touchedWin;
2286 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002287
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002288 boolean canAddToastWindowForUid(int uid) {
2289 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002290 // Also if the app is focused adding more than one toast at
2291 // a time for better backwards compatibility.
2292 final WindowState focusedWindowForUid = getWindow(w ->
2293 w.mOwnerUid == uid && w.isFocused());
2294 if (focusedWindowForUid != null) {
2295 return true;
2296 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002297 final WindowState win = getWindow(w ->
2298 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2299 && !w.mWindowRemovalAllowed);
2300 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002301 }
2302
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002303 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002304 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2305 return;
2306 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002307
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002308 // Used to communicate the old focus to the callback method.
2309 mTmpWindow = oldFocus;
2310
2311 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002312 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002313
2314 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002315 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002316
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002317 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002318
2319 if (mTmpWindow == null) {
2320 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2321 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002322 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002323 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002324 }
2325
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002326 /** Updates the layer assignment of windows on this display. */
2327 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002328 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002329 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002330 if (setLayoutNeeded) {
2331 setLayoutNeeded();
2332 }
Robert Carrb1579c82017-09-05 14:54:47 -07002333
Robert Carrf59b8dd2017-10-02 18:58:36 -07002334 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002335 // the application of this transaction until the animation pass triggers
2336 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2337 // the hiding and showing of surfaces.
2338 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002339 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002340 }
2341
Wale Ogunwale1666e312016-12-16 11:27:18 -08002342 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2343 // moving containers or resizing them. Need to investigate the best way to have it automatically
2344 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002345 void layoutAndAssignWindowLayersIfNeeded() {
2346 mService.mWindowsChanged = true;
2347 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002348
2349 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2350 false /*updateInputWindows*/)) {
2351 assignWindowLayers(false /* setLayoutNeeded */);
2352 }
2353
2354 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2355 mService.mWindowPlacerLocked.performSurfacePlacement();
2356 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2357 }
2358
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002359 /** Returns true if a leaked surface was destroyed */
2360 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002361 // Used to indicate that a surface was leaked.
2362 mTmpWindow = null;
2363 forAllWindows(w -> {
2364 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002365 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002366 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002367 }
2368 if (!mService.mSessions.contains(wsa.mSession)) {
2369 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002370 + w + " surface=" + wsa.mSurfaceController
2371 + " token=" + w.mToken
2372 + " pid=" + w.mSession.mPid
2373 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002374 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002375 mService.mForceRemoves.add(w);
2376 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002377 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002378 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002379 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002380 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002381 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002382 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002383 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002384 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002385 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002386
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002387 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002388 }
2389
2390 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002391 * Determine and return the window that should be the IME target.
2392 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2393 * @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 +00002394 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002395 WindowState computeImeTarget(boolean updateImeTarget) {
2396 if (mService.mInputMethodWindow == null) {
2397 // There isn't an IME so there shouldn't be a target...That was easy!
2398 if (updateImeTarget) {
2399 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2400 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002401 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002402 }
2403 return null;
2404 }
2405
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002406 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2407 // same display. Or even when the current IME/target are not on the same screen as the next
2408 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002409 mUpdateImeTarget = updateImeTarget;
2410 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002411
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002412
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002413 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2414 // to be on top of it, but it is not -really- where input will go. So look down below
2415 // for a real window to target...
2416 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2417 final AppWindowToken token = target.mAppToken;
2418 if (token != null) {
2419 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2420 if (betterTarget != null) {
2421 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002422 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002423 }
2424 }
2425
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002426 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2427 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002428
2429 // Now, a special case -- if the last target's window is in the process of exiting, and is
2430 // above the new target, keep on the last target to avoid flicker. Consider for example a
2431 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2432 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2433 // scrim.
2434 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002435 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2436 && (target == null
2437 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002438 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002439 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002440 }
2441
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002442 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2443 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002444
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002445 if (target == null) {
2446 if (updateImeTarget) {
2447 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2448 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2449 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002450 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002451 }
2452
2453 return null;
2454 }
2455
2456 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002457 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2458 if (token != null) {
2459
2460 // Now some fun for dealing with window animations that modify the Z order. We need
2461 // to look at all windows below the current target that are in this app, finding the
2462 // highest visible one in layering.
2463 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002464 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002465 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002466 }
2467
2468 if (highestTarget != null) {
2469 final AppTransition appTransition = mService.mAppTransition;
2470 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2471 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2472 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002473 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002474
2475 if (appTransition.isTransitionSet()) {
2476 // If we are currently setting up for an animation, hold everything until we
2477 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002478 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002479 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002480 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002481 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002482 // If the window we are currently targeting is involved with an animation,
2483 // and it is on top of the next target we will be over, then hold off on
2484 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002485 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002486 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002487 }
2488 }
2489 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002490
2491 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2492 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002493 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002494 }
2495
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002496 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002497 }
2498
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002499 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002500 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002501 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002502 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002503 }
2504
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002505 mService.mInputMethodTarget = target;
2506 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002507 assignWindowLayers(false /* setLayoutNeeded */);
2508 }
2509
2510 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2511 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2512 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2513 }
2514
2515 // Used to indicate we have reached the first window in the range we are interested in.
2516 mTmpWindow = null;
2517
2518 // TODO: Figure-out a more efficient way to do this.
2519 final WindowState candidate = getWindow(w -> {
2520 if (w == top) {
2521 // Reached the first window in the range we are interested in.
2522 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002523 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002524 if (mTmpWindow == null) {
2525 return false;
2526 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002527
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002528 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2529 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002530 }
2531 // If we reached the bottom of the range of windows we are considering,
2532 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002533 if (w == bottom) {
2534 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002535 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002536 return false;
2537 });
2538
2539 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002540 }
2541
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002542 void setLayoutNeeded() {
2543 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2544 mLayoutNeeded = true;
2545 }
2546
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002547 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002548 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2549 mLayoutNeeded = false;
2550 }
2551
2552 boolean isLayoutNeeded() {
2553 return mLayoutNeeded;
2554 }
2555
Wale Ogunwale02319a62016-09-26 15:21:22 -07002556 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2557 if (mTokenMap.isEmpty()) {
2558 return;
2559 }
2560 pw.println(" Display #" + mDisplayId);
2561 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2562 while (it.hasNext()) {
2563 final WindowToken token = it.next();
2564 pw.print(" ");
2565 pw.print(token);
2566 if (dumpAll) {
2567 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002568 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002569 } else {
2570 pw.println();
2571 }
2572 }
2573 }
2574
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002575 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002576 final int[] index = new int[1];
2577 forAllWindows(w -> {
2578 final WindowStateAnimator wAnim = w.mWinAnimator;
2579 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2580 index[0] = index[0] + 1;
2581 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002582 }
2583
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002584 void enableSurfaceTrace(FileDescriptor fd) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002585 forAllWindows(w -> {
2586 w.mWinAnimator.enableSurfaceTrace(fd);
2587 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002588 }
2589
2590 void disableSurfaceTrace() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002591 forAllWindows(w -> {
2592 w.mWinAnimator.disableSurfaceTrace();
2593 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002594 }
2595
Jorim Jaggife762342016-10-13 14:33:27 +02002596 /**
2597 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2598 */
2599 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2600 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002601 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002602 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2603 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002604 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002605 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002606 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002607 }
2608
Wale Ogunwale494009b82016-10-21 09:01:38 -07002609 boolean checkWaitingForWindows() {
2610
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002611 mHaveBootMsg = false;
2612 mHaveApp = false;
2613 mHaveWallpaper = false;
2614 mHaveKeyguard = true;
2615
2616 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002617 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2618 return true;
2619 }
2620 if (w.isDrawnLw()) {
2621 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002622 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002623 } else if (w.mAttrs.type == TYPE_APPLICATION
2624 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002625 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002626 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002627 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002628 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002629 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002630 }
2631 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002632 return false;
2633 });
2634
2635 if (visibleWindow != null) {
2636 // We have a visible window.
2637 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002638 }
2639
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002640 // if the wallpaper service is disabled on the device, we're never going to have
2641 // wallpaper, don't bother waiting for it
2642 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2643 com.android.internal.R.bool.config_enableWallpaperService)
2644 && !mService.mOnlyCore;
2645
Wale Ogunwale494009b82016-10-21 09:01:38 -07002646 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2647 "******** booted=" + mService.mSystemBooted
2648 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002649 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2650 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2651 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002652
2653 // If we are turning on the screen to show the boot message, don't do it until the boot
2654 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002655 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002656 return true;
2657 }
2658
2659 // If we are turning on the screen after the boot is completed normally, don't do so until
2660 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002661 if (mService.mSystemBooted
2662 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002663 return true;
2664 }
2665
2666 return false;
2667 }
2668
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002669 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002670 mTmpWindowAnimator = animator;
2671 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002672 }
2673
2674 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002675 resetAnimationBackgroundAnimator();
2676
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002677 // Used to indicate a detached wallpaper.
2678 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002679 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002680
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002681 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002682
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002683 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002684 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002685 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2686 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002687 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2688 }
2689 }
2690
Wale Ogunwale494009b82016-10-21 09:01:38 -07002691 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002692 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002693 if (imFocus == null) {
2694 return false;
2695 }
2696
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002697 if (DEBUG_INPUT_METHOD) {
2698 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2699 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2700 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002701 }
2702
Wale Ogunwale494009b82016-10-21 09:01:38 -07002703 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2704
2705 if (DEBUG_INPUT_METHOD) {
2706 Slog.i(TAG_WM, "IM target client: " + imeClient);
2707 if (imeClient != null) {
2708 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2709 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2710 }
2711 }
2712
2713 return imeClient != null && imeClient.asBinder() == client.asBinder();
2714 }
2715
2716 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002717 final WindowState win = getWindow(
2718 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2719 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002720 }
2721
2722 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002723 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002724 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002725 final int curValue = w.mSystemUiVisibility;
2726 final int diff = (curValue ^ visibility) & globalDiff;
2727 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002728 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002729 w.mSeq++;
2730 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002731 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002732 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2733 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002734 visibility, newValue, diff);
2735 }
2736 } catch (RemoteException e) {
2737 // so sorry
2738 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002739 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002740 }
2741
2742 void onWindowFreezeTimeout() {
2743 Slog.w(TAG_WM, "Window freeze timeout expired.");
2744 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002745
2746 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002747 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002748 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002749 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002750 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002751 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2752 - mService.mDisplayFreezeTime);
2753 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002754 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002755 mService.mWindowPlacerLocked.performSurfacePlacement();
2756 }
2757
2758 void waitForAllWindowsDrawn() {
2759 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002760 forAllWindows(w -> {
2761 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2762 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2763 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002764 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002765 w.mLastContentInsets.set(-1, -1, -1, -1);
2766 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002767 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002768 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002769 }
2770
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002771 // TODO: Super crazy long method that should be broken down...
2772 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2773
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002774 final int dw = mDisplayInfo.logicalWidth;
2775 final int dh = mDisplayInfo.logicalHeight;
2776 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2777
2778 mTmpUpdateAllDrawn.clear();
2779
2780 int repeats = 0;
2781 do {
2782 repeats++;
2783 if (repeats > 6) {
2784 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2785 clearLayoutNeeded();
2786 break;
2787 }
2788
2789 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2790 pendingLayoutChanges);
2791
Andrii Kulian839def92016-11-02 10:58:58 -07002792 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2793 // the wallpaper window jumping across displays.
2794 // Remove check for default display when there will be support for multiple wallpaper
2795 // targets (on different displays).
2796 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002797 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002798 }
2799
2800 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2801 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2802 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2803 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002804 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002805 }
2806 }
2807
2808 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2809 setLayoutNeeded();
2810 }
2811
2812 // FIRST LOOP: Perform a layout, if needed.
2813 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2814 performLayout(repeats == 1, false /* updateInputWindows */);
2815 } else {
2816 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2817 }
2818
2819 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2820 pendingLayoutChanges = 0;
2821
2822 if (isDefaultDisplay) {
2823 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002824 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002825 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2826 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2827 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2828 }
2829 } while (pendingLayoutChanges != 0);
2830
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002831 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002832
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002833 mTmpRecoveringMemory = recoveringMemory;
2834 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01002835 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002836
2837 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002838 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2839 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2840 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002841 true /* inTraversal, must call performTraversalInTrans... below */);
2842
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002843 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2844 if (wallpaperVisible != mLastWallpaperVisible) {
2845 mLastWallpaperVisible = wallpaperVisible;
2846 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2847 }
2848
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002849 while (!mTmpUpdateAllDrawn.isEmpty()) {
2850 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2851 // See if any windows have been drawn, so they (and others associated with them)
2852 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002853 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002854 }
2855
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002856 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002857 }
2858
Bryce Leef3c6a472017-11-14 14:53:06 -08002859 private void updateBounds() {
2860 calculateBounds(mTmpBounds);
2861 setBounds(mTmpBounds);
2862 }
2863
2864 // Determines the current display bounds based on the current state
2865 private void calculateBounds(Rect out) {
2866 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
2867 final int orientation = mDisplayInfo.rotation;
2868 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2869 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
2870 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
2871 int width = mDisplayInfo.logicalWidth;
2872 int left = (physWidth - width) / 2;
2873 int height = mDisplayInfo.logicalHeight;
2874 int top = (physHeight - height) / 2;
2875 out.set(left, top, left + width, top + height);
2876 }
2877
2878 @Override
2879 public void getBounds(Rect out) {
2880 calculateBounds(out);
2881 }
2882
2883 private void getBounds(Rect out, int orientation) {
2884 getBounds(out);
2885
2886 // Rotate the Rect if needed.
2887 final int currentRotation = mDisplayInfo.rotation;
2888 final int rotationDelta = deltaRotation(currentRotation, orientation);
2889 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
2890 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
2891 mTmpRectF.set(out);
2892 mTmpMatrix.mapRect(mTmpRectF);
2893 mTmpRectF.round(out);
2894 }
2895 }
2896
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002897 void performLayout(boolean initial, boolean updateInputWindows) {
2898 if (!isLayoutNeeded()) {
2899 return;
2900 }
2901 clearLayoutNeeded();
2902
2903 final int dw = mDisplayInfo.logicalWidth;
2904 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002905 if (DEBUG_LAYOUT) {
2906 Slog.v(TAG, "-------------------------------------");
2907 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2908 }
2909
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002910 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
2911 // TODO: Not sure if we really need to set the rotation here since we are updating from the
2912 // display info above...
2913 mDisplayFrames.mRotation = mRotation;
2914 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002915 if (isDefaultDisplay) {
2916 // Not needed on non-default displays.
2917 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2918 mService.mScreenRect.set(0, 0, dw, dh);
2919 }
2920
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002921 int seq = mService.mLayoutSeq + 1;
2922 if (seq < 0) seq = 0;
2923 mService.mLayoutSeq = seq;
2924
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002925 // Used to indicate that we have processed the dream window and all additional windows are
2926 // behind it.
2927 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002928 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002929
2930 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002931 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002932
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002933 // Used to indicate that we have processed the dream window and all additional attached
2934 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002935 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002936 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002937
2938 // Now perform layout of attached windows, which usually depend on the position of the
2939 // window they are attached to. XXX does not deal with windows that are attached to windows
2940 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002941 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002942
2943 // Window frames may have changed. Tell the input dispatcher about it.
2944 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2945 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2946 if (updateInputWindows) {
2947 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2948 }
2949
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002950 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2951 }
2952
2953 /**
2954 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2955 * In portrait mode, it grabs the full screenshot.
2956 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002957 * @param config of the output bitmap
2958 * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
2959 */
chaviwfbe47df2017-11-10 16:14:49 -08002960 Bitmap screenshotDisplay(Bitmap.Config config, boolean wallpaperOnly) {
2961 synchronized (mService.mWindowMap) {
Jorim Jaggi51304d72017-05-17 17:25:32 +02002962 if (!mService.mPolicy.isScreenOn()) {
chaviwfbe47df2017-11-10 16:14:49 -08002963 if (DEBUG_SCREENSHOT) {
2964 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002965 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002966 return null;
2967 }
2968
chaviwfbe47df2017-11-10 16:14:49 -08002969 if (wallpaperOnly && !shouldScreenshotWallpaper()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002970 return null;
2971 }
2972
chaviwfbe47df2017-11-10 16:14:49 -08002973 int dw = mDisplayInfo.logicalWidth;
2974 int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002975
chaviwfbe47df2017-11-10 16:14:49 -08002976 if (dw <= 0 || dh <= 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002977 return null;
2978 }
2979
chaviwfbe47df2017-11-10 16:14:49 -08002980 final Rect frame = new Rect(0, 0, dw, dh);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002981
2982 // The screenshot API does not apply the current screen rotation.
2983 int rot = mDisplay.getRotation();
2984
2985 if (rot == ROTATION_90 || rot == ROTATION_270) {
2986 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
2987 }
2988
chaviwfbe47df2017-11-10 16:14:49 -08002989 // SurfaceFlinger is not aware of orientation, so convert our logical
2990 // crop to SurfaceFlinger's portrait orientation.
2991 convertCropForSurfaceFlinger(frame, rot, dw, dh);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002992
2993 final ScreenRotationAnimation screenRotationAnimation =
2994 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
2995 final boolean inRotation = screenRotationAnimation != null &&
2996 screenRotationAnimation.isAnimating();
chaviwfbe47df2017-11-10 16:14:49 -08002997 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002998
Robert Carrb1579c82017-09-05 14:54:47 -07002999 // TODO(b/68392460): We should screenshot Task controls directly
3000 // but it's difficult at the moment as the Task doesn't have the
3001 // correct size set.
chaviwfbe47df2017-11-10 16:14:49 -08003002 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003003 if (bitmap == null) {
Robert Carrb1579c82017-09-05 14:54:47 -07003004 Slog.w(TAG_WM, "Failed to take screenshot");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003005 return null;
3006 }
chaviwfbe47df2017-11-10 16:14:49 -08003007
3008 // Create a copy of the screenshot that is immutable and backed in ashmem.
3009 // This greatly reduces the overhead of passing the bitmap between processes.
3010 final Bitmap ret = bitmap.createAshmemBitmap(config);
3011 bitmap.recycle();
3012 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003013 }
chaviwfbe47df2017-11-10 16:14:49 -08003014 }
3015
3016 private boolean shouldScreenshotWallpaper() {
3017 MutableBoolean screenshotReady = new MutableBoolean(false);
3018
3019 forAllWindows(w -> {
3020 if (!w.mIsWallpaper) {
3021 return false;
3022 }
3023
3024 // Found the wallpaper window
3025 final WindowStateAnimator winAnim = w.mWinAnimator;
3026
3027 if (winAnim.getShown() && winAnim.mLastAlpha > 0f) {
3028 screenshotReady.value = true;
3029 }
3030
3031 return true;
3032 }, true /* traverseTopToBottom */);
3033
3034 return screenshotReady.value;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003035 }
3036
3037 // TODO: Can this use createRotationMatrix()?
3038 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3039 if (rot == Surface.ROTATION_90) {
3040 final int tmp = crop.top;
3041 crop.top = dw - crop.right;
3042 crop.right = crop.bottom;
3043 crop.bottom = dw - crop.left;
3044 crop.left = tmp;
3045 } else if (rot == Surface.ROTATION_180) {
3046 int tmp = crop.top;
3047 crop.top = dh - crop.bottom;
3048 crop.bottom = dh - tmp;
3049 tmp = crop.right;
3050 crop.right = dw - crop.left;
3051 crop.left = dw - tmp;
3052 } else if (rot == Surface.ROTATION_270) {
3053 final int tmp = crop.top;
3054 crop.top = crop.left;
3055 crop.left = dh - crop.bottom;
3056 crop.bottom = crop.right;
3057 crop.right = dh - tmp;
3058 }
3059 }
3060
3061 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003062 // Used to indicate the layout is needed.
3063 mTmpWindow = null;
3064
3065 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003066 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003067 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003068 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003069 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003070 w.setDisplayLayoutNeeded();
3071 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003072 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003073
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003074 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003075 mService.mWindowPlacerLocked.performSurfacePlacement();
3076 }
3077 }
3078
Wale Ogunwale1666e312016-12-16 11:27:18 -08003079 void setExitingTokensHasVisible(boolean hasVisible) {
3080 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3081 mExitingTokens.get(i).hasVisible = hasVisible;
3082 }
3083
3084 // Initialize state of exiting applications.
3085 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3086 }
3087
3088 void removeExistingTokensIfPossible() {
3089 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3090 final WindowToken token = mExitingTokens.get(i);
3091 if (!token.hasVisible) {
3092 mExitingTokens.remove(i);
3093 }
3094 }
3095
3096 // Time to remove any exiting applications?
3097 mTaskStackContainers.removeExistingAppTokensIfPossible();
3098 }
3099
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003100 @Override
3101 void onDescendantOverrideConfigurationChanged() {
3102 setLayoutNeeded();
3103 mService.requestTraversal();
3104 }
3105
David Stevens9440dc82017-03-16 19:00:20 -07003106 boolean okToDisplay() {
3107 if (mDisplayId == DEFAULT_DISPLAY) {
3108 return !mService.mDisplayFrozen
3109 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3110 }
3111 return mDisplayInfo.state == Display.STATE_ON;
3112 }
3113
3114 boolean okToAnimate() {
3115 return okToDisplay() &&
3116 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3117 }
3118
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003119 static final class TaskForResizePointSearchResult {
3120 boolean searchDone;
3121 Task taskForResize;
3122
3123 void reset() {
3124 searchDone = false;
3125 taskForResize = null;
3126 }
3127 }
Robert Carr3b716242016-08-16 16:02:21 -07003128
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003129 private static final class ApplySurfaceChangesTransactionState {
3130 boolean displayHasContent;
3131 boolean obscured;
3132 boolean syswin;
3133 boolean focusDisplayed;
3134 float preferredRefreshRate;
3135 int preferredModeId;
3136
3137 void reset() {
3138 displayHasContent = false;
3139 obscured = false;
3140 syswin = false;
3141 focusDisplayed = false;
3142 preferredRefreshRate = 0;
3143 preferredModeId = 0;
3144 }
3145 }
3146
3147 private static final class ScreenshotApplicationState {
3148 WindowState appWin;
3149 int maxLayer;
3150 int minLayer;
3151 boolean screenshotReady;
3152
3153 void reset(boolean screenshotReady) {
3154 appWin = null;
3155 maxLayer = 0;
3156 minLayer = 0;
3157 this.screenshotReady = screenshotReady;
3158 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3159 }
3160 }
3161
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003162 /**
3163 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3164 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3165 * homogeneous children type which is currently required by sub-classes of
3166 * {@link WindowContainer} class.
3167 */
3168 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3169
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003170 DisplayChildWindowContainer(WindowManagerService service) {
3171 super(service);
3172 }
3173
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003174 @Override
3175 boolean fillsParent() {
3176 return true;
3177 }
3178
3179 @Override
3180 boolean isVisible() {
3181 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003182 }
3183 }
3184
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003185 /**
3186 * Window container class that contains all containers on this display relating to Apps.
3187 * I.e Activities.
3188 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003189 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003190 /**
3191 * A control placed at the appropriate level for transitions to occur.
3192 */
chaviw23ee71c2017-12-18 11:29:41 -08003193 SurfaceControl mAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003194
Robert Carrf7a7ca82017-12-06 13:17:07 -08003195 /**
3196 * Given that the split-screen divider does not have an AppWindowToken, it
3197 * will have to live inside of a "NonAppWindowContainer", in particular
3198 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3199 * it will need to be interleaved with some of our children, appearing on top of
3200 * both docked stacks but underneath any assistant stacks.
3201 *
3202 * To solve this problem we have this anchor control, which will always exist so
3203 * we can always assign it the correct value in our {@link #assignChildLayers}.
3204 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3205 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3206 * events between the two containers.
3207 */
3208 SurfaceControl mSplitScreenDividerAnchor = null;
3209
Wale Ogunwale61911492017-10-11 08:50:50 -07003210 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3211 // through the list to find them.
3212 private TaskStack mHomeStack = null;
3213 private TaskStack mPinnedStack = null;
3214 private TaskStack mSplitScreenPrimaryStack = null;
3215
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003216 TaskStackContainers(WindowManagerService service) {
3217 super(service);
3218 }
3219
Wale Ogunwale61911492017-10-11 08:50:50 -07003220 /**
3221 * Returns the topmost stack on the display that is compatible with the input windowing mode
3222 * and activity type. Null is no compatible stack on the display.
3223 */
3224 TaskStack getStack(int windowingMode, int activityType) {
3225 if (activityType == ACTIVITY_TYPE_HOME) {
3226 return mHomeStack;
3227 }
3228 if (windowingMode == WINDOWING_MODE_PINNED) {
3229 return mPinnedStack;
3230 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3231 return mSplitScreenPrimaryStack;
3232 }
3233 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3234 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003235 if (activityType == ACTIVITY_TYPE_UNDEFINED
3236 && windowingMode == stack.getWindowingMode()) {
3237 // Passing in undefined type means we want to match the topmost stack with the
3238 // windowing mode.
3239 return stack;
3240 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003241 if (stack.isCompatible(windowingMode, activityType)) {
3242 return stack;
3243 }
3244 }
3245 return null;
3246 }
3247
3248 @VisibleForTesting
3249 TaskStack getTopStack() {
3250 return mTaskStackContainers.getChildCount() > 0
3251 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3252 }
3253
3254 TaskStack getHomeStack() {
3255 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3256 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3257 }
3258 return mHomeStack;
3259 }
3260
3261 TaskStack getPinnedStack() {
3262 return mPinnedStack;
3263 }
3264
Matthew Ng64e77cf2017-10-31 14:01:31 -07003265 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003266 return mSplitScreenPrimaryStack;
3267 }
3268
Winson Chunge2d72172018-01-25 17:46:20 +00003269 ArrayList<Task> getVisibleTasks() {
3270 final ArrayList<Task> visibleTasks = new ArrayList<>();
3271 forAllTasks(task -> {
3272 if (task.isVisible()) {
3273 visibleTasks.add(task);
3274 }
3275 });
3276 return visibleTasks;
3277 }
3278
Andrii Kulian839def92016-11-02 10:58:58 -07003279 /**
3280 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003281 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003282 */
3283 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003284 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003285 addChild(stack, onTop);
3286 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003287 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003288
Wale Ogunwale61911492017-10-11 08:50:50 -07003289 void onStackWindowingModeChanged(TaskStack stack) {
3290 removeStackReferenceIfNeeded(stack);
3291 addStackReferenceIfNeeded(stack);
3292 if (stack == mPinnedStack && getTopStack() != stack) {
3293 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3294 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3295 }
3296 }
3297
3298 private void addStackReferenceIfNeeded(TaskStack stack) {
3299 if (stack.isActivityTypeHome()) {
3300 if (mHomeStack != null) {
3301 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3302 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3303 }
3304 mHomeStack = stack;
3305 }
3306 final int windowingMode = stack.getWindowingMode();
3307 if (windowingMode == WINDOWING_MODE_PINNED) {
3308 if (mPinnedStack != null) {
3309 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3310 + mPinnedStack + " already exist on display=" + this
3311 + " stack=" + stack);
3312 }
3313 mPinnedStack = stack;
3314 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3315 if (mSplitScreenPrimaryStack != null) {
3316 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3317 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3318 + " already exist on display=" + this + " stack=" + stack);
3319 }
3320 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003321 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003322 }
3323 }
3324
3325 private void removeStackReferenceIfNeeded(TaskStack stack) {
3326 if (stack == mHomeStack) {
3327 mHomeStack = null;
3328 } else if (stack == mPinnedStack) {
3329 mPinnedStack = null;
3330 } else if (stack == mSplitScreenPrimaryStack) {
3331 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003332 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3333 mService.setDockedStackCreateStateLocked(
3334 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3335 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003336 }
Andrii Kulian839def92016-11-02 10:58:58 -07003337 }
3338
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003339 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003340 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3341 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003342 addChild(stack, addIndex);
3343 setLayoutNeeded();
3344 }
3345
Wale Ogunwale61911492017-10-11 08:50:50 -07003346 @Override
3347 protected void removeChild(TaskStack stack) {
3348 super.removeChild(stack);
3349 removeStackReferenceIfNeeded(stack);
3350 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003351
3352 @Override
3353 boolean isOnTop() {
3354 // Considered always on top
3355 return true;
3356 }
3357
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003358 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003359 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003360 if (child.getWindowConfiguration().isAlwaysOnTop()
3361 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003362 // This stack is always-on-top, override the default behavior.
3363 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3364
3365 // Moving to its current position, as we must call super but we don't want to
3366 // perform any meaningful action.
3367 final int currentPosition = mChildren.indexOf(child);
3368 super.positionChildAt(currentPosition, child, false /* includingParents */);
3369 return;
3370 }
3371
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003372 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3373 super.positionChildAt(targetPosition, child, includingParents);
3374
3375 setLayoutNeeded();
3376 }
3377
3378 /**
3379 * When stack is added or repositioned, find a proper position for it.
3380 * This will make sure that pinned stack always stays on top.
3381 * @param requestedPosition Position requested by caller.
3382 * @param stack Stack to be added or positioned.
3383 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3384 * @return The proper position for the stack.
3385 */
3386 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3387 final int topChildPosition = mChildren.size() - 1;
3388 boolean toTop = requestedPosition == POSITION_TOP;
3389 toTop |= adding ? requestedPosition >= topChildPosition + 1
3390 : requestedPosition >= topChildPosition;
3391 int targetPosition = requestedPosition;
3392
Wale Ogunwale61911492017-10-11 08:50:50 -07003393 if (toTop && stack.getWindowingMode() != WINDOWING_MODE_PINNED && hasPinnedStack()) {
Bryce Lee48f4b572017-04-10 10:54:15 -07003394 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003395 TaskStack topStack = mChildren.get(topChildPosition);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07003396 if (topStack.getWindowingMode() != WINDOWING_MODE_PINNED) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003397 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3398 }
3399
3400 // So, stack is moved just below the pinned stack.
3401 // When we're adding a new stack the target is the current pinned stack position.
3402 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003403 // stack, because WindowContainer#positionAt() first removes element and then adds
3404 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003405 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3406 }
3407
3408 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003409 }
3410
3411 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003412 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3413 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003414 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003415 if (super.forAllWindows(callback, traverseTopToBottom)) {
3416 return true;
3417 }
3418 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3419 return true;
3420 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003421 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003422 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3423 return true;
3424 }
3425 if (super.forAllWindows(callback, traverseTopToBottom)) {
3426 return true;
3427 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003428 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003429 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003430 }
3431
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003432 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003433 boolean traverseTopToBottom) {
3434 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3435 // app tokens.
3436 // TODO: Investigate if we need to continue to do this or if we can just process them
3437 // in-order.
3438 if (traverseTopToBottom) {
3439 for (int i = mChildren.size() - 1; i >= 0; --i) {
3440 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3441 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003442 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3443 traverseTopToBottom)) {
3444 return true;
3445 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003446 }
3447 }
3448 } else {
3449 final int count = mChildren.size();
3450 for (int i = 0; i < count; ++i) {
3451 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3452 final int appTokensCount = appTokens.size();
3453 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003454 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3455 traverseTopToBottom)) {
3456 return true;
3457 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003458 }
3459 }
3460 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003461 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003462 }
3463
Wale Ogunwale1666e312016-12-16 11:27:18 -08003464 void setExitingTokensHasVisible(boolean hasVisible) {
3465 for (int i = mChildren.size() - 1; i >= 0; --i) {
3466 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3467 for (int j = appTokens.size() - 1; j >= 0; --j) {
3468 appTokens.get(j).hasVisible = hasVisible;
3469 }
3470 }
3471 }
3472
3473 void removeExistingAppTokensIfPossible() {
3474 for (int i = mChildren.size() - 1; i >= 0; --i) {
3475 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3476 for (int j = appTokens.size() - 1; j >= 0; --j) {
3477 final AppWindowToken token = appTokens.get(j);
3478 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3479 && (!token.mIsExiting || token.isEmpty())) {
3480 // Make sure there is no animation running on this token, so any windows
3481 // associated with it will be removed as soon as their animations are
3482 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003483 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003484 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3485 "performLayout: App token exiting now removed" + token);
3486 token.removeIfPossible();
3487 }
3488 }
3489 }
3490 }
3491
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003492 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003493 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003494 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3495 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003496 // Apps and their containers are not allowed to specify an orientation while the
3497 // docked or freeform stack is visible...except for the home stack/task if the
3498 // docked stack is minimized and it actually set something.
3499 if (mHomeStack != null && mHomeStack.isVisible()
3500 && mDividerControllerLocked.isMinimizedDock()) {
3501 final int orientation = mHomeStack.getOrientation();
3502 if (orientation != SCREEN_ORIENTATION_UNSET) {
3503 return orientation;
3504 }
3505 }
3506 return SCREEN_ORIENTATION_UNSPECIFIED;
3507 }
3508
3509 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003510 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3511 PackageManager.FEATURE_AUTOMOTIVE);
3512 if (isCar) {
3513 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3514 // allow anything but the default orientation.
3515 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3516 "Forcing UNSPECIFIED orientation in car. Ignoring " + orientation);
3517 return SCREEN_ORIENTATION_UNSPECIFIED;
3518 }
3519
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003520 if (orientation != SCREEN_ORIENTATION_UNSET
3521 && orientation != SCREEN_ORIENTATION_BEHIND) {
3522 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3523 "App is requesting an orientation, return " + orientation);
3524 return orientation;
3525 }
3526
3527 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08003528 "No app is requesting an orientation, return " + mLastOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003529 // The next app has not been requested to be visible, so we keep the current orientation
3530 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003531 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003532 }
Robert Carrb1579c82017-09-05 14:54:47 -07003533
3534 @Override
3535 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrf7a7ca82017-12-06 13:17:07 -08003536
3537 final int HOME_STACK_STATE = 0;
3538 final int NORMAL_STACK_STATE = 1;
3539 final int ALWAYS_ON_TOP_STATE = 2;
3540
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003541 int layer = 0;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003542 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3543 for (int i = 0; i < mChildren.size(); i++) {
3544 final TaskStack s = mChildren.get(i);
3545 if (state == HOME_STACK_STATE && s.isActivityTypeHome()) {
3546 s.assignLayer(t, layer++);
3547 } else if (state == NORMAL_STACK_STATE && !s.isActivityTypeHome()
3548 && !s.isAlwaysOnTop()) {
3549 s.assignLayer(t, layer++);
3550 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3551 t.setLayer(mSplitScreenDividerAnchor, layer++);
3552 }
3553 } else if (state == ALWAYS_ON_TOP_STATE && s.isAlwaysOnTop()) {
3554 s.assignLayer(t, layer++);
3555 }
3556 }
3557 // The appropriate place for App-Transitions to occur is right
3558 // above all other animations but still below things in the Picture-and-Picture
3559 // windowing mode.
3560 if (state == NORMAL_STACK_STATE && mAppAnimationLayer != null) {
3561 t.setLayer(mAppAnimationLayer, layer++);
Robert Carrb1579c82017-09-05 14:54:47 -07003562 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003563 }
3564 for (int i = 0; i < mChildren.size(); i++) {
3565 final TaskStack s = mChildren.get(i);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003566 s.assignChildLayers(t);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003567 }
3568
Robert Carrb1579c82017-09-05 14:54:47 -07003569 }
3570
3571 @Override
chaviw23ee71c2017-12-18 11:29:41 -08003572 SurfaceControl getAppAnimationLayer() {
3573 return mAppAnimationLayer;
3574 }
3575
Robert Carrf7a7ca82017-12-06 13:17:07 -08003576 SurfaceControl getSplitScreenDividerAnchor() {
3577 return mSplitScreenDividerAnchor;
3578 }
3579
chaviw23ee71c2017-12-18 11:29:41 -08003580 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003581 void onParentSet() {
3582 super.onParentSet();
3583 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003584 mAppAnimationLayer = makeChildSurface(null)
3585 .setName("animationLayer")
3586 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003587 mSplitScreenDividerAnchor = makeChildSurface(null)
3588 .setName("splitScreenDividerAnchor")
3589 .build();
3590 getPendingTransaction()
3591 .show(mAppAnimationLayer)
3592 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003593 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003594 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003595 mAppAnimationLayer.destroy();
3596 mAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003597 mSplitScreenDividerAnchor.destroy();
3598 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003599 }
3600 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003601 }
3602
Robert Carree4d4b92017-11-22 12:21:46 -08003603 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003604 AboveAppWindowContainers(String name, WindowManagerService service) {
3605 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003606 }
3607
3608 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3609 boolean needAssignIme = imeContainer != null
3610 && imeContainer.getSurfaceControl() != null;
3611 for (int j = 0; j < mChildren.size(); ++j) {
3612 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003613
3614 // See {@link mSplitScreenDividerAnchor}
3615 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3616 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3617 continue;
3618 }
Robert Carree4d4b92017-11-22 12:21:46 -08003619 wt.assignLayer(t, j);
3620 wt.assignChildLayers(t);
3621
3622 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3623 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003624
3625 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3626 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003627 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003628 needAssignIme = false;
3629 }
3630 }
3631 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003632 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003633 }
3634 }
3635 }
3636
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003637 /**
3638 * Window container class that contains all containers on this display that are not related to
3639 * Apps. E.g. status bar.
3640 */
Robert Carree4d4b92017-11-22 12:21:46 -08003641 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003642 /**
3643 * Compares two child window tokens returns -1 if the first is lesser than the second in
3644 * terms of z-order and 1 otherwise.
3645 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003646 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003647 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003648 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3649 token1.mOwnerCanManageAppTokens)
3650 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3651 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003652
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003653 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3654 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3655 return false;
3656 }
3657 final int req = w.mAttrs.screenOrientation;
3658 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3659 || req == SCREEN_ORIENTATION_UNSET) {
3660 return false;
3661 }
3662 return true;
3663 };
3664
Wale Ogunwale3a931692016-11-02 16:49:48 -07003665 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003666 private final Dimmer mDimmer = new Dimmer(this);
3667 private final Rect mTmpDimBoundsRect = new Rect();
3668
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003669 NonAppWindowContainers(String name, WindowManagerService service) {
3670 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003671 mName = name;
3672 }
3673
3674 void addChild(WindowToken token) {
3675 addChild(token, mWindowComparator);
3676 }
3677
3678 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003679 int getOrientation() {
3680 final WindowManagerPolicy policy = mService.mPolicy;
3681 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003682 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003683
3684 if (win != null) {
3685 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003686 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003687 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003688 if (mService.mKeyguardGoingAway) {
3689 // Keyguard can't affect the orientation if it is going away...
3690 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3691 return SCREEN_ORIENTATION_UNSET;
3692 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003693 }
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003694 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003695 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003696 }
3697
Andrii Kulian8ee72852017-03-10 10:36:45 -08003698 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003699
Jorim Jaggi75520d52017-08-24 17:23:19 +02003700 if (policy.isKeyguardShowingAndNotOccluded()
3701 || mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003702 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003703 }
3704
3705 return SCREEN_ORIENTATION_UNSET;
3706 }
3707
3708 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003709 String getName() {
3710 return mName;
3711 }
chaviwf29223e2018-01-31 13:23:51 -08003712
3713 @Override
3714 Dimmer getDimmer() {
3715 return mDimmer;
3716 }
3717
3718 @Override
3719 void prepareSurfaces() {
3720 mDimmer.resetDimStates();
3721 super.prepareSurfaces();
3722 getBounds(mTmpDimBoundsRect);
3723
3724 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
3725 scheduleAnimation();
3726 }
3727 }
Robert Carr3b716242016-08-16 16:02:21 -07003728 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003729
Robert Carr9034d962018-01-04 18:27:42 -08003730 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
3731 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
3732 super(name, service);
3733 }
3734
3735 @Override
3736 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
3737 }
3738 };
3739
Robert Carrb1579c82017-09-05 14:54:47 -07003740 SurfaceControl.Builder makeSurface(SurfaceSession s) {
3741 return mService.makeSurfaceBuilder(s)
3742 .setParent(mWindowingLayer);
3743 }
3744
3745 @Override
3746 SurfaceSession getSession() {
3747 return mSession;
3748 }
3749
3750 @Override
3751 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003752 SurfaceSession s = child != null ? child.getSession() : getSession();
3753 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07003754 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07003755
3756 if (child == null) {
3757 return b;
3758 }
3759
Robert Carree4d4b92017-11-22 12:21:46 -08003760 return b.setName(child.getName())
3761 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07003762 }
3763
3764 /**
3765 * The makeSurface variants are for use by the window-container
3766 * hierarchy. makeOverlay here is a function for various non windowing
3767 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
3768 * and other potpourii.
3769 */
3770 SurfaceControl.Builder makeOverlay() {
3771 return mService.makeSurfaceBuilder(mSession)
3772 .setParent(mOverlayLayer);
3773 }
3774
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09003775 /**
3776 * Reparents the given surface to mOverlayLayer.
3777 */
3778 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
3779 transaction.reparent(surface, mOverlayLayer.getHandle());
3780 }
3781
Robert Carrb1579c82017-09-05 14:54:47 -07003782 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003783 applyMagnificationSpec(getPendingTransaction(), spec);
3784 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07003785 }
3786
3787 @Override
3788 void onParentSet() {
3789 // Since we are the top of the SurfaceControl hierarchy here
3790 // we create the root surfaces explicitly rather than chaining
3791 // up as the default implementation in onParentSet does. So we
3792 // explicitly do NOT call super here.
3793 }
3794
3795 @Override
3796 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07003797
3798 // These are layers as children of "mWindowingLayer"
3799 mBelowAppWindowsContainers.assignLayer(t, 0);
3800 mTaskStackContainers.assignLayer(t, 1);
3801 mAboveAppWindowsContainers.assignLayer(t, 2);
3802
3803 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08003804 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08003805
Robert Carree4d4b92017-11-22 12:21:46 -08003806 // In the case where we have an IME target that is not in split-screen
3807 // mode IME assignment is easy. We just need the IME to go directly above
3808 // the target. This way children of the target will naturally go above the IME
3809 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08003810 //
Robert Carree4d4b92017-11-22 12:21:46 -08003811 // In the case of split-screen windowing mode, we need to elevate the IME above the
3812 // docked divider while keeping the app itself below the docked divider, so instead
3813 // we use relative layering of the IME targets child windows, and place the
3814 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08003815 //
Robert Carree4d4b92017-11-22 12:21:46 -08003816 // In the case where we have no IME target we assign it where it's base layer would
3817 // place it in the AboveAppWindowContainers.
3818 if (imeTarget != null && !imeTarget.inSplitScreenWindowingMode()
3819 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003820 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07003821 // TODO: We need to use an extra level on the app surface to ensure
3822 // this is always above SurfaceView but always below attached window.
3823 1);
Robert Carree4d4b92017-11-22 12:21:46 -08003824 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07003825 }
3826
3827 // Above we have assigned layers to our children, now we ask them to assign
3828 // layers to their children.
3829 mBelowAppWindowsContainers.assignChildLayers(t);
3830 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08003831 mAboveAppWindowsContainers.assignChildLayers(t,
3832 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07003833 mImeWindowsContainers.assignChildLayers(t);
3834 }
3835
3836 /**
3837 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
3838 * that the IME target is one of the docked applications. We'd like the docked divider to be
3839 * above both of the applications, and we'd like the IME to be above the docked divider.
3840 * However we need child windows of the applications to be above the IME (Text drag handles).
3841 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
3842 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
3843 * with {@link #WindowState#assignLayer}
3844 */
3845 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
3846 t.setRelativeLayer(child.getSurfaceControl(), mImeWindowsContainers.getSurfaceControl(), 1);
3847 }
3848
3849 @Override
Chavi Weingarten38804382018-02-15 21:00:15 +00003850 public void destroyAfterPendingTransaction(SurfaceControl surface) {
3851 mPendingDestroyingSurfaces.add(surface);
3852 }
3853
3854 /**
3855 * Destroys any surfaces that have been put into the pending list with
3856 * {@link #destroyAfterPendingTransaction}.
3857 */
3858 void onPendingTransactionApplied() {
3859 for (int i = mPendingDestroyingSurfaces.size() - 1; i >= 0; i--) {
3860 mPendingDestroyingSurfaces.get(i).destroy();
3861 }
3862 mPendingDestroyingSurfaces.clear();
3863 }
3864
3865 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003866 void prepareSurfaces() {
3867 final ScreenRotationAnimation screenRotationAnimation =
3868 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
3869 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
3870 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
3871 mPendingTransaction.setMatrix(mWindowingLayer,
3872 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
3873 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
3874 mPendingTransaction.setPosition(mWindowingLayer,
3875 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
3876 mPendingTransaction.setAlpha(mWindowingLayer,
3877 screenRotationAnimation.getEnterTransformation().getAlpha());
3878 }
3879 super.prepareSurfaces();
3880 }
Craig Mautner59c00972012-07-30 12:10:24 -07003881}