blob: 04ed87fcfb03a7d92c3bf24f2abb8b3e25d121db [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 Ogunwale3797c222015-10-27 14:21:58 -070019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Wale Ogunwale51362492016-09-08 17:49:17 -070020import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -070021import static android.app.ActivityManager.StackId.HOME_STACK_ID;
22import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Wale Ogunwalea77e1462016-09-28 10:09:46 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070024import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
25import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070026import static android.view.Display.DEFAULT_DISPLAY;
27import static android.view.Display.FLAG_PRIVATE;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070028import static android.view.Surface.ROTATION_0;
29import static android.view.Surface.ROTATION_180;
30import static android.view.Surface.ROTATION_270;
31import static android.view.Surface.ROTATION_90;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070032import static android.view.View.GONE;
Wale Ogunwale10124582016-09-15 20:25:50 -070033import static android.view.WindowManager.DOCKED_BOTTOM;
34import static android.view.WindowManager.DOCKED_INVALID;
35import static android.view.WindowManager.DOCKED_TOP;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080036import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
37import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
38import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale494009b82016-10-21 09:01:38 -070039import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070040import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070041import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
42import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070043import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwale494009b82016-10-21 09:01:38 -070044import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070045import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale494009b82016-10-21 09:01:38 -070046import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Wale Ogunwale494009b82016-10-21 09:01:38 -070047import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070048import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Wale Ogunwale3a931692016-11-02 16:49:48 -070049import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
50import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale494009b82016-10-21 09:01:38 -070051import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070052import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
53import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070054import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070055import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070056import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070057import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
58import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070059import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale1666e312016-12-16 11:27:18 -080060import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070061import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070062import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070063import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
64import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070065import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwalec69694a2016-10-18 13:51:15 -070066import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070067import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020069import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070070import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070071import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070072import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale1666e312016-12-16 11:27:18 -080073import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070074import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070075import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Andrii Kulian06d07d62017-03-14 11:11:47 -070076import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070077import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070078import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070079import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080080import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -070081import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070082import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
83import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -070084import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070085import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -070086import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
87import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070088import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
89import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
90import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -070091import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070092import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -070093import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070094import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070095import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070096import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -070097import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070098import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070099import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700100import static com.android.server.wm.proto.DisplayProto.ABOVE_APP_WINDOWS;
101import static com.android.server.wm.proto.DisplayProto.BELOW_APP_WINDOWS;
102import static com.android.server.wm.proto.DisplayProto.DISPLAY_INFO;
103import static com.android.server.wm.proto.DisplayProto.DOCKED_STACK_DIVIDER_CONTROLLER;
104import static com.android.server.wm.proto.DisplayProto.DPI;
105import static com.android.server.wm.proto.DisplayProto.ID;
106import static com.android.server.wm.proto.DisplayProto.IME_WINDOWS;
107import static com.android.server.wm.proto.DisplayProto.PINNED_STACK_CONTROLLER;
108import static com.android.server.wm.proto.DisplayProto.STACKS;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700109
Andrii Kulian3a507b52016-09-19 18:14:12 -0700110import android.annotation.NonNull;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700111import android.app.ActivityManager.StackId;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700112import android.content.res.CompatibilityInfo;
Andrii Kulian441e4492016-09-29 15:25:00 -0700113import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700114import android.graphics.Bitmap;
Jorim Jaggi6a7a8592017-01-12 00:44:33 +0100115import android.graphics.GraphicBuffer;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700116import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800117import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700118import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700119import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100120import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700121import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700122import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700123import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700124import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700125import android.os.RemoteException;
126import android.os.SystemClock;
Chong Zhang8e89b312015-09-09 15:09:30 -0700127import android.util.DisplayMetrics;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800128import android.util.MutableBoolean;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700129import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700130import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700131import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -0700132import android.view.DisplayInfo;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700133import android.view.InputDevice;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700134import android.view.Surface;
135import android.view.SurfaceControl;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700136import android.view.WindowManagerPolicy;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700137
Bryce Lee48f4b572017-04-10 10:54:15 -0700138import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800139import com.android.internal.util.ToBooleanFunction;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700140import com.android.internal.view.IInputMethodClient;
Craig Mautner59c00972012-07-30 12:10:24 -0700141
Robert Carr3b716242016-08-16 16:02:21 -0700142import java.io.FileDescriptor;
Craig Mautner59c00972012-07-30 12:10:24 -0700143import java.io.PrintWriter;
144import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700145import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700146import java.util.HashMap;
147import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700148import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700149import java.util.List;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800150import java.util.function.Consumer;
151import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700152
Craig Mautner59c00972012-07-30 12:10:24 -0700153/**
154 * Utility class for keeping track of the WindowStates and other pertinent contents of a
155 * particular Display.
156 *
157 * IMPORTANT: No method from this class should ever be used without holding
158 * WindowManagerService.mWindowMap.
159 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700160class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700161 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700162
163 /** Unique identifier of this stack. */
164 private final int mDisplayId;
165
Wale Ogunwale3a931692016-11-02 16:49:48 -0700166 /** The containers below are the only child containers the display can have. */
167 // Contains all window containers that are related to apps (Activities)
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700168 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers();
Wale Ogunwale3a931692016-11-02 16:49:48 -0700169 // Contains all non-app window containers that should be displayed above the app containers
170 // (e.g. Status bar)
171 private final NonAppWindowContainers mAboveAppWindowsContainers =
172 new NonAppWindowContainers("mAboveAppWindowsContainers");
173 // Contains all non-app window containers that should be displayed below the app containers
174 // (e.g. Wallpaper).
175 private final NonAppWindowContainers mBelowAppWindowsContainers =
176 new NonAppWindowContainers("mBelowAppWindowsContainers");
177 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
178 // on the IME target. We mainly have this container grouping so we can keep track of all the IME
179 // window containers together and move them in-sync if/when needed.
180 private final NonAppWindowContainers mImeWindowsContainers =
181 new NonAppWindowContainers("mImeWindowsContainers");
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700182
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000183 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800184 private WindowState mTmpWindow2;
185 private WindowAnimator mTmpWindowAnimator;
186 private boolean mTmpRecoveringMemory;
187 private boolean mUpdateImeTarget;
188 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700189 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700190
Wale Ogunwale02319a62016-09-26 15:21:22 -0700191 // Mapping from a token IBinder to a WindowToken object on this display.
192 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
193
Andrii Kuliancd097992017-03-23 18:31:59 -0700194 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700195 int mInitialDisplayWidth = 0;
196 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700197 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700198
199 /**
200 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
201 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
202 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
203 */
Craig Mautner59c00972012-07-30 12:10:24 -0700204 int mBaseDisplayWidth = 0;
205 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700206 /**
207 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
208 * but can be set from Settings or via shell command "adb shell wm density".
209 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
210 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700211 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700212 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700213 private final DisplayInfo mDisplayInfo = new DisplayInfo();
214 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700215 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Andrii Kulian06d07d62017-03-14 11:11:47 -0700216 /**
217 * For default display it contains real metrics, empty for others.
218 * @see WindowManagerService#createWatermarkInTransaction()
219 */
220 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
221 /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */
222 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700223
Andrii Kulian06d07d62017-03-14 11:11:47 -0700224 /**
225 * Compat metrics computed based on {@link #mDisplayMetrics}.
226 * @see #updateDisplayAndOrientation(int)
227 */
228 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
229
230 /** The desired scaling factor for compatible apps. */
231 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700232
Andrii Kulian8ee72852017-03-10 10:36:45 -0800233 /**
234 * Current rotation of the display.
235 * Constants as per {@link android.view.Surface.Rotation}.
236 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700237 * @see #updateRotationUnchecked(boolean)
Andrii Kulian8ee72852017-03-10 10:36:45 -0800238 */
239 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700240
Andrii Kulian8ee72852017-03-10 10:36:45 -0800241 /**
242 * Last applied orientation of the display.
243 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
244 *
245 * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int)
246 */
247 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700248
Andrii Kulian8ee72852017-03-10 10:36:45 -0800249 /**
250 * Flag indicating that the application is receiving an orientation that has different metrics
251 * than it expected. E.g. Portrait instead of Landscape.
252 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700253 * @see #updateRotationUnchecked(boolean)
Andrii Kulian8ee72852017-03-10 10:36:45 -0800254 */
255 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700256
Andrii Kulian8ee72852017-03-10 10:36:45 -0800257 /**
258 * Orientation forced by some window. If there is no visible window that specifies orientation
259 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
260 *
261 * @see NonAppWindowContainers#getOrientation()
262 */
263 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700264
Andrii Kulian8ee72852017-03-10 10:36:45 -0800265 /**
266 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
267 * occluded.
268 *
269 * @see NonAppWindowContainers#getOrientation()
270 */
271 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
272
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700273 /**
274 * Keep track of wallpaper visibility to notify changes.
275 */
276 private boolean mLastWallpaperVisible = false;
277
Andrii Kulian06d07d62017-03-14 11:11:47 -0700278 private Rect mBaseDisplayRect = new Rect();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700279 private Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700280
Craig Mautner39834192012-09-02 07:47:24 -0700281 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700282 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700283 int pendingLayoutChanges;
Andrii Kulian839def92016-11-02 10:58:58 -0700284 // TODO(multi-display): remove some of the usages.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800285 boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700286
Craig Mautnerdc548482014-02-05 13:35:24 -0800287 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700288 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800289
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800290 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
291 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -0700292 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700293
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700294 /** Detect user tapping outside of current focused task bounds .*/
295 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700296
Craig Mautner6601b7b2013-04-29 10:29:11 -0700297 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700298 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700299
Craig Mautner6601b7b2013-04-29 10:29:11 -0700300 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800301 private final Rect mTmpRect = new Rect();
302 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700303 private final RectF mTmpRectF = new RectF();
304 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800305 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700306
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800307 WindowManagerService mService;
Craig Mautner9d808b12013-08-06 18:00:25 -0700308
Craig Mautner95da1082014-02-24 17:54:35 -0800309 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700310 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800311
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700312 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700313 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700314
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800315 DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700316
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800317 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
318
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000319 private boolean mHaveBootMsg = false;
320 private boolean mHaveApp = false;
321 private boolean mHaveWallpaper = false;
322 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700323
324 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
325
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700326 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
327 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000328 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
329 new ApplySurfaceChangesTransactionState();
330 private final ScreenshotApplicationState mScreenshotApplicationState =
331 new ScreenshotApplicationState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700332
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700333 // True if this display is in the process of being removed. Used to determine if the removal of
334 // the display's direct children should be allowed.
335 private boolean mRemovingDisplay = false;
336
Bryce Leed1871262017-06-12 14:12:29 -0700337 // {@code false} if this display is in the processing of being created.
338 private boolean mDisplayReady = false;
339
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700340 private final WindowLayersController mLayersController;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800341 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700342 int mInputMethodAnimLayerAdjustment;
343
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800344 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
345 WindowStateAnimator winAnimator = w.mWinAnimator;
346 if (winAnimator.hasSurface()) {
347 final boolean wasAnimating = winAnimator.mWasAnimating;
348 final boolean nowAnimating = winAnimator.stepAnimationLocked(
349 mTmpWindowAnimator.mCurrentTime);
350 winAnimator.mWasAnimating = nowAnimating;
351 mTmpWindowAnimator.orAnimating(nowAnimating);
352
353 if (DEBUG_WALLPAPER) Slog.v(TAG,
354 w + ": wasAnimating=" + wasAnimating + ", nowAnimating=" + nowAnimating);
355
356 if (wasAnimating && !winAnimator.mAnimating
357 && mWallpaperController.isWallpaperTarget(w)) {
358 mTmpWindowAnimator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
359 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
360 if (DEBUG_LAYOUT_REPEATS) {
361 mService.mWindowPlacerLocked.debugLayoutRepeats(
362 "updateWindowsAndWallpaperLocked 2", pendingLayoutChanges);
363 }
364 }
365 }
366
367 final AppWindowToken atoken = w.mAppToken;
368 if (winAnimator.mDrawState == READY_TO_SHOW) {
369 if (atoken == null || atoken.allDrawn) {
370 if (w.performShowLocked()) {
371 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
372 if (DEBUG_LAYOUT_REPEATS) {
373 mService.mWindowPlacerLocked.debugLayoutRepeats(
374 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
375 }
376 }
377 }
378 }
379 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
380 if (appAnimator != null && appAnimator.thumbnail != null) {
381 if (appAnimator.thumbnailTransactionSeq
382 != mTmpWindowAnimator.mAnimTransactionSequence) {
383 appAnimator.thumbnailTransactionSeq =
384 mTmpWindowAnimator.mAnimTransactionSequence;
385 appAnimator.thumbnailLayer = 0;
386 }
387 if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
388 appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
389 }
390 }
391 };
392
393 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
394 final WindowStateAnimator winAnimator = w.mWinAnimator;
395 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
396 return;
397 }
398
399 final int flags = w.mAttrs.flags;
400
401 // If this window is animating, make a note that we have an animating window and take
402 // care of a request to run a detached wallpaper animation.
403 if (winAnimator.mAnimating) {
404 if (winAnimator.mAnimation != null) {
405 if ((flags & FLAG_SHOW_WALLPAPER) != 0
406 && winAnimator.mAnimation.getDetachWallpaper()) {
407 mTmpWindow = w;
408 }
409 final int color = winAnimator.mAnimation.getBackgroundColor();
410 if (color != 0) {
411 final TaskStack stack = w.getStack();
412 if (stack != null) {
413 stack.setAnimationBackground(winAnimator, color);
414 }
415 }
416 }
417 mTmpWindowAnimator.setAnimating(true);
418 }
419
420 // If this window's app token is running a detached wallpaper animation, make a note so
421 // we can ensure the wallpaper is displayed behind it.
422 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
423 if (appAnimator != null && appAnimator.animation != null
424 && appAnimator.animating) {
425 if ((flags & FLAG_SHOW_WALLPAPER) != 0
426 && appAnimator.animation.getDetachWallpaper()) {
427 mTmpWindow = w;
428 }
429
430 final int color = appAnimator.animation.getBackgroundColor();
431 if (color != 0) {
432 final TaskStack stack = w.getStack();
433 if (stack != null) {
434 stack.setAnimationBackground(winAnimator, color);
435 }
436 }
437 }
438 };
439
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800440 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
441 final int lostFocusUid = mTmpWindow.mOwnerUid;
442 final Handler handler = mService.mH;
443 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
444 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
445 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
446 w.mAttrs.hideTimeoutMilliseconds);
447 }
448 }
449 };
450
451 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
452 final AppWindowToken focusedApp = mService.mFocusedApp;
453 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
454 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
455
456 if (!w.canReceiveKeys()) {
457 return false;
458 }
459
460 final AppWindowToken wtoken = w.mAppToken;
461
462 // If this window's application has been removed, just skip it.
463 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
464 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
465 + (wtoken.removed ? "removed" : "sendingToBottom"));
466 return false;
467 }
468
469 if (focusedApp == null) {
470 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
471 + " using new focus @ " + w);
472 mTmpWindow = w;
473 return true;
474 }
475
476 if (!focusedApp.windowsAreFocusable()) {
477 // Current focused app windows aren't focusable...
478 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
479 + " focusable using new focus @ " + w);
480 mTmpWindow = w;
481 return true;
482 }
483
484 // Descend through all of the app tokens and find the first that either matches
485 // win.mAppToken (return win) or mFocusedApp (return null).
486 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
487 if (focusedApp.compareTo(wtoken) > 0) {
488 // App stack below focused app stack. No focus for you!!!
489 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
490 "findFocusedWindow: Reached focused app=" + focusedApp);
491 mTmpWindow = null;
492 return true;
493 }
494 }
495
496 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
497 mTmpWindow = w;
498 return true;
499 };
500
501 private final Consumer<WindowState> mPrepareWindowSurfaces =
502 w -> w.mWinAnimator.prepareSurfaceLocked(true);
503
504 private final Consumer<WindowState> mPerformLayout = w -> {
505 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
506 // wasting time and funky changes while a window is animating away.
507 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
508 || w.isGoneForLayoutLw();
509
510 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
511 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
512 + " mLayoutAttached=" + w.mLayoutAttached
513 + " screen changed=" + w.isConfigChanged());
514 final AppWindowToken atoken = w.mAppToken;
515 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
516 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.hidden
517 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
518 + " parentHidden=" + w.isParentWindowHidden());
519 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
520 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.hidden
521 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
522 + " parentHidden=" + w.isParentWindowHidden());
523 }
524
525 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
526 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
527 // since that means "perform layout as normal, just don't display").
528 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
529 || ((w.isConfigChanged() || w.setReportResizeHints())
530 && !w.isGoneForLayoutLw() &&
531 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
532 (w.mHasSurface && w.mAppToken != null &&
533 w.mAppToken.layoutConfigChanges)))) {
534 if (!w.mLayoutAttached) {
535 if (mTmpInitial) {
536 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
537 w.mContentChanged = false;
538 }
539 if (w.mAttrs.type == TYPE_DREAM) {
540 // Don't layout windows behind a dream, so that if it does stuff like hide
541 // the status bar we won't get a bad transition when it goes away.
542 mTmpWindow = w;
543 }
544 w.mLayoutNeeded = false;
545 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200546 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800547 mService.mPolicy.layoutWindowLw(w, null);
548 w.mLayoutSeq = mService.mLayoutSeq;
549
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200550 // If this is the first layout, we need to initialize the last inset values as
551 // otherwise we'd immediately cause an unnecessary resize.
552 if (firstLayout) {
553 w.updateLastInsetValues();
554 }
555
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800556 // Window frames may have changed. Update dim layer with the new bounds.
557 final Task task = w.getTask();
558 if (task != null) {
559 mDimLayerController.updateDimLayer(task);
560 }
561
562 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
563 + " mContainingFrame=" + w.mContainingFrame
564 + " mDisplayFrame=" + w.mDisplayFrame);
565 }
566 }
567 };
568
569 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
570 if (w.mLayoutAttached) {
571 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
572 + " mViewVisibility=" + w.mViewVisibility
573 + " mRelayoutCalled=" + w.mRelayoutCalled);
574 // If this view is GONE, then skip it -- keep the current frame, and let the caller
575 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
576 // windows, since that means "perform layout as normal, just don't display").
577 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
578 return;
579 }
580 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
581 || w.mLayoutNeeded) {
582 if (mTmpInitial) {
583 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
584 w.mContentChanged = false;
585 }
586 w.mLayoutNeeded = false;
587 w.prelayout();
588 mService.mPolicy.layoutWindowLw(w, w.getParentWindow());
589 w.mLayoutSeq = mService.mLayoutSeq;
590 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
591 + " mContainingFrame=" + w.mContainingFrame
592 + " mDisplayFrame=" + w.mDisplayFrame);
593 }
594 } else if (w.mAttrs.type == TYPE_DREAM) {
595 // Don't layout windows behind a dream, so that if it does stuff like hide the
596 // status bar we won't get a bad transition when it goes away.
597 mTmpWindow = mTmpWindow2;
598 }
599 };
600
601 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
602 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
603 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
604 return w.canBeImeTarget();
605 };
606
607 private final Consumer<WindowState> mApplyPostLayoutPolicy =
608 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
609 mService.mInputMethodTarget);
610
611 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
612 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
613 final boolean obscuredChanged = w.mObscured !=
614 mTmpApplySurfaceChangesTransactionState.obscured;
615 final RootWindowContainer root = mService.mRoot;
616 // Only used if default window
617 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
618
619 // Update effect.
620 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
621 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
622 final boolean isDisplayed = w.isDisplayedLw();
623
624 if (isDisplayed && w.isObscuringDisplay()) {
625 // This window completely covers everything behind it, so we want to leave all
626 // of them as undimmed (for performance reasons).
627 root.mObscuringWindow = w;
628 mTmpApplySurfaceChangesTransactionState.obscured = true;
629 }
630
631 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
632 root.handleNotObscuredLocked(w,
633 mTmpApplySurfaceChangesTransactionState.obscured,
634 mTmpApplySurfaceChangesTransactionState.syswin);
635
636 if (w.mHasSurface && isDisplayed) {
637 final int type = w.mAttrs.type;
638 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
639 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
640 mTmpApplySurfaceChangesTransactionState.syswin = true;
641 }
642 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
643 && w.mAttrs.preferredRefreshRate != 0) {
644 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
645 = w.mAttrs.preferredRefreshRate;
646 }
647 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
648 && w.mAttrs.preferredDisplayModeId != 0) {
649 mTmpApplySurfaceChangesTransactionState.preferredModeId
650 = w.mAttrs.preferredDisplayModeId;
651 }
652 }
653 }
654
655 w.applyDimLayerIfNeeded();
656
657 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
658 && mWallpaperController.isWallpaperTarget(w)) {
659 // This is the wallpaper target and its obscured state changed... make sure the
660 // current wallpaper's visibility has been updated accordingly.
661 mWallpaperController.updateWallpaperVisibility();
662 }
663
664 w.handleWindowMovedIfNeeded();
665
666 final WindowStateAnimator winAnimator = w.mWinAnimator;
667
668 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
669 w.mContentChanged = false;
670
671 // Moved from updateWindowsAndWallpaperLocked().
672 if (w.mHasSurface) {
673 // Take care of the window being ready to display.
674 final boolean committed = winAnimator.commitFinishDrawingLocked();
675 if (isDefaultDisplay && committed) {
676 if (w.mAttrs.type == TYPE_DREAM) {
677 // HACK: When a dream is shown, it may at that point hide the lock screen.
678 // So we need to redo the layout to let the phone window manager make this
679 // happen.
680 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
681 if (DEBUG_LAYOUT_REPEATS) {
682 surfacePlacer.debugLayoutRepeats(
683 "dream and commitFinishDrawingLocked true",
684 pendingLayoutChanges);
685 }
686 }
687 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
688 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
689 "First draw done in potential wallpaper target " + w);
690 root.mWallpaperMayChange = true;
691 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
692 if (DEBUG_LAYOUT_REPEATS) {
693 surfacePlacer.debugLayoutRepeats(
694 "wallpaper and commitFinishDrawingLocked true",
695 pendingLayoutChanges);
696 }
697 }
698 }
Robert Carr2117aaf2017-04-25 14:46:50 -0700699 final TaskStack stack = w.getStack();
700 if ((!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening())
701 || (stack != null && stack.isAnimatingBounds())) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800702 // Updates the shown frame before we set up the surface. This is needed
703 // because the resizing could change the top-left position (in addition to
704 // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to
705 // position the surface.
706 //
707 // If an animation is being started, we can't call this method because the
708 // animation hasn't processed its initial transformation yet, but in general
Robert Carr2117aaf2017-04-25 14:46:50 -0700709 // we do want to update the position if the window is animating. We make an exception
710 // for the bounds animating state, where an application may have been waiting
711 // for an exit animation to start, but instead enters PiP. We need to ensure
712 // we always recompute the top-left in this case.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800713 winAnimator.computeShownFrameLocked();
714 }
715 winAnimator.setSurfaceBoundariesLocked(mTmpRecoveringMemory /* recoveringMemory */);
716 }
717
718 final AppWindowToken atoken = w.mAppToken;
719 if (atoken != null) {
720 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
721 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
722 mTmpUpdateAllDrawn.add(atoken);
723 }
724 }
725
726 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
727 && w.isDisplayedLw()) {
728 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
729 }
730
731 w.updateResizingWindowIfNeeded();
732 };
733
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800734 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800735 * Create new {@link DisplayContent} instance, add itself to the root window container and
736 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700737 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800738 * @param service You know.
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700739 * @param layersController window layer controller used to assign layer to the windows on this
740 * display.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700741 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
742 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700743 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700744 DisplayContent(Display display, WindowManagerService service,
Wale Ogunwale0303c572016-10-20 10:16:29 -0700745 WindowLayersController layersController, WallpaperController wallpaperController) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800746 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
747 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
748 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
749 + " new=" + display);
750 }
751
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700752 mDisplay = display;
753 mDisplayId = display.getDisplayId();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700754 mLayersController = layersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700755 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700756 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700757 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700758 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700759 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700760 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800761 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700762 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800763 mDimLayerController = new DimLayerController(this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700764
765 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700766 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700767 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700768 super.addChild(mAboveAppWindowsContainers, null);
769 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800770
771 // Add itself as a child to the root container.
772 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700773
774 // TODO(b/62541591): evaluate whether this is the best spot to declare the
775 // {@link DisplayContent} ready for use.
776 mDisplayReady = true;
777 }
778
779 boolean isReady() {
780 // The display is ready when the system and the individual display are both ready.
781 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700782 }
783
784 int getDisplayId() {
785 return mDisplayId;
786 }
787
Wale Ogunwale02319a62016-09-26 15:21:22 -0700788 WindowToken getWindowToken(IBinder binder) {
789 return mTokenMap.get(binder);
790 }
791
792 AppWindowToken getAppWindowToken(IBinder binder) {
793 final WindowToken token = getWindowToken(binder);
794 if (token == null) {
795 return null;
796 }
797 return token.asAppWindowToken();
798 }
799
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700800 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700801 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
802 if (dc != null) {
803 // We currently don't support adding a window token to the display if the display
804 // already has the binder mapped to another token. If there is a use case for supporting
805 // this moving forward we will either need to merge the WindowTokens some how or have
806 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700807 throw new IllegalArgumentException("Can't map token=" + token + " to display="
808 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700809 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700810 if (binder == null) {
811 throw new IllegalArgumentException("Can't map token=" + token + " to display="
812 + getName() + " binder is null");
813 }
814 if (token == null) {
815 throw new IllegalArgumentException("Can't map null token to display="
816 + getName() + " binder=" + binder);
817 }
818
Wale Ogunwale02319a62016-09-26 15:21:22 -0700819 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700820
821 if (token.asAppWindowToken() == null) {
822 // Add non-app token to container hierarchy on the display. App tokens are added through
823 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700824 switch (token.windowType) {
825 case TYPE_WALLPAPER:
826 mBelowAppWindowsContainers.addChild(token);
827 break;
828 case TYPE_INPUT_METHOD:
829 case TYPE_INPUT_METHOD_DIALOG:
830 mImeWindowsContainers.addChild(token);
831 break;
832 default:
833 mAboveAppWindowsContainers.addChild(token);
834 break;
835 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700836 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700837 }
838
839 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700840 final WindowToken token = mTokenMap.remove(binder);
841 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800842 token.setExiting();
843 }
844 return token;
845 }
846
847 /** Changes the display the input window token is housed on to this one. */
848 void reParentWindowToken(WindowToken token) {
849 final DisplayContent prevDc = token.getDisplayContent();
850 if (prevDc == this) {
851 return;
852 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800853 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
854 && token.asAppWindowToken() == null) {
855 // Removed the token from the map, but made sure it's not an app token before removing
856 // from parent.
857 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700858 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800859
860 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700861 }
862
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700863 void removeAppToken(IBinder binder) {
864 final WindowToken token = removeWindowToken(binder);
865 if (token == null) {
866 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
867 return;
868 }
869
870 final AppWindowToken appToken = token.asAppWindowToken();
871
872 if (appToken == null) {
873 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
874 return;
875 }
876
877 appToken.onRemovedFromDisplay();
878 }
879
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700880 Display getDisplay() {
881 return mDisplay;
882 }
883
Craig Mautner59c00972012-07-30 12:10:24 -0700884 DisplayInfo getDisplayInfo() {
885 return mDisplayInfo;
886 }
887
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700888 DisplayMetrics getDisplayMetrics() {
889 return mDisplayMetrics;
890 }
891
Andrii Kulian8ee72852017-03-10 10:36:45 -0800892 int getRotation() {
893 return mRotation;
894 }
895
896 void setRotation(int newRotation) {
897 mRotation = newRotation;
898 }
899
900 int getLastOrientation() {
901 return mLastOrientation;
902 }
903
904 void setLastOrientation(int orientation) {
905 mLastOrientation = orientation;
906 }
907
908 boolean getAltOrientation() {
909 return mAltOrientation;
910 }
911
912 void setAltOrientation(boolean altOrientation) {
913 mAltOrientation = altOrientation;
914 }
915
916 int getLastWindowForcedOrientation() {
917 return mLastWindowForcedOrientation;
918 }
919
Andrii Kulian06d07d62017-03-14 11:11:47 -0700920 /**
921 * Update rotation of the display.
922 *
923 * Returns true if the rotation has been changed. In this case YOU MUST CALL
924 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
925 */
926 boolean updateRotationUnchecked(boolean inTransaction) {
927 if (mService.mDeferredRotationPauseCount > 0) {
928 // Rotation updates have been paused temporarily. Defer the update until
929 // updates have been resumed.
930 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
931 return false;
932 }
933
934 ScreenRotationAnimation screenRotationAnimation =
935 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
936 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
937 // Rotation updates cannot be performed while the previous rotation change
938 // animation is still in progress. Skip this update. We will try updating
939 // again after the animation is finished and the display is unfrozen.
940 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
941 return false;
942 }
943 if (mService.mDisplayFrozen) {
944 // Even if the screen rotation animation has finished (e.g. isAnimating
945 // returns false), there is still some time where we haven't yet unfrozen
946 // the display. We also need to abort rotation here.
947 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
948 "Deferring rotation, still finishing previous rotation");
949 return false;
950 }
951
952 if (!mService.mDisplayEnabled) {
953 // No point choosing a rotation if the display is not enabled.
954 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
955 return false;
956 }
957
958 final int oldRotation = mRotation;
959 final int lastOrientation = mLastOrientation;
960 final boolean oldAltOrientation = mAltOrientation;
961 int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation);
Robert Carr897215d2017-03-29 12:25:50 -0700962 final boolean rotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation,
963 rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -0700964
Robert Carr897215d2017-03-29 12:25:50 -0700965 if (rotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700966 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
967 if (seamlessRotated != null) {
968 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
969 // to complete (that is, waiting for windows to redraw). It's tempting to check
970 // w.mSeamlessRotationCount but that could be incorrect in the case of
971 // window-removal.
972 return false;
973 }
Andrii Kulian06d07d62017-03-14 11:11:47 -0700974 }
975
976 // TODO: Implement forced rotation changes.
977 // Set mAltOrientation to indicate that the application is receiving
978 // an orientation that has different metrics than it expected.
979 // eg. Portrait instead of Landscape.
980
981 final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw(
982 lastOrientation, rotation);
983
984 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Selected orientation " + lastOrientation
985 + ", got rotation " + rotation + " which has "
986 + (altOrientation ? "incompatible" : "compatible") + " metrics");
987
988 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
989 // No change.
990 return false;
991 }
992
993 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Rotation changed to " + rotation
994 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
995 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
996
997 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
998 mService.mWaitingForConfig = true;
999 }
1000
1001 mRotation = rotation;
1002 mAltOrientation = altOrientation;
1003 if (isDefaultDisplay) {
1004 mService.mPolicy.setRotationLw(rotation);
1005 }
1006
1007 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1008 mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
1009 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1010 WINDOW_FREEZE_TIMEOUT_DURATION);
1011
1012 setLayoutNeeded();
1013 final int[] anim = new int[2];
1014 if (isDimming()) {
1015 anim[0] = anim[1] = 0;
1016 } else {
1017 mService.mPolicy.selectRotationAnimationLw(anim);
1018 }
1019
1020 if (!rotateSeamlessly) {
Bryce Lee8f853582017-06-05 17:25:59 -07001021 mService.startFreezingDisplayLocked(inTransaction, anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001022 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1023 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1024 mDisplayId);
1025 } else {
1026 // The screen rotation animation uses a screenshot to freeze the screen
1027 // while windows resize underneath.
1028 // When we are rotating seamlessly, we allow the elements to transition
1029 // to their rotated state independently and without a freeze required.
1030 screenRotationAnimation = null;
1031
1032 // We have to reset this in case a window was removed before it
1033 // finished seamless rotation.
1034 mService.mSeamlessRotationCount = 0;
1035 }
1036
1037 // We need to update our screen size information to match the new rotation. If the rotation
1038 // has actually changed then this method will return true and, according to the comment at
1039 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1040 // By updating the Display info here it will be available to
1041 // #computeScreenConfiguration() later.
1042 updateDisplayAndOrientation(getConfiguration().uiMode);
1043
1044 if (!inTransaction) {
1045 if (SHOW_TRANSACTIONS) {
1046 Slog.i(TAG_WM, ">>> OPEN TRANSACTION setRotationUnchecked");
1047 }
1048 mService.openSurfaceTransaction();
1049 }
1050 try {
1051 // NOTE: We disable the rotation in the emulator because
1052 // it doesn't support hardware OpenGL emulation yet.
1053 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1054 && screenRotationAnimation.hasScreenshot()) {
1055 if (screenRotationAnimation.setRotationInTransaction(
1056 rotation, mService.mFxSession,
1057 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1058 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1059 mService.scheduleAnimationLocked();
1060 }
1061 }
1062
1063 if (rotateSeamlessly) {
1064 forAllWindows(w -> {
1065 w.mWinAnimator.seamlesslyRotateWindow(oldRotation, rotation);
1066 }, true /* traverseTopToBottom */);
1067 }
1068
1069 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
1070 } finally {
1071 if (!inTransaction) {
1072 mService.closeSurfaceTransaction();
1073 if (SHOW_LIGHT_TRANSACTIONS) {
1074 Slog.i(TAG_WM, "<<< CLOSE TRANSACTION setRotationUnchecked");
1075 }
1076 }
1077 }
1078
1079 forAllWindows(w -> {
1080 // Discard surface after orientation change, these can't be reused.
1081 if (w.mAppToken != null) {
1082 w.mAppToken.destroySavedSurfaces();
1083 }
1084 if (w.mHasSurface && !rotateSeamlessly) {
1085 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001086 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001087 mService.mRoot.mOrientationChangeComplete = false;
1088 w.mLastFreezeDuration = 0;
1089 }
1090 w.mReportOrientationChanged = true;
1091 }, true /* traverseTopToBottom */);
1092
1093 if (rotateSeamlessly) {
1094 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1095 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1096 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1097 }
1098
1099 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1100 final WindowManagerService.RotationWatcher rotationWatcher
1101 = mService.mRotationWatchers.get(i);
1102 if (rotationWatcher.mDisplayId == mDisplayId) {
1103 try {
1104 rotationWatcher.mWatcher.onRotationChanged(rotation);
1105 } catch (RemoteException e) {
1106 // Ignore
1107 }
1108 }
1109 }
1110
1111 // TODO (multi-display): Magnification is supported only for the default display.
1112 // Announce rotation only if we will not animate as we already have the
1113 // windows in final state. Otherwise, we make this call at the rotation end.
1114 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1115 && isDefaultDisplay) {
1116 mService.mAccessibilityController.onRotationChangedLocked(this);
1117 }
1118
1119 return true;
1120 }
1121
1122 /**
1123 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1124 * changed.
1125 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1126 */
1127 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1128 // Use the effective "visual" dimensions based on current rotation
1129 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1130 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1131 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1132 int dw = realdw;
1133 int dh = realdh;
1134
1135 if (mAltOrientation) {
1136 if (realdw > realdh) {
1137 // Turn landscape into portrait.
1138 int maxw = (int)(realdh/1.3f);
1139 if (maxw < realdw) {
1140 dw = maxw;
1141 }
1142 } else {
1143 // Turn portrait into landscape.
1144 int maxh = (int)(realdw/1.3f);
1145 if (maxh < realdh) {
1146 dh = maxh;
1147 }
1148 }
1149 }
1150
1151 // Update application display metrics.
1152 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
1153 mDisplayId);
1154 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
1155 mDisplayId);
1156 mDisplayInfo.rotation = mRotation;
1157 mDisplayInfo.logicalWidth = dw;
1158 mDisplayInfo.logicalHeight = dh;
1159 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1160 mDisplayInfo.appWidth = appWidth;
1161 mDisplayInfo.appHeight = appHeight;
1162 if (isDefaultDisplay) {
1163 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1164 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1165 }
1166 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1167 if (mDisplayScalingDisabled) {
1168 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1169 } else {
1170 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1171 }
1172
1173 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
1174 mDisplayInfo);
1175
1176 mBaseDisplayRect.set(0, 0, dw, dh);
1177
1178 if (isDefaultDisplay) {
1179 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1180 mCompatDisplayMetrics);
1181 }
1182 return mDisplayInfo;
1183 }
1184
1185 /**
1186 * Compute display configuration based on display properties and policy settings.
1187 * Do not call if mDisplayReady == false.
1188 */
1189 void computeScreenConfiguration(Configuration config) {
1190 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1191
1192 final int dw = displayInfo.logicalWidth;
1193 final int dh = displayInfo.logicalHeight;
1194 config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT :
1195 Configuration.ORIENTATION_LANDSCAPE;
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001196
Andrii Kulian06d07d62017-03-14 11:11:47 -07001197 config.screenWidthDp =
1198 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
1199 config.uiMode, mDisplayId) / mDisplayMetrics.density);
1200 config.screenHeightDp =
1201 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
1202 config.uiMode, mDisplayId) / mDisplayMetrics.density);
Bryce Lee7566d762017-03-30 09:34:15 -07001203
1204 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh, mTmpRect);
1205 final int leftInset = mTmpRect.left;
1206 final int topInset = mTmpRect.top;
1207 // appBounds at the root level should mirror the app screen size.
1208 config.setAppBounds(leftInset /*left*/, topInset /*top*/, leftInset + displayInfo.appWidth /*right*/,
1209 topInset + displayInfo.appHeight /*bottom*/);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001210 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1211 || displayInfo.rotation == Surface.ROTATION_270);
1212
1213 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
1214 mDisplayMetrics.density, config);
1215
1216 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1217 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1218 ? Configuration.SCREENLAYOUT_ROUND_YES
1219 : Configuration.SCREENLAYOUT_ROUND_NO);
1220
1221 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1222 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1223 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1224 dh, mDisplayId);
1225 config.densityDpi = displayInfo.logicalDensityDpi;
1226
1227 config.colorMode =
1228 (displayInfo.isHdr()
1229 ? Configuration.COLOR_MODE_HDR_YES
1230 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001231 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001232 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1233 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1234
1235 // Update the configuration based on available input devices, lid switch,
1236 // and platform configuration.
1237 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1238 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1239 config.navigation = Configuration.NAVIGATION_NONAV;
1240
1241 int keyboardPresence = 0;
1242 int navigationPresence = 0;
1243 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1244 final int len = devices != null ? devices.length : 0;
1245 for (int i = 0; i < len; i++) {
1246 InputDevice device = devices[i];
1247 if (!device.isVirtual()) {
1248 final int sources = device.getSources();
1249 final int presenceFlag = device.isExternal() ?
1250 WindowManagerPolicy.PRESENCE_EXTERNAL :
1251 WindowManagerPolicy.PRESENCE_INTERNAL;
1252
1253 // TODO(multi-display): Configure on per-display basis.
1254 if (mService.mIsTouchDevice) {
1255 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1256 InputDevice.SOURCE_TOUCHSCREEN) {
1257 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1258 }
1259 } else {
1260 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1261 }
1262
1263 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1264 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1265 navigationPresence |= presenceFlag;
1266 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1267 && config.navigation == Configuration.NAVIGATION_NONAV) {
1268 config.navigation = Configuration.NAVIGATION_DPAD;
1269 navigationPresence |= presenceFlag;
1270 }
1271
1272 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1273 config.keyboard = Configuration.KEYBOARD_QWERTY;
1274 keyboardPresence |= presenceFlag;
1275 }
1276 }
1277 }
1278
1279 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1280 config.navigation = Configuration.NAVIGATION_DPAD;
1281 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1282 }
1283
1284 // Determine whether a hard keyboard is available and enabled.
1285 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1286 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1287 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1288 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1289 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1290 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1291 }
1292
1293 // Let the policy update hidden states.
1294 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1295 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1296 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1297 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1298 }
1299
1300 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1301 int displayId) {
1302 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1303 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1304 final int unrotDw, unrotDh;
1305 if (rotated) {
1306 unrotDw = dh;
1307 unrotDh = dw;
1308 } else {
1309 unrotDw = dw;
1310 unrotDh = dh;
1311 }
1312 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1313 displayId);
1314 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1315 displayId);
1316 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1317 displayId);
1318 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1319 displayId);
1320 return sw;
1321 }
1322
1323 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1324 DisplayMetrics dm, int dw, int dh, int displayId) {
1325 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
1326 displayId);
1327 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
1328 uiMode, displayId);
1329 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1330 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1331 if (curSize == 0 || size < curSize) {
1332 curSize = size;
1333 }
1334 return curSize;
1335 }
1336
1337 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1338 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1339
1340 // We need to determine the smallest width that will occur under normal
1341 // operation. To this, start with the base screen size and compute the
1342 // width under the different possible rotations. We need to un-rotate
1343 // the current screen dimensions before doing this.
1344 int unrotDw, unrotDh;
1345 if (rotated) {
1346 unrotDw = dh;
1347 unrotDh = dw;
1348 } else {
1349 unrotDw = dw;
1350 unrotDh = dh;
1351 }
1352 displayInfo.smallestNominalAppWidth = 1<<30;
1353 displayInfo.smallestNominalAppHeight = 1<<30;
1354 displayInfo.largestNominalAppWidth = 0;
1355 displayInfo.largestNominalAppHeight = 0;
1356 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1357 unrotDh);
1358 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1359 unrotDw);
1360 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1361 unrotDh);
1362 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1363 unrotDw);
1364 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1365 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1366 displayId);
1367 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1368 displayId);
1369 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1370 displayId);
1371 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1372 displayId);
1373 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1374 outConfig.screenLayout = sl;
1375 }
1376
1377 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1378 int uiMode, int displayId) {
1379 // Get the app screen size at this rotation.
1380 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId);
1381 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId);
1382
1383 // Compute the screen layout size class for this rotation.
1384 int longSize = w;
1385 int shortSize = h;
1386 if (longSize < shortSize) {
1387 int tmp = longSize;
1388 longSize = shortSize;
1389 shortSize = tmp;
1390 }
1391 longSize = (int)(longSize/density);
1392 shortSize = (int)(shortSize/density);
1393 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1394 }
1395
1396 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1397 int uiMode, int dw, int dh) {
1398 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
1399 displayId);
1400 if (width < displayInfo.smallestNominalAppWidth) {
1401 displayInfo.smallestNominalAppWidth = width;
1402 }
1403 if (width > displayInfo.largestNominalAppWidth) {
1404 displayInfo.largestNominalAppWidth = width;
1405 }
1406 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
1407 displayId);
1408 if (height < displayInfo.smallestNominalAppHeight) {
1409 displayInfo.smallestNominalAppHeight = height;
1410 }
1411 if (height > displayInfo.largestNominalAppHeight) {
1412 displayInfo.largestNominalAppHeight = height;
1413 }
1414 }
1415
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001416 DockedStackDividerController getDockedDividerController() {
1417 return mDividerControllerLocked;
1418 }
1419
Winson Chung655332c2016-10-31 13:14:28 -07001420 PinnedStackController getPinnedStackController() {
1421 return mPinnedStackControllerLocked;
1422 }
1423
Jeff Browna506a6e2013-06-04 00:02:38 -07001424 /**
1425 * Returns true if the specified UID has access to this display.
1426 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001427 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001428 return mDisplay.hasAccess(uid);
1429 }
1430
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001431 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001432 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001433 }
1434
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001435 TaskStack getHomeStack() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001436 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001437 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
Craig Mautnere0a38842013-12-16 16:14:02 -08001438 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07001439 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001440 }
1441
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001442 TaskStack getStackById(int stackId) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001443 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1444 final TaskStack stack = mTaskStackContainers.get(i);
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001445 if (stack.mStackId == stackId) {
1446 return stack;
1447 }
1448 }
1449 return null;
1450 }
1451
Bryce Lee48f4b572017-04-10 10:54:15 -07001452 @VisibleForTesting
1453 int getStackCount() {
1454 return mTaskStackContainers.size();
1455 }
1456
1457 @VisibleForTesting
1458 int getStaskPosById(int stackId) {
1459 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1460 final TaskStack stack = mTaskStackContainers.get(i);
1461 if (stack.mStackId == stackId) {
1462 return i;
1463 }
1464 }
1465 return -1;
1466 }
1467
Andrii Kulian441e4492016-09-29 15:25:00 -07001468 @Override
1469 void onConfigurationChanged(Configuration newParentConfig) {
1470 super.onConfigurationChanged(newParentConfig);
1471
Andrii Kulian3a507b52016-09-19 18:14:12 -07001472 // The display size information is heavily dependent on the resources in the current
1473 // configuration, so we need to reconfigure it every time the configuration changes.
1474 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1475 mService.reconfigureDisplayLocked(this);
1476
1477 getDockedDividerController().onConfigurationChanged();
Winson Chung655332c2016-10-31 13:14:28 -07001478 getPinnedStackController().onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -07001479 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001480
Andrii Kulian441e4492016-09-29 15:25:00 -07001481 /**
1482 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1483 * bounds were updated.
1484 */
1485 void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001486 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1487 final TaskStack stack = mTaskStackContainers.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001488 if (stack.updateBoundsAfterConfigChange()) {
Andrii Kulian3a507b52016-09-19 18:14:12 -07001489 changedStackList.add(stack.mStackId);
1490 }
1491 }
Winson Chung32c566f2017-04-11 18:31:21 -07001492
1493 // If there was no pinned stack, we still need to notify the controller of the display info
1494 // update as a result of the config change. We do this here to consolidate the flow between
1495 // changes when there is and is not a stack.
1496 if (getStackById(PINNED_STACK_ID) == null) {
1497 mPinnedStackControllerLocked.onDisplayInfoChanged();
1498 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001499 }
1500
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001501 @Override
1502 boolean fillsParent() {
1503 return true;
1504 }
1505
1506 @Override
1507 boolean isVisible() {
1508 return true;
1509 }
1510
1511 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001512 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001513 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001514 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001515 }
1516
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001517 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001518 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1519 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1520 // target, or here in order if there isn't an IME target.
1521 if (traverseTopToBottom) {
1522 for (int i = mChildren.size() - 1; i >= 0; --i) {
1523 final DisplayChildWindowContainer child = mChildren.get(i);
1524 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1525 // In this case the Ime windows will be processed above their target so we skip
1526 // here.
1527 continue;
1528 }
1529 if (child.forAllWindows(callback, traverseTopToBottom)) {
1530 return true;
1531 }
1532 }
1533 } else {
1534 final int count = mChildren.size();
1535 for (int i = 0; i < count; i++) {
1536 final DisplayChildWindowContainer child = mChildren.get(i);
1537 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1538 // In this case the Ime windows will be processed above their target so we skip
1539 // here.
1540 continue;
1541 }
1542 if (child.forAllWindows(callback, traverseTopToBottom)) {
1543 return true;
1544 }
1545 }
1546 }
1547 return false;
1548 }
1549
1550 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1551 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1552 }
1553
Wale Ogunwale399c8692017-05-08 14:22:42 -07001554 @Override
1555 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001556 final WindowManagerPolicy policy = mService.mPolicy;
1557
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001558 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001559 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001560 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08001561 "Display is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001562 // If the display is frozen, some activities may be in the middle of restarting, and
1563 // thus have removed their old window. If the window has the flag to hide the lock
1564 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1565 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001566 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001567 } else if (policy.isKeyguardLocked()) {
1568 // Use the last orientation the while the display is frozen with the keyguard
1569 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1570 // window. We don't want to check the show when locked window directly though as
1571 // things aren't stable while the display is frozen, for example the window could be
1572 // momentarily unavailable due to activity relaunch.
1573 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
Andrii Kulian8ee72852017-03-10 10:36:45 -08001574 + "return " + mLastOrientation);
1575 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001576 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001577 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001578 final int orientation = mAboveAppWindowsContainers.getOrientation();
1579 if (orientation != SCREEN_ORIENTATION_UNSET) {
1580 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001581 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001582 }
1583
Wale Ogunwale399c8692017-05-08 14:22:42 -07001584 // Top system windows are not requesting an orientation. Start searching from apps.
1585 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001586 }
1587
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001588 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001589 // Check if display metrics changed and update base values if needed.
1590 updateBaseDisplayMetricsIfNeeded();
1591
Craig Mautner722285e2012-09-07 13:55:58 -07001592 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001593 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001594
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001595 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1596 mTaskStackContainers.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001597 }
Craig Mautner722285e2012-09-07 13:55:58 -07001598 }
1599
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001600 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001601 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1602 if (displayManagerInternal != null) {
1603 // Bootstrap the default logical display from the display manager.
1604 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1605 if (newDisplayInfo != null) {
1606 mDisplayInfo.copyFrom(newDisplayInfo);
1607 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001608 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001609
Andrii Kuliancd097992017-03-23 18:31:59 -07001610 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1611 mDisplayInfo.logicalDensityDpi);
1612 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1613 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1614 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001615 }
1616
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001617 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001618 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -08001619 final int orientation = mDisplayInfo.rotation;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07001620 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
Craig Mautner4a1cb222013-12-04 16:14:06 -08001621 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1622 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001623 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -08001624 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001625 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -08001626 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001627 out.set(left, top, left + width, top + height);
1628 }
1629
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07001630 private void getLogicalDisplayRect(Rect out, int orientation) {
1631 getLogicalDisplayRect(out);
1632
1633 // Rotate the Rect if needed.
1634 final int currentRotation = mDisplayInfo.rotation;
1635 final int rotationDelta = deltaRotation(currentRotation, orientation);
1636 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
1637 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
1638 mTmpRectF.set(out);
1639 mTmpMatrix.mapRect(mTmpRectF);
1640 mTmpRectF.round(out);
1641 }
1642 }
1643
Andrii Kuliancd097992017-03-23 18:31:59 -07001644 /**
1645 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1646 * values.
1647 */
1648 private void updateBaseDisplayMetricsIfNeeded() {
1649 // Get real display metrics without overrides from WM.
1650 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1651 final int orientation = mDisplayInfo.rotation;
1652 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1653 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1654 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1655 final int newDensity = mDisplayInfo.logicalDensityDpi;
1656
1657 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1658 || mInitialDisplayHeight != newHeight
1659 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi;
1660
1661 if (displayMetricsChanged) {
1662 // Check if display size or density is forced.
1663 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1664 || mBaseDisplayHeight != mInitialDisplayHeight;
1665 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1666
1667 // If there is an override set for base values - use it, otherwise use new values.
1668 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1669 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1670 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1671
1672 // Real display metrics changed, so we should also update initial values.
1673 mInitialDisplayWidth = newWidth;
1674 mInitialDisplayHeight = newHeight;
1675 mInitialDisplayDensity = newDensity;
1676 mService.reconfigureDisplayLocked(this);
1677 }
1678 }
1679
Bryce Lee27cec322017-03-21 09:41:37 -07001680 /** Sets the maximum width the screen resolution can be */
1681 void setMaxUiWidth(int width) {
1682 if (DEBUG_DISPLAY) {
1683 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1684 }
1685
1686 mMaxUiWidth = width;
1687
1688 // Update existing metrics.
1689 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1690 }
1691
1692 /** Update base (override) display metrics. */
1693 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1694 mBaseDisplayWidth = baseWidth;
1695 mBaseDisplayHeight = baseHeight;
1696 mBaseDisplayDensity = baseDensity;
1697
1698 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1699 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1700 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1701 mBaseDisplayWidth = mMaxUiWidth;
1702
1703 if (DEBUG_DISPLAY) {
1704 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1705 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1706 + " on display:" + getDisplayId());
1707 }
1708 }
1709
1710 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
1711 }
1712
Chong Zhangf66db432016-01-13 10:39:51 -08001713 void getContentRect(Rect out) {
1714 out.set(mContentRect);
1715 }
1716
Wale Ogunwale1666e312016-12-16 11:27:18 -08001717 TaskStack addStackToDisplay(int stackId, boolean onTop) {
1718 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1719 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001720
Wale Ogunwale1666e312016-12-16 11:27:18 -08001721 TaskStack stack = getStackById(stackId);
1722 if (stack != null) {
1723 // It's already attached to the display...clear mDeferRemoval and move stack to
1724 // appropriate z-order on display as needed.
1725 stack.mDeferRemoval = false;
1726 // We're not moving the display to front when we're adding stacks, only when
1727 // requested to change the position of stack explicitly.
1728 mTaskStackContainers.positionChildAt(onTop ? POSITION_TOP : POSITION_BOTTOM, stack,
1729 false /* includingParents */);
Andrii Kulian839def92016-11-02 10:58:58 -07001730 } else {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001731 stack = new TaskStack(mService, stackId);
Andrii Kulian839def92016-11-02 10:58:58 -07001732 mTaskStackContainers.addStackToDisplay(stack, onTop);
1733 }
1734
Wale Ogunwale1666e312016-12-16 11:27:18 -08001735 if (stackId == DOCKED_STACK_ID) {
1736 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Andrii Kulian839def92016-11-02 10:58:58 -07001737 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001738 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001739 }
1740
Andrii Kulian51c1b672017-04-07 18:39:32 -07001741 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001742 final DisplayContent prevDc = stack.getDisplayContent();
1743 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001744 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1745 + " which is not currently attached to any display");
1746 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001747 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001748 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1749 + " to its current displayId=" + mDisplayId);
1750 }
1751
Wale Ogunwale1666e312016-12-16 11:27:18 -08001752 prevDc.mTaskStackContainers.removeStackFromDisplay(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001753 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001754 }
1755
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001756 @Override
1757 protected void addChild(DisplayChildWindowContainer child,
1758 Comparator<DisplayChildWindowContainer> comparator) {
1759 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1760 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001761
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001762 @Override
1763 protected void addChild(DisplayChildWindowContainer child, int index) {
1764 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1765 }
1766
1767 @Override
1768 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001769 // Only allow removal of direct children from this display if the display is in the process
1770 // of been removed.
1771 if (mRemovingDisplay) {
1772 super.removeChild(child);
1773 return;
1774 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001775 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001776 }
1777
Andrii Kuliand2765632016-12-12 22:26:34 -08001778 @Override
1779 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1780 // Children of the display are statically ordered, so the real intention here is to perform
1781 // the operation on the display and not the static direct children.
1782 getParent().positionChildAt(position, this, includingParents);
1783 }
1784
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001785 int taskIdFromPoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001786 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1787 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001788 final int taskId = stack.taskIdFromPoint(x, y);
1789 if (taskId != -1) {
1790 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001791 }
1792 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001793 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001794 }
1795
Chong Zhang8e89b312015-09-09 15:09:30 -07001796 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001797 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001798 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001799 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001800 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001801 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001802 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001803 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1804 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -07001805 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001806 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001807 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001808
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001809 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1810 if (mTmpTaskForResizePointSearchResult.searchDone) {
1811 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001812 }
1813 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001814 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001815 }
1816
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001817 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001818 // The provided task is the task on this display with focus, so if WindowManagerService's
1819 // focused app is not on this display, focusedTask will be null.
1820 if (focusedTask == null) {
1821 mTouchExcludeRegion.setEmpty();
1822 } else {
1823 mTouchExcludeRegion.set(mBaseDisplayRect);
1824 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1825 mTmpRect2.setEmpty();
1826 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1827 final TaskStack stack = mTaskStackContainers.get(stackNdx);
1828 stack.setTouchExcludeRegion(
1829 focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2);
1830 }
1831 // If we removed the focused task above, add it back and only leave its
1832 // outside touch area in the exclusion. TapDectector is not interested in
1833 // any touch inside the focused task itself.
1834 if (!mTmpRect2.isEmpty()) {
1835 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1836 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001837 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001838 final WindowState inputMethod = mService.mInputMethodWindow;
1839 if (inputMethod != null && inputMethod.isVisibleLw()) {
1840 // If the input method is visible and the user is typing, we don't want these touch
1841 // events to be intercepted and used to change focus. This would likely cause a
1842 // disappearance of the input method.
1843 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001844 if (inputMethod.getDisplayId() == mDisplayId) {
1845 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1846 } else {
1847 // IME is on a different display, so we need to update its tap detector.
1848 // TODO(multidisplay): Remove when IME will always appear on same display.
1849 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1850 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001851 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001852 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
1853 WindowState win = mTapExcludedWindows.get(i);
1854 win.getTouchableRegion(mTmpRegion);
1855 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1856 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001857 // TODO(multi-display): Support docked stacks on secondary displays.
1858 if (mDisplayId == DEFAULT_DISPLAY && getDockedStackLocked() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001859 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001860 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001861 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1862 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001863 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001864 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001865 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001866 }
1867
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001868 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001869 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001870 super.switchUser();
1871 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001872 }
1873
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001874 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001875 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1876 mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001877 }
1878 }
1879
1880 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001881 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -07001882 }
1883
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001884 private void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001885 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -07001886 }
1887
1888 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001889 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -07001890 }
1891
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001892 private void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001893 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -07001894 }
1895
Wale Ogunwale10124582016-09-15 20:25:50 -07001896 @Override
1897 void removeIfPossible() {
1898 if (isAnimating()) {
1899 mDeferredRemoval = true;
1900 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001901 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001902 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001903 }
1904
Wale Ogunwale10124582016-09-15 20:25:50 -07001905 @Override
1906 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001907 mRemovingDisplay = true;
1908 try {
1909 super.removeImmediately();
1910 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
1911 mDimLayerController.close();
Wale Ogunwale1666e312016-12-16 11:27:18 -08001912 if (mDisplayId == DEFAULT_DISPLAY && mService.canDispatchPointerEvents()) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001913 mService.unregisterPointerEventListener(mTapDetector);
1914 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1915 }
1916 } finally {
1917 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001918 }
Craig Mautner95da1082014-02-24 17:54:35 -08001919 }
1920
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001921 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001922 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001923 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001924 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1925
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001926 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001927 removeImmediately();
Craig Mautner95da1082014-02-24 17:54:35 -08001928 mService.onDisplayRemoved(mDisplayId);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001929 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001930 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001931 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001932 }
1933
Andrii Kulian0214ed92017-05-16 13:44:05 -07001934 /** @return 'true' if removal of this display content is deferred due to active animation. */
1935 boolean isRemovalDeferred() {
1936 return mDeferredRemoval;
1937 }
1938
Wale Ogunwale10124582016-09-15 20:25:50 -07001939 boolean animateForIme(float interpolatedValue, float animationTarget,
1940 float dividerAnimationTarget) {
1941 boolean updated = false;
1942
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001943 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1944 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001945 if (stack == null || !stack.isAdjustedForIme()) {
1946 continue;
1947 }
1948
1949 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
1950 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1951 updated = true;
1952 } else {
1953 mDividerControllerLocked.mLastAnimationProgress =
1954 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
1955 mDividerControllerLocked.mLastDividerProgress =
1956 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
1957 updated |= stack.updateAdjustForIme(
1958 mDividerControllerLocked.mLastAnimationProgress,
1959 mDividerControllerLocked.mLastDividerProgress,
1960 false /* force */);
1961 }
1962 if (interpolatedValue >= 1f) {
1963 stack.endImeAdjustAnimation();
1964 }
1965 }
1966
1967 return updated;
1968 }
1969
1970 boolean clearImeAdjustAnimation() {
1971 boolean changed = false;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001972 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1973 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001974 if (stack != null && stack.isAdjustedForIme()) {
1975 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1976 changed = true;
1977 }
1978 }
1979 return changed;
1980 }
1981
1982 void beginImeAdjustAnimation() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001983 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1984 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001985 if (stack.isVisible() && stack.isAdjustedForIme()) {
1986 stack.beginImeAdjustAnimation();
1987 }
1988 }
1989 }
1990
1991 void adjustForImeIfNeeded() {
1992 final WindowState imeWin = mService.mInputMethodWindow;
1993 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
1994 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale1666e312016-12-16 11:27:18 -08001995 final boolean dockVisible = isStackVisible(DOCKED_STACK_ID);
Wale Ogunwale10124582016-09-15 20:25:50 -07001996 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
1997 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
1998 imeTargetStack.getDockSide() : DOCKED_INVALID;
1999 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2000 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2001 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
2002 final int imeHeight = mService.mPolicy.getInputMethodWindowVisibleHeightLw();
2003 final boolean imeHeightChanged = imeVisible &&
2004 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2005
2006 // The divider could be adjusted for IME position, or be thinner than usual,
2007 // or both. There are three possible cases:
2008 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2009 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2010 // - If IME is not visible, divider is not moved and is normal width.
2011
2012 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002013 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
2014 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002015 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Winson Chungfef058d2017-04-25 14:43:10 -07002016 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom) &&
2017 StackId.isStackAffectedByDragResizing(stack.mStackId)) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002018 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2019 } else {
2020 stack.resetAdjustedForIme(false);
2021 }
2022 }
2023 mDividerControllerLocked.setAdjustedForIme(
2024 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2025 } else {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002026 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
2027 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002028 stack.resetAdjustedForIme(!dockVisible);
2029 }
2030 mDividerControllerLocked.setAdjustedForIme(
2031 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2032 }
Winson Chung655332c2016-10-31 13:14:28 -07002033 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002034 }
2035
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002036 void setInputMethodAnimLayerAdjustment(int adj) {
2037 if (DEBUG_LAYERS) Slog.v(TAG_WM, "Setting im layer adj to " + adj);
2038 mInputMethodAnimLayerAdjustment = adj;
Robert Carrdee1b3f2017-02-27 11:33:33 -08002039 assignWindowLayers(false /* relayoutNeeded */);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002040 }
2041
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002042 /**
2043 * If a window that has an animation specifying a colored background and the current wallpaper
2044 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2045 * suddenly disappear.
2046 */
2047 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002048 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2049 w -> w.mIsWallpaper && w.isVisibleNow());
2050
2051 if (visibleWallpaper != null) {
2052 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002053 }
2054 return winAnimator.mAnimLayer;
2055 }
2056
Wale Ogunwale10124582016-09-15 20:25:50 -07002057 void prepareFreezingTaskBounds() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002058 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
2059 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002060 stack.prepareFreezingTaskBounds();
2061 }
2062 }
2063
Wale Ogunwale94744212015-09-21 19:01:47 -07002064 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002065 getLogicalDisplayRect(mTmpRect, newRotation);
2066
2067 // Compute a transform matrix to undo the coordinate space transformation,
2068 // and present the window at the same physical position it previously occupied.
2069 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2070 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2071
2072 mTmpRectF.set(bounds);
2073 mTmpMatrix.mapRect(mTmpRectF);
2074 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002075 }
2076
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002077 static int deltaRotation(int oldRotation, int newRotation) {
2078 int delta = newRotation - oldRotation;
2079 if (delta < 0) delta += 4;
2080 return delta;
2081 }
2082
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002083 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002084 Matrix outMatrix) {
2085 // For rotations without Z-ordering we don't need the target rectangle's position.
2086 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2087 displayHeight, outMatrix);
2088 }
2089
2090 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2091 float displayWidth, float displayHeight, Matrix outMatrix) {
2092 switch (rotation) {
2093 case ROTATION_0:
2094 outMatrix.reset();
2095 break;
2096 case ROTATION_270:
2097 outMatrix.setRotate(270, 0, 0);
2098 outMatrix.postTranslate(0, displayHeight);
2099 outMatrix.postTranslate(rectTop, 0);
2100 break;
2101 case ROTATION_180:
2102 outMatrix.reset();
2103 break;
2104 case ROTATION_90:
2105 outMatrix.setRotate(90, 0, 0);
2106 outMatrix.postTranslate(displayWidth, 0);
2107 outMatrix.postTranslate(-rectTop, rectLeft);
2108 break;
2109 }
2110 }
2111
Steven Timotiusaf03df62017-07-18 16:56:43 -07002112 void writeToProto(ProtoOutputStream proto, long fieldId) {
2113 final long token = proto.start(fieldId);
2114 proto.write(ID, mDisplayId);
2115 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
2116 final TaskStack stack = mTaskStackContainers.get(stackNdx);
2117 stack.writeToProto(proto, STACKS);
2118 }
2119 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2120 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
2121 for (int i = mAboveAppWindowsContainers.size() - 1; i >= 0; --i) {
2122 final WindowToken windowToken = mAboveAppWindowsContainers.get(i);
2123 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS);
2124 }
2125 for (int i = mBelowAppWindowsContainers.size() - 1; i >= 0; --i) {
2126 final WindowToken windowToken = mBelowAppWindowsContainers.get(i);
2127 windowToken.writeToProto(proto, BELOW_APP_WINDOWS);
2128 }
2129 for (int i = mImeWindowsContainers.size() - 1; i >= 0; --i) {
2130 final WindowToken windowToken = mImeWindowsContainers.get(i);
2131 windowToken.writeToProto(proto, IME_WINDOWS);
2132 }
2133 proto.write(DPI, mBaseDisplayDensity);
2134 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
2135 proto.end(token);
2136 }
2137
Craig Mautnera91f9e22012-09-14 16:22:08 -07002138 public void dump(String prefix, PrintWriter pw) {
2139 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2140 final String subPrefix = " " + prefix;
2141 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2142 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2143 pw.print("dpi");
2144 if (mInitialDisplayWidth != mBaseDisplayWidth
2145 || mInitialDisplayHeight != mBaseDisplayHeight
2146 || mInitialDisplayDensity != mBaseDisplayDensity) {
2147 pw.print(" base=");
2148 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2149 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2150 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002151 if (mDisplayScalingDisabled) {
2152 pw.println(" noscale");
2153 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002154 pw.print(" cur=");
2155 pw.print(mDisplayInfo.logicalWidth);
2156 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2157 pw.print(" app=");
2158 pw.print(mDisplayInfo.appWidth);
2159 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2160 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2161 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2162 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2163 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002164 pw.println(subPrefix + "deferred=" + mDeferredRemoval
2165 + " mLayoutNeeded=" + mLayoutNeeded);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002166
Craig Mautnerdc548482014-02-05 13:35:24 -08002167 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002168 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002169 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
2170 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002171 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002172 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002173
Craig Mautnerdc548482014-02-05 13:35:24 -08002174 pw.println();
2175 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002176 pw.println();
2177 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002178 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002179 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002180 pw.print(" Exiting #"); pw.print(i);
2181 pw.print(' '); pw.print(token);
2182 pw.println(':');
2183 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002184 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002185 }
Craig Mautner59c00972012-07-30 12:10:24 -07002186 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002187 mDimLayerController.dump(prefix, pw);
Jorim Jaggi31f71702016-05-04 16:43:04 -07002188 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002189 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002190 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002191 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002192
2193 if (mInputMethodAnimLayerAdjustment != 0) {
2194 pw.println(subPrefix
2195 + "mInputMethodAnimLayerAdjustment=" + mInputMethodAnimLayerAdjustment);
2196 }
Craig Mautner59c00972012-07-30 12:10:24 -07002197 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002198
2199 @Override
2200 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002201 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002202 }
2203
2204 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002205 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002206 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002207
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002208 /** Checks if stack with provided id is visible on this display. */
2209 boolean isStackVisible(int stackId) {
2210 final TaskStack stack = getStackById(stackId);
2211 return (stack != null && stack.isVisible());
2212 }
2213
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08002214 /**
2215 * @return The docked stack, but only if it is visible, and {@code null} otherwise.
2216 */
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002217 TaskStack getDockedStackLocked() {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002218 final TaskStack stack = getStackById(DOCKED_STACK_ID);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002219 return (stack != null && stack.isVisible()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002220 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002221
2222 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08002223 * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not
Jorim Jaggife762342016-10-13 14:33:27 +02002224 * visible.
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08002225 */
Jorim Jaggife762342016-10-13 14:33:27 +02002226 TaskStack getDockedStackIgnoringVisibility() {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002227 return getStackById(DOCKED_STACK_ID);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08002228 }
2229
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002230 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002231 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002232 final int x = (int) xf;
2233 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002234 final WindowState touchedWin = getWindow(w -> {
2235 final int flags = w.mAttrs.flags;
2236 if (!w.isVisibleLw()) {
2237 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002238 }
2239 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002240 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002241 }
2242
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002243 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002244 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002245 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002246 }
2247
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002248 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002249
2250 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002251 return mTmpRegion.contains(x, y) || touchFlags == 0;
2252 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002253
2254 return touchedWin;
2255 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002256
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002257 boolean canAddToastWindowForUid(int uid) {
2258 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002259 // Also if the app is focused adding more than one toast at
2260 // a time for better backwards compatibility.
2261 final WindowState focusedWindowForUid = getWindow(w ->
2262 w.mOwnerUid == uid && w.isFocused());
2263 if (focusedWindowForUid != null) {
2264 return true;
2265 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002266 final WindowState win = getWindow(w ->
2267 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2268 && !w.mWindowRemovalAllowed);
2269 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002270 }
2271
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002272 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002273 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2274 return;
2275 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002276
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002277 // Used to communicate the old focus to the callback method.
2278 mTmpWindow = oldFocus;
2279
2280 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002281 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002282
2283 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002284 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002285
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002286 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002287
2288 if (mTmpWindow == null) {
2289 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2290 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002291 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002292 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002293 }
2294
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002295 /** Updates the layer assignment of windows on this display. */
2296 void assignWindowLayers(boolean setLayoutNeeded) {
Wale Ogunwaled1880962016-11-08 10:31:59 -08002297 mLayersController.assignWindowLayers(this);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002298 if (setLayoutNeeded) {
2299 setLayoutNeeded();
2300 }
2301 }
2302
Wale Ogunwale1666e312016-12-16 11:27:18 -08002303 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2304 // moving containers or resizing them. Need to investigate the best way to have it automatically
2305 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002306 void layoutAndAssignWindowLayersIfNeeded() {
2307 mService.mWindowsChanged = true;
2308 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002309
2310 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2311 false /*updateInputWindows*/)) {
2312 assignWindowLayers(false /* setLayoutNeeded */);
2313 }
2314
2315 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2316 mService.mWindowPlacerLocked.performSurfacePlacement();
2317 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2318 }
2319
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002320 /** Returns true if a leaked surface was destroyed */
2321 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002322 // Used to indicate that a surface was leaked.
2323 mTmpWindow = null;
2324 forAllWindows(w -> {
2325 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002326 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002327 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002328 }
2329 if (!mService.mSessions.contains(wsa.mSession)) {
2330 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002331 + w + " surface=" + wsa.mSurfaceController
2332 + " token=" + w.mToken
2333 + " pid=" + w.mSession.mPid
2334 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002335 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002336 mService.mForceRemoves.add(w);
2337 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002338 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002339 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002340 + w + " surface=" + wsa.mSurfaceController
2341 + " token=" + w.mAppToken
2342 + " saved=" + w.hasSavedSurface());
2343 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002344 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002345 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002346 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002347 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002348
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002349 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002350 }
2351
2352 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002353 * Determine and return the window that should be the IME target.
2354 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2355 * @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 +00002356 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002357 WindowState computeImeTarget(boolean updateImeTarget) {
2358 if (mService.mInputMethodWindow == null) {
2359 // There isn't an IME so there shouldn't be a target...That was easy!
2360 if (updateImeTarget) {
2361 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2362 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
2363 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim, 0);
2364 }
2365 return null;
2366 }
2367
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002368 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2369 // same display. Or even when the current IME/target are not on the same screen as the next
2370 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002371 mUpdateImeTarget = updateImeTarget;
2372 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002373
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002374
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002375 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2376 // to be on top of it, but it is not -really- where input will go. So look down below
2377 // for a real window to target...
2378 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2379 final AppWindowToken token = target.mAppToken;
2380 if (token != null) {
2381 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2382 if (betterTarget != null) {
2383 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002384 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002385 }
2386 }
2387
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002388 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2389 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002390
2391 // Now, a special case -- if the last target's window is in the process of exiting, and is
2392 // above the new target, keep on the last target to avoid flicker. Consider for example a
2393 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2394 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2395 // scrim.
2396 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002397 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2398 && (target == null
2399 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002400 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002401 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002402 }
2403
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002404 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2405 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002406
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002407 if (target == null) {
2408 if (updateImeTarget) {
2409 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2410 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2411 + Debug.getCallers(4) : ""));
2412 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim, 0);
2413 }
2414
2415 return null;
2416 }
2417
2418 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002419 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2420 if (token != null) {
2421
2422 // Now some fun for dealing with window animations that modify the Z order. We need
2423 // to look at all windows below the current target that are in this app, finding the
2424 // highest visible one in layering.
2425 WindowState highestTarget = null;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002426 if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002427 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002428 }
2429
2430 if (highestTarget != null) {
2431 final AppTransition appTransition = mService.mAppTransition;
2432 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2433 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2434 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002435 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002436
2437 if (appTransition.isTransitionSet()) {
2438 // If we are currently setting up for an animation, hold everything until we
2439 // can find out what will happen.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002440 setInputMethodTarget(highestTarget, true, mInputMethodAnimLayerAdjustment);
2441 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002442 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002443 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002444 // If the window we are currently targeting is involved with an animation,
2445 // and it is on top of the next target we will be over, then hold off on
2446 // moving until that is done.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002447 setInputMethodTarget(highestTarget, true, mInputMethodAnimLayerAdjustment);
2448 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002449 }
2450 }
2451 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002452
2453 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2454 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
2455 setInputMethodTarget(target, false, target.mAppToken != null
Robert Carrdee1b3f2017-02-27 11:33:33 -08002456 ? target.mAppToken.getAnimLayerAdjustment() : 0);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002457 }
2458
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002459 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002460 }
2461
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002462 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim, int layerAdj) {
2463 if (target == mService.mInputMethodTarget
2464 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim
2465 && mInputMethodAnimLayerAdjustment == layerAdj) {
2466 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002467 }
2468
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002469 mService.mInputMethodTarget = target;
2470 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
2471 setInputMethodAnimLayerAdjustment(layerAdj);
2472 assignWindowLayers(false /* setLayoutNeeded */);
2473 }
2474
2475 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2476 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2477 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2478 }
2479
2480 // Used to indicate we have reached the first window in the range we are interested in.
2481 mTmpWindow = null;
2482
2483 // TODO: Figure-out a more efficient way to do this.
2484 final WindowState candidate = getWindow(w -> {
2485 if (w == top) {
2486 // Reached the first window in the range we are interested in.
2487 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002488 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002489 if (mTmpWindow == null) {
2490 return false;
2491 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002492
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002493 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2494 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002495 }
2496 // If we reached the bottom of the range of windows we are considering,
2497 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002498 if (w == bottom) {
2499 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002500 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002501 return false;
2502 });
2503
2504 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002505 }
2506
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002507 void setLayoutNeeded() {
2508 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2509 mLayoutNeeded = true;
2510 }
2511
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002512 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002513 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2514 mLayoutNeeded = false;
2515 }
2516
2517 boolean isLayoutNeeded() {
2518 return mLayoutNeeded;
2519 }
2520
Wale Ogunwale02319a62016-09-26 15:21:22 -07002521 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2522 if (mTokenMap.isEmpty()) {
2523 return;
2524 }
2525 pw.println(" Display #" + mDisplayId);
2526 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2527 while (it.hasNext()) {
2528 final WindowToken token = it.next();
2529 pw.print(" ");
2530 pw.print(token);
2531 if (dumpAll) {
2532 pw.println(':');
2533 token.dump(pw, " ");
2534 } else {
2535 pw.println();
2536 }
2537 }
2538 }
2539
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002540 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002541 final int[] index = new int[1];
2542 forAllWindows(w -> {
2543 final WindowStateAnimator wAnim = w.mWinAnimator;
2544 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2545 index[0] = index[0] + 1;
2546 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002547 }
2548
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002549 void enableSurfaceTrace(FileDescriptor fd) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002550 forAllWindows(w -> {
2551 w.mWinAnimator.enableSurfaceTrace(fd);
2552 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002553 }
2554
2555 void disableSurfaceTrace() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002556 forAllWindows(w -> {
2557 w.mWinAnimator.disableSurfaceTrace();
2558 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002559 }
2560
Jorim Jaggife762342016-10-13 14:33:27 +02002561 /**
2562 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2563 */
2564 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2565 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002566 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002567 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2568 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002569 w.mWinAnimator.setAnimation(
Jorim Jaggife762342016-10-13 14:33:27 +02002570 policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
2571 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002572 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002573 }
2574
Wale Ogunwale494009b82016-10-21 09:01:38 -07002575 boolean checkWaitingForWindows() {
2576
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002577 mHaveBootMsg = false;
2578 mHaveApp = false;
2579 mHaveWallpaper = false;
2580 mHaveKeyguard = true;
2581
2582 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002583 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2584 return true;
2585 }
2586 if (w.isDrawnLw()) {
2587 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002588 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002589 } else if (w.mAttrs.type == TYPE_APPLICATION
2590 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002591 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002592 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002593 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002594 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002595 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002596 }
2597 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002598 return false;
2599 });
2600
2601 if (visibleWindow != null) {
2602 // We have a visible window.
2603 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002604 }
2605
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002606 // if the wallpaper service is disabled on the device, we're never going to have
2607 // wallpaper, don't bother waiting for it
2608 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2609 com.android.internal.R.bool.config_enableWallpaperService)
2610 && !mService.mOnlyCore;
2611
Wale Ogunwale494009b82016-10-21 09:01:38 -07002612 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2613 "******** booted=" + mService.mSystemBooted
2614 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002615 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2616 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2617 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002618
2619 // If we are turning on the screen to show the boot message, don't do it until the boot
2620 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002621 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002622 return true;
2623 }
2624
2625 // If we are turning on the screen after the boot is completed normally, don't do so until
2626 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002627 if (mService.mSystemBooted
2628 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002629 return true;
2630 }
2631
2632 return false;
2633 }
2634
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002635 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002636 mTmpWindowAnimator = animator;
2637 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002638 }
2639
2640 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002641 resetAnimationBackgroundAnimator();
2642
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002643 // Used to indicate a detached wallpaper.
2644 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002645 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002646
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002647 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002648
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002649 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002650 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002651 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2652 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002653 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2654 }
2655 }
2656
2657 void prepareWindowSurfaces() {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002658 forAllWindows(mPrepareWindowSurfaces, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002659 }
2660
Wale Ogunwale494009b82016-10-21 09:01:38 -07002661 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002662 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002663 if (imFocus == null) {
2664 return false;
2665 }
2666
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002667 if (DEBUG_INPUT_METHOD) {
2668 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2669 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2670 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002671 }
2672
Wale Ogunwale494009b82016-10-21 09:01:38 -07002673 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2674
2675 if (DEBUG_INPUT_METHOD) {
2676 Slog.i(TAG_WM, "IM target client: " + imeClient);
2677 if (imeClient != null) {
2678 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2679 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2680 }
2681 }
2682
2683 return imeClient != null && imeClient.asBinder() == client.asBinder();
2684 }
2685
2686 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002687 final WindowState win = getWindow(
2688 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2689 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002690 }
2691
2692 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002693 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002694 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002695 final int curValue = w.mSystemUiVisibility;
2696 final int diff = (curValue ^ visibility) & globalDiff;
2697 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002698 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002699 w.mSeq++;
2700 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002701 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002702 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2703 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002704 visibility, newValue, diff);
2705 }
2706 } catch (RemoteException e) {
2707 // so sorry
2708 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002709 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002710 }
2711
2712 void onWindowFreezeTimeout() {
2713 Slog.w(TAG_WM, "Window freeze timeout expired.");
2714 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002715
2716 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002717 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002718 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002719 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002720 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002721 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2722 - mService.mDisplayFreezeTime);
2723 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002724 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002725 mService.mWindowPlacerLocked.performSurfacePlacement();
2726 }
2727
2728 void waitForAllWindowsDrawn() {
2729 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002730 forAllWindows(w -> {
2731 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2732 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2733 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002734 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002735 w.mLastContentInsets.set(-1, -1, -1, -1);
2736 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002737 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002738 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002739 }
2740
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002741 // TODO: Super crazy long method that should be broken down...
2742 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2743
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002744 final int dw = mDisplayInfo.logicalWidth;
2745 final int dh = mDisplayInfo.logicalHeight;
2746 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2747
2748 mTmpUpdateAllDrawn.clear();
2749
2750 int repeats = 0;
2751 do {
2752 repeats++;
2753 if (repeats > 6) {
2754 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2755 clearLayoutNeeded();
2756 break;
2757 }
2758
2759 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2760 pendingLayoutChanges);
2761
Andrii Kulian839def92016-11-02 10:58:58 -07002762 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2763 // the wallpaper window jumping across displays.
2764 // Remove check for default display when there will be support for multiple wallpaper
2765 // targets (on different displays).
2766 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002767 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002768 }
2769
2770 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2771 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2772 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2773 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002774 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002775 }
2776 }
2777
2778 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2779 setLayoutNeeded();
2780 }
2781
2782 // FIRST LOOP: Perform a layout, if needed.
2783 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2784 performLayout(repeats == 1, false /* updateInputWindows */);
2785 } else {
2786 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2787 }
2788
2789 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2790 pendingLayoutChanges = 0;
2791
2792 if (isDefaultDisplay) {
2793 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002794 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002795 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2796 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2797 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2798 }
2799 } while (pendingLayoutChanges != 0);
2800
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002801 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002802 resetDimming();
2803
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002804 mTmpRecoveringMemory = recoveringMemory;
2805 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002806
2807 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002808 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2809 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2810 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002811 true /* inTraversal, must call performTraversalInTrans... below */);
2812
2813 stopDimmingIfNeeded();
2814
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002815 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2816 if (wallpaperVisible != mLastWallpaperVisible) {
2817 mLastWallpaperVisible = wallpaperVisible;
2818 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2819 }
2820
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002821 while (!mTmpUpdateAllDrawn.isEmpty()) {
2822 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2823 // See if any windows have been drawn, so they (and others associated with them)
2824 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002825 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002826 }
2827
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002828 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002829 }
2830
2831 void performLayout(boolean initial, boolean updateInputWindows) {
2832 if (!isLayoutNeeded()) {
2833 return;
2834 }
2835 clearLayoutNeeded();
2836
2837 final int dw = mDisplayInfo.logicalWidth;
2838 final int dh = mDisplayInfo.logicalHeight;
2839
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002840 if (DEBUG_LAYOUT) {
2841 Slog.v(TAG, "-------------------------------------");
2842 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2843 }
2844
Andrii Kulian8ee72852017-03-10 10:36:45 -08002845 mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mRotation,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002846 getConfiguration().uiMode);
2847 if (isDefaultDisplay) {
2848 // Not needed on non-default displays.
2849 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2850 mService.mScreenRect.set(0, 0, dw, dh);
2851 }
2852
2853 mService.mPolicy.getContentRectLw(mContentRect);
2854
2855 int seq = mService.mLayoutSeq + 1;
2856 if (seq < 0) seq = 0;
2857 mService.mLayoutSeq = seq;
2858
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002859 // Used to indicate that we have processed the dream window and all additional windows are
2860 // behind it.
2861 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002862 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002863
2864 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002865 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002866
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002867 // Used to indicate that we have processed the dream window and all additional attached
2868 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002869 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002870 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002871
2872 // Now perform layout of attached windows, which usually depend on the position of the
2873 // window they are attached to. XXX does not deal with windows that are attached to windows
2874 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002875 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002876
2877 // Window frames may have changed. Tell the input dispatcher about it.
2878 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2879 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2880 if (updateInputWindows) {
2881 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2882 }
2883
2884 mService.mPolicy.finishLayoutLw();
2885 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2886 }
2887
2888 /**
2889 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2890 * In portrait mode, it grabs the full screenshot.
2891 *
2892 * @param width the width of the target bitmap
2893 * @param height the height of the target bitmap
2894 * @param includeFullDisplay true if the screen should not be cropped before capture
2895 * @param frameScale the scale to apply to the frame, only used when width = -1 and height = -1
2896 * @param config of the output bitmap
2897 * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
Jorim Jaggi02886a82016-12-06 09:10:06 -08002898 * @param includeDecor whether to include window decors, like the status or navigation bar
2899 * background of the window
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002900 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002901 Bitmap screenshotApplications(IBinder appToken, int width, int height,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002902 boolean includeFullDisplay, float frameScale, Bitmap.Config config,
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01002903 boolean wallpaperOnly, boolean includeDecor) {
2904 Bitmap bitmap = screenshotApplications(appToken, width, height, includeFullDisplay,
2905 frameScale, wallpaperOnly, includeDecor, SurfaceControl::screenshot);
Jorim Jaggi9f9d61f2017-01-17 11:15:37 +01002906 if (bitmap == null) {
2907 return null;
2908 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01002909
2910 if (DEBUG_SCREENSHOT) {
2911 // TEST IF IT's ALL BLACK
2912 int[] buffer = new int[bitmap.getWidth() * bitmap.getHeight()];
2913 bitmap.getPixels(buffer, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(),
2914 bitmap.getHeight());
2915 boolean allBlack = true;
2916 final int firstColor = buffer[0];
2917 for (int i = 0; i < buffer.length; i++) {
2918 if (buffer[i] != firstColor) {
2919 allBlack = false;
2920 break;
2921 }
2922 }
2923 if (allBlack) {
2924 final WindowState appWin = mScreenshotApplicationState.appWin;
2925 final int maxLayer = mScreenshotApplicationState.maxLayer;
2926 final int minLayer = mScreenshotApplicationState.minLayer;
2927 Slog.i(TAG_WM, "Screenshot " + appWin + " was monochrome(" +
2928 Integer.toHexString(firstColor) + ")! mSurfaceLayer=" +
2929 (appWin != null ?
2930 appWin.mWinAnimator.mSurfaceController.getLayer() : "null") +
2931 " minLayer=" + minLayer + " maxLayer=" + maxLayer);
2932 }
2933 }
2934
2935 // Create a copy of the screenshot that is immutable and backed in ashmem.
2936 // This greatly reduces the overhead of passing the bitmap between processes.
2937 Bitmap ret = bitmap.createAshmemBitmap(config);
2938 bitmap.recycle();
2939 return ret;
2940 }
2941
2942 GraphicBuffer screenshotApplicationsToBuffer(IBinder appToken, int width, int height,
2943 boolean includeFullDisplay, float frameScale, boolean wallpaperOnly,
2944 boolean includeDecor) {
2945 return screenshotApplications(appToken, width, height, includeFullDisplay, frameScale,
2946 wallpaperOnly, includeDecor, SurfaceControl::screenshotToBuffer);
2947 }
2948
2949 private <E> E screenshotApplications(IBinder appToken, int width, int height,
2950 boolean includeFullDisplay, float frameScale, boolean wallpaperOnly,
2951 boolean includeDecor, Screenshoter<E> screenshoter) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002952 int dw = mDisplayInfo.logicalWidth;
2953 int dh = mDisplayInfo.logicalHeight;
2954 if (dw == 0 || dh == 0) {
2955 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
2956 + ": returning null. logical widthxheight=" + dw + "x" + dh);
2957 return null;
2958 }
2959
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01002960 E bitmap;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002961
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002962 mScreenshotApplicationState.reset(appToken == null && !wallpaperOnly);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002963 final Rect frame = new Rect();
2964 final Rect stackBounds = new Rect();
2965
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002966 final int aboveAppLayer = (mService.mPolicy.getWindowLayerFromTypeLw(TYPE_APPLICATION) + 1)
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002967 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Jorim Jaggi02886a82016-12-06 09:10:06 -08002968 final MutableBoolean mutableIncludeFullDisplay = new MutableBoolean(includeFullDisplay);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002969 synchronized(mService.mWindowMap) {
Jorim Jaggi51304d72017-05-17 17:25:32 +02002970 if (!mService.mPolicy.isScreenOn()) {
2971 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Attempted to take screenshot while display"
2972 + " was off.");
2973 return null;
2974 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002975 // Figure out the part of the screen that is actually the app.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002976 mScreenshotApplicationState.appWin = null;
2977 forAllWindows(w -> {
2978 if (!w.mHasSurface) {
2979 return false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002980 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002981 if (w.mLayer >= aboveAppLayer) {
2982 return false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002983 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002984 if (wallpaperOnly && !w.mIsWallpaper) {
2985 return false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002986 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002987 if (w.mIsImWindow) {
Jorim Jaggieb59d6e2017-05-04 13:54:22 +02002988 return false;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002989 } else if (w.mIsWallpaper) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002990 // If this is the wallpaper layer and we're only looking for the wallpaper layer
2991 // then the target window state is this one.
2992 if (wallpaperOnly) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002993 mScreenshotApplicationState.appWin = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002994 }
2995
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002996 if (mScreenshotApplicationState.appWin == null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002997 // We have not ran across the target window yet, so it is probably behind
2998 // the wallpaper. This can happen when the keyguard is up and all windows
2999 // are moved behind the wallpaper. We don't want to include the wallpaper
3000 // layer in the screenshot as it will cover-up the layer of the target
3001 // window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003002 return false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003003 }
3004 // Fall through. The target window is in front of the wallpaper. For this
3005 // case we want to include the wallpaper layer in the screenshot because
3006 // the target window might have some transparent areas.
3007 } else if (appToken != null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003008 if (w.mAppToken == null || w.mAppToken.token != appToken) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003009 // This app window is of no interest if it is not associated with the
3010 // screenshot app.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003011 return false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003012 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003013 mScreenshotApplicationState.appWin = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003014 }
3015
3016 // Include this window.
3017
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003018 final WindowStateAnimator winAnim = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003019 int layer = winAnim.mSurfaceController.getLayer();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003020 if (mScreenshotApplicationState.maxLayer < layer) {
3021 mScreenshotApplicationState.maxLayer = layer;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003022 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003023 if (mScreenshotApplicationState.minLayer > layer) {
3024 mScreenshotApplicationState.minLayer = layer;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003025 }
3026
3027 // Don't include wallpaper in bounds calculation
Jorim Jaggi70f59482017-05-04 14:05:59 +02003028 if (!w.mIsWallpaper && !mutableIncludeFullDisplay.value) {
3029 if (includeDecor) {
Jorim Jaggie6c6ecb2017-07-20 18:09:20 +02003030 final Task task = w.getTask();
3031 if (task != null) {
3032 task.getBounds(frame);
3033 } else {
Jorim Jaggi30d64f32017-04-07 16:33:17 +02003034
Jorim Jaggie6c6ecb2017-07-20 18:09:20 +02003035 // No task bounds? Too bad! Ain't no screenshot then.
3036 return true;
3037 }
Jorim Jaggi70f59482017-05-04 14:05:59 +02003038 } else {
3039 final Rect wf = w.mFrame;
3040 final Rect cr = w.mContentInsets;
3041 int left = wf.left + cr.left;
3042 int top = wf.top + cr.top;
3043 int right = wf.right - cr.right;
3044 int bottom = wf.bottom - cr.bottom;
3045 frame.union(left, top, right, bottom);
3046 w.getVisibleBounds(stackBounds);
3047 if (!Rect.intersects(frame, stackBounds)) {
3048 // Set frame empty if there's no intersection.
3049 frame.setEmpty();
3050 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003051 }
3052 }
3053
3054 final boolean foundTargetWs =
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003055 (w.mAppToken != null && w.mAppToken.token == appToken)
3056 || (mScreenshotApplicationState.appWin != null && wallpaperOnly);
Jorim Jaggi52e85da2017-01-24 16:21:39 +01003057 if (foundTargetWs && winAnim.getShown()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003058 mScreenshotApplicationState.screenshotReady = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003059 }
3060
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003061 if (w.isObscuringDisplay()){
3062 return true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003063 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003064 return false;
3065 }, true /* traverseTopToBottom */);
3066
3067 final WindowState appWin = mScreenshotApplicationState.appWin;
3068 final boolean screenshotReady = mScreenshotApplicationState.screenshotReady;
3069 final int maxLayer = mScreenshotApplicationState.maxLayer;
3070 final int minLayer = mScreenshotApplicationState.minLayer;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003071
3072 if (appToken != null && appWin == null) {
3073 // Can't find a window to snapshot.
3074 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM,
3075 "Screenshot: Couldn't find a surface matching " + appToken);
3076 return null;
3077 }
3078
3079 if (!screenshotReady) {
3080 Slog.i(TAG_WM, "Failed to capture screenshot of " + appToken +
3081 " appWin=" + (appWin == null ? "null" : (appWin + " drawState=" +
3082 appWin.mWinAnimator.mDrawState)));
3083 return null;
3084 }
3085
3086 // Screenshot is ready to be taken. Everything from here below will continue
3087 // through the bottom of the loop and return a value. We only stay in the loop
3088 // because we don't want to release the mWindowMap lock until the screenshot is
3089 // taken.
3090
3091 if (maxLayer == 0) {
3092 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
3093 + ": returning null maxLayer=" + maxLayer);
3094 return null;
3095 }
3096
Jorim Jaggi02886a82016-12-06 09:10:06 -08003097 if (!mutableIncludeFullDisplay.value) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003098 // Constrain frame to the screen size.
3099 if (!frame.intersect(0, 0, dw, dh)) {
3100 frame.setEmpty();
3101 }
3102 } else {
3103 // Caller just wants entire display.
3104 frame.set(0, 0, dw, dh);
3105 }
3106 if (frame.isEmpty()) {
3107 return null;
3108 }
3109
3110 if (width < 0) {
3111 width = (int) (frame.width() * frameScale);
3112 }
3113 if (height < 0) {
3114 height = (int) (frame.height() * frameScale);
3115 }
3116
3117 // Tell surface flinger what part of the image to crop. Take the top
3118 // right part of the application, and crop the larger dimension to fit.
3119 Rect crop = new Rect(frame);
3120 if (width / (float) frame.width() < height / (float) frame.height()) {
3121 int cropWidth = (int)((float)width / (float)height * frame.height());
3122 crop.right = crop.left + cropWidth;
3123 } else {
3124 int cropHeight = (int)((float)height / (float)width * frame.width());
3125 crop.bottom = crop.top + cropHeight;
3126 }
3127
3128 // The screenshot API does not apply the current screen rotation.
3129 int rot = mDisplay.getRotation();
3130
3131 if (rot == ROTATION_90 || rot == ROTATION_270) {
3132 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3133 }
3134
3135 // Surfaceflinger is not aware of orientation, so convert our logical
3136 // crop to surfaceflinger's portrait orientation.
3137 convertCropForSurfaceFlinger(crop, rot, dw, dh);
3138
3139 if (DEBUG_SCREENSHOT) {
3140 Slog.i(TAG_WM, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to "
3141 + maxLayer + " appToken=" + appToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003142 forAllWindows(w -> {
3143 final WindowSurfaceController controller = w.mWinAnimator.mSurfaceController;
3144 Slog.i(TAG_WM, w + ": " + w.mLayer
3145 + " animLayer=" + w.mWinAnimator.mAnimLayer
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003146 + " surfaceLayer=" + ((controller == null)
3147 ? "null" : controller.getLayer()));
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003148 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003149 }
3150
3151 final ScreenRotationAnimation screenRotationAnimation =
3152 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3153 final boolean inRotation = screenRotationAnimation != null &&
3154 screenRotationAnimation.isAnimating();
3155 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM,
3156 "Taking screenshot while rotating");
3157
3158 // We force pending transactions to flush before taking
3159 // the screenshot by pushing an empty synchronous transaction.
3160 SurfaceControl.openTransaction();
3161 SurfaceControl.closeTransactionSync();
3162
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003163 bitmap = screenshoter.screenshot(crop, width, height, minLayer, maxLayer,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003164 inRotation, rot);
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003165 if (bitmap == null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003166 Slog.w(TAG_WM, "Screenshot failure taking screenshot for (" + dw + "x" + dh
3167 + ") to layer " + maxLayer);
3168 return null;
3169 }
3170 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003171 return bitmap;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003172 }
3173
3174 // TODO: Can this use createRotationMatrix()?
3175 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3176 if (rot == Surface.ROTATION_90) {
3177 final int tmp = crop.top;
3178 crop.top = dw - crop.right;
3179 crop.right = crop.bottom;
3180 crop.bottom = dw - crop.left;
3181 crop.left = tmp;
3182 } else if (rot == Surface.ROTATION_180) {
3183 int tmp = crop.top;
3184 crop.top = dh - crop.bottom;
3185 crop.bottom = dh - tmp;
3186 tmp = crop.right;
3187 crop.right = dw - crop.left;
3188 crop.left = dw - tmp;
3189 } else if (rot == Surface.ROTATION_270) {
3190 final int tmp = crop.top;
3191 crop.top = crop.left;
3192 crop.left = dh - crop.bottom;
3193 crop.bottom = crop.right;
3194 crop.right = dh - tmp;
3195 }
3196 }
3197
3198 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003199 // Used to indicate the layout is needed.
3200 mTmpWindow = null;
3201
3202 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003203 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003204 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003205 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003206 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003207 w.setDisplayLayoutNeeded();
3208 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003209 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003210
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003211 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003212 mService.mWindowPlacerLocked.performSurfacePlacement();
3213 }
3214 }
3215
Wale Ogunwale1666e312016-12-16 11:27:18 -08003216 void setExitingTokensHasVisible(boolean hasVisible) {
3217 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3218 mExitingTokens.get(i).hasVisible = hasVisible;
3219 }
3220
3221 // Initialize state of exiting applications.
3222 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3223 }
3224
3225 void removeExistingTokensIfPossible() {
3226 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3227 final WindowToken token = mExitingTokens.get(i);
3228 if (!token.hasVisible) {
3229 mExitingTokens.remove(i);
3230 }
3231 }
3232
3233 // Time to remove any exiting applications?
3234 mTaskStackContainers.removeExistingAppTokensIfPossible();
3235 }
3236
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003237 @Override
3238 void onDescendantOverrideConfigurationChanged() {
3239 setLayoutNeeded();
3240 mService.requestTraversal();
3241 }
3242
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003243 static final class TaskForResizePointSearchResult {
3244 boolean searchDone;
3245 Task taskForResize;
3246
3247 void reset() {
3248 searchDone = false;
3249 taskForResize = null;
3250 }
3251 }
Robert Carr3b716242016-08-16 16:02:21 -07003252
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003253 private static final class ApplySurfaceChangesTransactionState {
3254 boolean displayHasContent;
3255 boolean obscured;
3256 boolean syswin;
3257 boolean focusDisplayed;
3258 float preferredRefreshRate;
3259 int preferredModeId;
3260
3261 void reset() {
3262 displayHasContent = false;
3263 obscured = false;
3264 syswin = false;
3265 focusDisplayed = false;
3266 preferredRefreshRate = 0;
3267 preferredModeId = 0;
3268 }
3269 }
3270
3271 private static final class ScreenshotApplicationState {
3272 WindowState appWin;
3273 int maxLayer;
3274 int minLayer;
3275 boolean screenshotReady;
3276
3277 void reset(boolean screenshotReady) {
3278 appWin = null;
3279 maxLayer = 0;
3280 minLayer = 0;
3281 this.screenshotReady = screenshotReady;
3282 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3283 }
3284 }
3285
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003286 /**
3287 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3288 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3289 * homogeneous children type which is currently required by sub-classes of
3290 * {@link WindowContainer} class.
3291 */
3292 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3293
3294 int size() {
3295 return mChildren.size();
3296 }
3297
3298 E get(int index) {
3299 return mChildren.get(index);
3300 }
3301
3302 @Override
3303 boolean fillsParent() {
3304 return true;
3305 }
3306
3307 @Override
3308 boolean isVisible() {
3309 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003310 }
3311 }
3312
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003313 /**
3314 * Window container class that contains all containers on this display relating to Apps.
3315 * I.e Activities.
3316 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003317 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003318
Andrii Kulian839def92016-11-02 10:58:58 -07003319 /**
3320 * Adds the stack to this container.
3321 * @see WindowManagerService#addStackToDisplay(int, int, boolean)
3322 */
3323 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003324 if (stack.mStackId == HOME_STACK_ID) {
3325 if (mHomeStack != null) {
3326 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
3327 }
3328 mHomeStack = stack;
3329 }
3330 addChild(stack, onTop);
3331 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003332 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003333
Andrii Kulian839def92016-11-02 10:58:58 -07003334 /** Removes the stack from its container and prepare for changing the parent. */
3335 void removeStackFromDisplay(TaskStack stack) {
3336 removeChild(stack);
3337 stack.onRemovedFromDisplay();
Andrii Kulian839def92016-11-02 10:58:58 -07003338 }
3339
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003340 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003341 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3342 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003343 addChild(stack, addIndex);
3344 setLayoutNeeded();
3345 }
3346
Bryce Lee00d586d2017-07-28 20:48:43 -07003347
3348 @Override
3349 boolean isOnTop() {
3350 // Considered always on top
3351 return true;
3352 }
3353
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003354 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003355 void positionChildAt(int position, TaskStack child, boolean includingParents) {
3356 if (StackId.isAlwaysOnTop(child.mStackId) && position != POSITION_TOP) {
3357 // This stack is always-on-top, override the default behavior.
3358 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3359
3360 // Moving to its current position, as we must call super but we don't want to
3361 // perform any meaningful action.
3362 final int currentPosition = mChildren.indexOf(child);
3363 super.positionChildAt(currentPosition, child, false /* includingParents */);
3364 return;
3365 }
3366
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003367 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3368 super.positionChildAt(targetPosition, child, includingParents);
3369
3370 setLayoutNeeded();
3371 }
3372
3373 /**
3374 * When stack is added or repositioned, find a proper position for it.
3375 * This will make sure that pinned stack always stays on top.
3376 * @param requestedPosition Position requested by caller.
3377 * @param stack Stack to be added or positioned.
3378 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3379 * @return The proper position for the stack.
3380 */
3381 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3382 final int topChildPosition = mChildren.size() - 1;
3383 boolean toTop = requestedPosition == POSITION_TOP;
3384 toTop |= adding ? requestedPosition >= topChildPosition + 1
3385 : requestedPosition >= topChildPosition;
3386 int targetPosition = requestedPosition;
3387
Bryce Lee48f4b572017-04-10 10:54:15 -07003388 if (toTop && stack.mStackId != PINNED_STACK_ID
3389 && getStackById(PINNED_STACK_ID) != null) {
3390 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003391 TaskStack topStack = mChildren.get(topChildPosition);
3392 if (topStack.mStackId != PINNED_STACK_ID) {
3393 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3394 }
3395
3396 // So, stack is moved just below the pinned stack.
3397 // When we're adding a new stack the target is the current pinned stack position.
3398 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003399 // stack, because WindowContainer#positionAt() first removes element and then adds
3400 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003401 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3402 }
3403
3404 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003405 }
3406
3407 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003408 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3409 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003410 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003411 if (super.forAllWindows(callback, traverseTopToBottom)) {
3412 return true;
3413 }
3414 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3415 return true;
3416 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003417 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003418 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3419 return true;
3420 }
3421 if (super.forAllWindows(callback, traverseTopToBottom)) {
3422 return true;
3423 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003424 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003425 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003426 }
3427
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003428 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003429 boolean traverseTopToBottom) {
3430 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3431 // app tokens.
3432 // TODO: Investigate if we need to continue to do this or if we can just process them
3433 // in-order.
3434 if (traverseTopToBottom) {
3435 for (int i = mChildren.size() - 1; i >= 0; --i) {
3436 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3437 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003438 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3439 traverseTopToBottom)) {
3440 return true;
3441 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003442 }
3443 }
3444 } else {
3445 final int count = mChildren.size();
3446 for (int i = 0; i < count; ++i) {
3447 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3448 final int appTokensCount = appTokens.size();
3449 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003450 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3451 traverseTopToBottom)) {
3452 return true;
3453 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003454 }
3455 }
3456 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003457 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003458 }
3459
Wale Ogunwale1666e312016-12-16 11:27:18 -08003460 void setExitingTokensHasVisible(boolean hasVisible) {
3461 for (int i = mChildren.size() - 1; i >= 0; --i) {
3462 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3463 for (int j = appTokens.size() - 1; j >= 0; --j) {
3464 appTokens.get(j).hasVisible = hasVisible;
3465 }
3466 }
3467 }
3468
3469 void removeExistingAppTokensIfPossible() {
3470 for (int i = mChildren.size() - 1; i >= 0; --i) {
3471 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3472 for (int j = appTokens.size() - 1; j >= 0; --j) {
3473 final AppWindowToken token = appTokens.get(j);
3474 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3475 && (!token.mIsExiting || token.isEmpty())) {
3476 // Make sure there is no animation running on this token, so any windows
3477 // associated with it will be removed as soon as their animations are
3478 // complete.
3479 token.mAppAnimator.clearAnimation();
3480 token.mAppAnimator.animating = false;
3481 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3482 "performLayout: App token exiting now removed" + token);
3483 token.removeIfPossible();
3484 }
3485 }
3486 }
3487 }
3488
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003489 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003490 int getOrientation() {
Wale Ogunwale1666e312016-12-16 11:27:18 -08003491 if (isStackVisible(DOCKED_STACK_ID) || isStackVisible(FREEFORM_WORKSPACE_STACK_ID)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003492 // Apps and their containers are not allowed to specify an orientation while the
3493 // docked or freeform stack is visible...except for the home stack/task if the
3494 // docked stack is minimized and it actually set something.
3495 if (mHomeStack != null && mHomeStack.isVisible()
3496 && mDividerControllerLocked.isMinimizedDock()) {
3497 final int orientation = mHomeStack.getOrientation();
3498 if (orientation != SCREEN_ORIENTATION_UNSET) {
3499 return orientation;
3500 }
3501 }
3502 return SCREEN_ORIENTATION_UNSPECIFIED;
3503 }
3504
3505 final int orientation = super.getOrientation();
3506 if (orientation != SCREEN_ORIENTATION_UNSET
3507 && orientation != SCREEN_ORIENTATION_BEHIND) {
3508 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3509 "App is requesting an orientation, return " + orientation);
3510 return orientation;
3511 }
3512
3513 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08003514 "No app is requesting an orientation, return " + mLastOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003515 // The next app has not been requested to be visible, so we keep the current orientation
3516 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003517 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003518 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003519 }
3520
3521 /**
3522 * Window container class that contains all containers on this display that are not related to
3523 * Apps. E.g. status bar.
3524 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003525 private final class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
3526 /**
3527 * Compares two child window tokens returns -1 if the first is lesser than the second in
3528 * terms of z-order and 1 otherwise.
3529 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003530 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003531 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003532 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3533 token1.mOwnerCanManageAppTokens)
3534 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3535 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003536
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003537 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3538 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3539 return false;
3540 }
3541 final int req = w.mAttrs.screenOrientation;
3542 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3543 || req == SCREEN_ORIENTATION_UNSET) {
3544 return false;
3545 }
3546 return true;
3547 };
3548
Wale Ogunwale3a931692016-11-02 16:49:48 -07003549 private final String mName;
3550 NonAppWindowContainers(String name) {
3551 mName = name;
3552 }
3553
3554 void addChild(WindowToken token) {
3555 addChild(token, mWindowComparator);
3556 }
3557
3558 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003559 int getOrientation() {
3560 final WindowManagerPolicy policy = mService.mPolicy;
3561 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003562 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003563
3564 if (win != null) {
3565 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003566 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003567 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003568 if (mService.mKeyguardGoingAway) {
3569 // Keyguard can't affect the orientation if it is going away...
3570 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3571 return SCREEN_ORIENTATION_UNSET;
3572 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003573 }
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003574 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003575 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003576 }
3577
Andrii Kulian8ee72852017-03-10 10:36:45 -08003578 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003579
3580 if (policy.isKeyguardShowingAndNotOccluded()) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003581 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003582 }
3583
3584 return SCREEN_ORIENTATION_UNSET;
3585 }
3586
3587 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003588 String getName() {
3589 return mName;
3590 }
Robert Carr3b716242016-08-16 16:02:21 -07003591 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003592
3593 /**
3594 * Interface to screenshot into various types, i.e. {@link Bitmap} and {@link GraphicBuffer}.
3595 */
3596 @FunctionalInterface
3597 private interface Screenshoter<E> {
3598 E screenshot(Rect sourceCrop, int width, int height, int minLayer, int maxLayer,
3599 boolean useIdentityTransform, int rotation);
3600 }
Craig Mautner59c00972012-07-30 12:10:24 -07003601}