blob: 592eaec7f31d2a553bfaabc833dc2e5ba17bb565 [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 Ogunwale494009b82016-10-21 09:01:38 -070060import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070061import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070062import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
63import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070064import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwalec69694a2016-10-18 13:51:15 -070065import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070066import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070067import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070069import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070070import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070071import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070072import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070073import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070074import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070075import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070076import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080077import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070078import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
79import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -070080import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070081import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
82import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
83import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
84import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale494009b82016-10-21 09:01:38 -070085import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070086import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070087import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070088import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -070089import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070090import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070091import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070092
Andrii Kulian3a507b52016-09-19 18:14:12 -070093import android.annotation.NonNull;
Wale Ogunwale3797c222015-10-27 14:21:58 -070094import android.app.ActivityManager.StackId;
Andrii Kulian441e4492016-09-29 15:25:00 -070095import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070096import android.graphics.Bitmap;
Jorim Jaggi6a7a8592017-01-12 00:44:33 +010097import android.graphics.GraphicBuffer;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070098import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -080099import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700100import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700101import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100102import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700103import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700104import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700105import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700106import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700107import android.os.RemoteException;
108import android.os.SystemClock;
Chong Zhang8e89b312015-09-09 15:09:30 -0700109import android.util.DisplayMetrics;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800110import android.util.MutableBoolean;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700111import android.util.Slog;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700112import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -0700113import android.view.DisplayInfo;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700114import android.view.Surface;
115import android.view.SurfaceControl;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700116import android.view.WindowManagerPolicy;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700117
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800118import com.android.internal.util.ToBooleanFunction;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700119import com.android.internal.view.IInputMethodClient;
Craig Mautner59c00972012-07-30 12:10:24 -0700120
Robert Carr3b716242016-08-16 16:02:21 -0700121import java.io.FileDescriptor;
Craig Mautner59c00972012-07-30 12:10:24 -0700122import java.io.PrintWriter;
123import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700124import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700125import java.util.HashMap;
126import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700127import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700128import java.util.List;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800129import java.util.function.Consumer;
130import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700131
Craig Mautner59c00972012-07-30 12:10:24 -0700132/**
133 * Utility class for keeping track of the WindowStates and other pertinent contents of a
134 * particular Display.
135 *
136 * IMPORTANT: No method from this class should ever be used without holding
137 * WindowManagerService.mWindowMap.
138 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700139class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700140 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700141
142 /** Unique identifier of this stack. */
143 private final int mDisplayId;
144
Wale Ogunwale3a931692016-11-02 16:49:48 -0700145 /** The containers below are the only child containers the display can have. */
146 // Contains all window containers that are related to apps (Activities)
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700147 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers();
Wale Ogunwale3a931692016-11-02 16:49:48 -0700148 // Contains all non-app window containers that should be displayed above the app containers
149 // (e.g. Status bar)
150 private final NonAppWindowContainers mAboveAppWindowsContainers =
151 new NonAppWindowContainers("mAboveAppWindowsContainers");
152 // Contains all non-app window containers that should be displayed below the app containers
153 // (e.g. Wallpaper).
154 private final NonAppWindowContainers mBelowAppWindowsContainers =
155 new NonAppWindowContainers("mBelowAppWindowsContainers");
156 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
157 // on the IME target. We mainly have this container grouping so we can keep track of all the IME
158 // window containers together and move them in-sync if/when needed.
159 private final NonAppWindowContainers mImeWindowsContainers =
160 new NonAppWindowContainers("mImeWindowsContainers");
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700161
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000162 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800163 private WindowState mTmpWindow2;
164 private WindowAnimator mTmpWindowAnimator;
165 private boolean mTmpRecoveringMemory;
166 private boolean mUpdateImeTarget;
167 private boolean mTmpInitial;
Craig Mautner59c00972012-07-30 12:10:24 -0700168
Wale Ogunwale02319a62016-09-26 15:21:22 -0700169 // Mapping from a token IBinder to a WindowToken object on this display.
170 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
171
Craig Mautner59c00972012-07-30 12:10:24 -0700172 int mInitialDisplayWidth = 0;
173 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700174 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -0700175 int mBaseDisplayWidth = 0;
176 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700177 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700178 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700179 private final DisplayInfo mDisplayInfo = new DisplayInfo();
180 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700181 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -0700182
Craig Mautner6601b7b2013-04-29 10:29:11 -0700183 Rect mBaseDisplayRect = new Rect();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700184 private Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700185
Craig Mautner39834192012-09-02 07:47:24 -0700186 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700187 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700188 int pendingLayoutChanges;
Andrii Kulian839def92016-11-02 10:58:58 -0700189 // TODO(multi-display): remove some of the usages.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800190 boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700191
Craig Mautnerdc548482014-02-05 13:35:24 -0800192 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700193 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800194
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800195 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
196 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -0700197 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700198
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700199 /** Detect user tapping outside of current focused task bounds .*/
200 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700201
Craig Mautner6601b7b2013-04-29 10:29:11 -0700202 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700203 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700204
Craig Mautner6601b7b2013-04-29 10:29:11 -0700205 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800206 private final Rect mTmpRect = new Rect();
207 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700208 private final RectF mTmpRectF = new RectF();
209 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800210 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700211
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800212 WindowManagerService mService;
Craig Mautner9d808b12013-08-06 18:00:25 -0700213
Craig Mautner95da1082014-02-24 17:54:35 -0800214 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700215 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800216
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700217 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700218 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700219
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800220 DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700221
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800222 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
223
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000224 private boolean mHaveBootMsg = false;
225 private boolean mHaveApp = false;
226 private boolean mHaveWallpaper = false;
227 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700228
229 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
230
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700231 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
232 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000233 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
234 new ApplySurfaceChangesTransactionState();
235 private final ScreenshotApplicationState mScreenshotApplicationState =
236 new ScreenshotApplicationState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700237
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700238 // True if this display is in the process of being removed. Used to determine if the removal of
239 // the display's direct children should be allowed.
240 private boolean mRemovingDisplay = false;
241
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700242 private final WindowLayersController mLayersController;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800243 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700244 int mInputMethodAnimLayerAdjustment;
245
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800246 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
247 WindowStateAnimator winAnimator = w.mWinAnimator;
248 if (winAnimator.hasSurface()) {
249 final boolean wasAnimating = winAnimator.mWasAnimating;
250 final boolean nowAnimating = winAnimator.stepAnimationLocked(
251 mTmpWindowAnimator.mCurrentTime);
252 winAnimator.mWasAnimating = nowAnimating;
253 mTmpWindowAnimator.orAnimating(nowAnimating);
254
255 if (DEBUG_WALLPAPER) Slog.v(TAG,
256 w + ": wasAnimating=" + wasAnimating + ", nowAnimating=" + nowAnimating);
257
258 if (wasAnimating && !winAnimator.mAnimating
259 && mWallpaperController.isWallpaperTarget(w)) {
260 mTmpWindowAnimator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
261 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
262 if (DEBUG_LAYOUT_REPEATS) {
263 mService.mWindowPlacerLocked.debugLayoutRepeats(
264 "updateWindowsAndWallpaperLocked 2", pendingLayoutChanges);
265 }
266 }
267 }
268
269 final AppWindowToken atoken = w.mAppToken;
270 if (winAnimator.mDrawState == READY_TO_SHOW) {
271 if (atoken == null || atoken.allDrawn) {
272 if (w.performShowLocked()) {
273 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
274 if (DEBUG_LAYOUT_REPEATS) {
275 mService.mWindowPlacerLocked.debugLayoutRepeats(
276 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
277 }
278 }
279 }
280 }
281 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
282 if (appAnimator != null && appAnimator.thumbnail != null) {
283 if (appAnimator.thumbnailTransactionSeq
284 != mTmpWindowAnimator.mAnimTransactionSequence) {
285 appAnimator.thumbnailTransactionSeq =
286 mTmpWindowAnimator.mAnimTransactionSequence;
287 appAnimator.thumbnailLayer = 0;
288 }
289 if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
290 appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
291 }
292 }
293 };
294
295 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
296 final WindowStateAnimator winAnimator = w.mWinAnimator;
297 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
298 return;
299 }
300
301 final int flags = w.mAttrs.flags;
302
303 // If this window is animating, make a note that we have an animating window and take
304 // care of a request to run a detached wallpaper animation.
305 if (winAnimator.mAnimating) {
306 if (winAnimator.mAnimation != null) {
307 if ((flags & FLAG_SHOW_WALLPAPER) != 0
308 && winAnimator.mAnimation.getDetachWallpaper()) {
309 mTmpWindow = w;
310 }
311 final int color = winAnimator.mAnimation.getBackgroundColor();
312 if (color != 0) {
313 final TaskStack stack = w.getStack();
314 if (stack != null) {
315 stack.setAnimationBackground(winAnimator, color);
316 }
317 }
318 }
319 mTmpWindowAnimator.setAnimating(true);
320 }
321
322 // If this window's app token is running a detached wallpaper animation, make a note so
323 // we can ensure the wallpaper is displayed behind it.
324 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
325 if (appAnimator != null && appAnimator.animation != null
326 && appAnimator.animating) {
327 if ((flags & FLAG_SHOW_WALLPAPER) != 0
328 && appAnimator.animation.getDetachWallpaper()) {
329 mTmpWindow = w;
330 }
331
332 final int color = appAnimator.animation.getBackgroundColor();
333 if (color != 0) {
334 final TaskStack stack = w.getStack();
335 if (stack != null) {
336 stack.setAnimationBackground(winAnimator, color);
337 }
338 }
339 }
340 };
341
342 private final Consumer<WindowState> mSetInputMethodAnimLayerAdjustment =
343 w -> w.adjustAnimLayer(mInputMethodAnimLayerAdjustment);
344
345 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
346 final int lostFocusUid = mTmpWindow.mOwnerUid;
347 final Handler handler = mService.mH;
348 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
349 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
350 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
351 w.mAttrs.hideTimeoutMilliseconds);
352 }
353 }
354 };
355
356 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
357 final AppWindowToken focusedApp = mService.mFocusedApp;
358 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
359 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
360
361 if (!w.canReceiveKeys()) {
362 return false;
363 }
364
365 final AppWindowToken wtoken = w.mAppToken;
366
367 // If this window's application has been removed, just skip it.
368 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
369 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
370 + (wtoken.removed ? "removed" : "sendingToBottom"));
371 return false;
372 }
373
374 if (focusedApp == null) {
375 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
376 + " using new focus @ " + w);
377 mTmpWindow = w;
378 return true;
379 }
380
381 if (!focusedApp.windowsAreFocusable()) {
382 // Current focused app windows aren't focusable...
383 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
384 + " focusable using new focus @ " + w);
385 mTmpWindow = w;
386 return true;
387 }
388
389 // Descend through all of the app tokens and find the first that either matches
390 // win.mAppToken (return win) or mFocusedApp (return null).
391 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
392 if (focusedApp.compareTo(wtoken) > 0) {
393 // App stack below focused app stack. No focus for you!!!
394 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
395 "findFocusedWindow: Reached focused app=" + focusedApp);
396 mTmpWindow = null;
397 return true;
398 }
399 }
400
401 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
402 mTmpWindow = w;
403 return true;
404 };
405
406 private final Consumer<WindowState> mPrepareWindowSurfaces =
407 w -> w.mWinAnimator.prepareSurfaceLocked(true);
408
409 private final Consumer<WindowState> mPerformLayout = w -> {
410 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
411 // wasting time and funky changes while a window is animating away.
412 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
413 || w.isGoneForLayoutLw();
414
415 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
416 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
417 + " mLayoutAttached=" + w.mLayoutAttached
418 + " screen changed=" + w.isConfigChanged());
419 final AppWindowToken atoken = w.mAppToken;
420 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
421 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.hidden
422 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
423 + " parentHidden=" + w.isParentWindowHidden());
424 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
425 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.hidden
426 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
427 + " parentHidden=" + w.isParentWindowHidden());
428 }
429
430 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
431 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
432 // since that means "perform layout as normal, just don't display").
433 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
434 || ((w.isConfigChanged() || w.setReportResizeHints())
435 && !w.isGoneForLayoutLw() &&
436 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
437 (w.mHasSurface && w.mAppToken != null &&
438 w.mAppToken.layoutConfigChanges)))) {
439 if (!w.mLayoutAttached) {
440 if (mTmpInitial) {
441 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
442 w.mContentChanged = false;
443 }
444 if (w.mAttrs.type == TYPE_DREAM) {
445 // Don't layout windows behind a dream, so that if it does stuff like hide
446 // the status bar we won't get a bad transition when it goes away.
447 mTmpWindow = w;
448 }
449 w.mLayoutNeeded = false;
450 w.prelayout();
451 mService.mPolicy.layoutWindowLw(w, null);
452 w.mLayoutSeq = mService.mLayoutSeq;
453
454 // Window frames may have changed. Update dim layer with the new bounds.
455 final Task task = w.getTask();
456 if (task != null) {
457 mDimLayerController.updateDimLayer(task);
458 }
459
460 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
461 + " mContainingFrame=" + w.mContainingFrame
462 + " mDisplayFrame=" + w.mDisplayFrame);
463 }
464 }
465 };
466
467 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
468 if (w.mLayoutAttached) {
469 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
470 + " mViewVisibility=" + w.mViewVisibility
471 + " mRelayoutCalled=" + w.mRelayoutCalled);
472 // If this view is GONE, then skip it -- keep the current frame, and let the caller
473 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
474 // windows, since that means "perform layout as normal, just don't display").
475 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
476 return;
477 }
478 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
479 || w.mLayoutNeeded) {
480 if (mTmpInitial) {
481 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
482 w.mContentChanged = false;
483 }
484 w.mLayoutNeeded = false;
485 w.prelayout();
486 mService.mPolicy.layoutWindowLw(w, w.getParentWindow());
487 w.mLayoutSeq = mService.mLayoutSeq;
488 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
489 + " mContainingFrame=" + w.mContainingFrame
490 + " mDisplayFrame=" + w.mDisplayFrame);
491 }
492 } else if (w.mAttrs.type == TYPE_DREAM) {
493 // Don't layout windows behind a dream, so that if it does stuff like hide the
494 // status bar we won't get a bad transition when it goes away.
495 mTmpWindow = mTmpWindow2;
496 }
497 };
498
499 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
500 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
501 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
502 return w.canBeImeTarget();
503 };
504
505 private final Consumer<WindowState> mApplyPostLayoutPolicy =
506 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
507 mService.mInputMethodTarget);
508
509 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
510 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
511 final boolean obscuredChanged = w.mObscured !=
512 mTmpApplySurfaceChangesTransactionState.obscured;
513 final RootWindowContainer root = mService.mRoot;
514 // Only used if default window
515 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
516
517 // Update effect.
518 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
519 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
520 final boolean isDisplayed = w.isDisplayedLw();
521
522 if (isDisplayed && w.isObscuringDisplay()) {
523 // This window completely covers everything behind it, so we want to leave all
524 // of them as undimmed (for performance reasons).
525 root.mObscuringWindow = w;
526 mTmpApplySurfaceChangesTransactionState.obscured = true;
527 }
528
529 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
530 root.handleNotObscuredLocked(w,
531 mTmpApplySurfaceChangesTransactionState.obscured,
532 mTmpApplySurfaceChangesTransactionState.syswin);
533
534 if (w.mHasSurface && isDisplayed) {
535 final int type = w.mAttrs.type;
536 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
537 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
538 mTmpApplySurfaceChangesTransactionState.syswin = true;
539 }
540 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
541 && w.mAttrs.preferredRefreshRate != 0) {
542 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
543 = w.mAttrs.preferredRefreshRate;
544 }
545 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
546 && w.mAttrs.preferredDisplayModeId != 0) {
547 mTmpApplySurfaceChangesTransactionState.preferredModeId
548 = w.mAttrs.preferredDisplayModeId;
549 }
550 }
551 }
552
553 w.applyDimLayerIfNeeded();
554
555 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
556 && mWallpaperController.isWallpaperTarget(w)) {
557 // This is the wallpaper target and its obscured state changed... make sure the
558 // current wallpaper's visibility has been updated accordingly.
559 mWallpaperController.updateWallpaperVisibility();
560 }
561
562 w.handleWindowMovedIfNeeded();
563
564 final WindowStateAnimator winAnimator = w.mWinAnimator;
565
566 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
567 w.mContentChanged = false;
568
569 // Moved from updateWindowsAndWallpaperLocked().
570 if (w.mHasSurface) {
571 // Take care of the window being ready to display.
572 final boolean committed = winAnimator.commitFinishDrawingLocked();
573 if (isDefaultDisplay && committed) {
574 if (w.mAttrs.type == TYPE_DREAM) {
575 // HACK: When a dream is shown, it may at that point hide the lock screen.
576 // So we need to redo the layout to let the phone window manager make this
577 // happen.
578 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
579 if (DEBUG_LAYOUT_REPEATS) {
580 surfacePlacer.debugLayoutRepeats(
581 "dream and commitFinishDrawingLocked true",
582 pendingLayoutChanges);
583 }
584 }
585 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
586 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
587 "First draw done in potential wallpaper target " + w);
588 root.mWallpaperMayChange = true;
589 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
590 if (DEBUG_LAYOUT_REPEATS) {
591 surfacePlacer.debugLayoutRepeats(
592 "wallpaper and commitFinishDrawingLocked true",
593 pendingLayoutChanges);
594 }
595 }
596 }
597 if (!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening()) {
598 // Updates the shown frame before we set up the surface. This is needed
599 // because the resizing could change the top-left position (in addition to
600 // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to
601 // position the surface.
602 //
603 // If an animation is being started, we can't call this method because the
604 // animation hasn't processed its initial transformation yet, but in general
605 // we do want to update the position if the window is animating.
606 winAnimator.computeShownFrameLocked();
607 }
608 winAnimator.setSurfaceBoundariesLocked(mTmpRecoveringMemory /* recoveringMemory */);
609 }
610
611 final AppWindowToken atoken = w.mAppToken;
612 if (atoken != null) {
613 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
614 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
615 mTmpUpdateAllDrawn.add(atoken);
616 }
617 }
618
619 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
620 && w.isDisplayedLw()) {
621 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
622 }
623
624 w.updateResizingWindowIfNeeded();
625 };
626
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800627 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700628 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800629 * @param service You know.
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700630 * @param layersController window layer controller used to assign layer to the windows on this
631 * display.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700632 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
633 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700634 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700635 DisplayContent(Display display, WindowManagerService service,
Wale Ogunwale0303c572016-10-20 10:16:29 -0700636 WindowLayersController layersController, WallpaperController wallpaperController) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700637 mDisplay = display;
638 mDisplayId = display.getDisplayId();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700639 mLayersController = layersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700640 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700641 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700642 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700643 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700644 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700645 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800646 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700647 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800648 mDimLayerController = new DimLayerController(this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700649
650 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700651 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700652 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700653 super.addChild(mAboveAppWindowsContainers, null);
654 super.addChild(mImeWindowsContainers, null);
Craig Mautner59c00972012-07-30 12:10:24 -0700655 }
656
657 int getDisplayId() {
658 return mDisplayId;
659 }
660
Wale Ogunwale02319a62016-09-26 15:21:22 -0700661 WindowToken getWindowToken(IBinder binder) {
662 return mTokenMap.get(binder);
663 }
664
665 AppWindowToken getAppWindowToken(IBinder binder) {
666 final WindowToken token = getWindowToken(binder);
667 if (token == null) {
668 return null;
669 }
670 return token.asAppWindowToken();
671 }
672
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800673 void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700674 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
675 if (dc != null) {
676 // We currently don't support adding a window token to the display if the display
677 // already has the binder mapped to another token. If there is a use case for supporting
678 // this moving forward we will either need to merge the WindowTokens some how or have
679 // the binder map to a list of window tokens.
680 throw new IllegalArgumentException("Can't map token=" + token + " to display=" + this
681 + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
682 }
683 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700684
685 if (token.asAppWindowToken() == null) {
686 // Add non-app token to container hierarchy on the display. App tokens are added through
687 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700688 switch (token.windowType) {
689 case TYPE_WALLPAPER:
690 mBelowAppWindowsContainers.addChild(token);
691 break;
692 case TYPE_INPUT_METHOD:
693 case TYPE_INPUT_METHOD_DIALOG:
694 mImeWindowsContainers.addChild(token);
695 break;
696 default:
697 mAboveAppWindowsContainers.addChild(token);
698 break;
699 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700700 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700701 }
702
703 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700704 final WindowToken token = mTokenMap.remove(binder);
705 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800706 token.setExiting();
707 }
708 return token;
709 }
710
711 /** Changes the display the input window token is housed on to this one. */
712 void reParentWindowToken(WindowToken token) {
713 final DisplayContent prevDc = token.getDisplayContent();
714 if (prevDc == this) {
715 return;
716 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800717 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
718 && token.asAppWindowToken() == null) {
719 // Removed the token from the map, but made sure it's not an app token before removing
720 // from parent.
721 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700722 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800723
724 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700725 }
726
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700727 void removeAppToken(IBinder binder) {
728 final WindowToken token = removeWindowToken(binder);
729 if (token == null) {
730 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
731 return;
732 }
733
734 final AppWindowToken appToken = token.asAppWindowToken();
735
736 if (appToken == null) {
737 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
738 return;
739 }
740
741 appToken.onRemovedFromDisplay();
742 }
743
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700744 Display getDisplay() {
745 return mDisplay;
746 }
747
Craig Mautner59c00972012-07-30 12:10:24 -0700748 DisplayInfo getDisplayInfo() {
749 return mDisplayInfo;
750 }
751
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700752 DisplayMetrics getDisplayMetrics() {
753 return mDisplayMetrics;
754 }
755
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100756 DockedStackDividerController getDockedDividerController() {
757 return mDividerControllerLocked;
758 }
759
Winson Chung655332c2016-10-31 13:14:28 -0700760 PinnedStackController getPinnedStackController() {
761 return mPinnedStackControllerLocked;
762 }
763
Jeff Browna506a6e2013-06-04 00:02:38 -0700764 /**
765 * Returns true if the specified UID has access to this display.
766 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700767 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700768 return mDisplay.hasAccess(uid);
769 }
770
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700771 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700772 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -0700773 }
774
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700775 TaskStack getHomeStack() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700776 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800777 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
Craig Mautnere0a38842013-12-16 16:14:02 -0800778 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700779 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700780 }
781
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700782 TaskStack getStackById(int stackId) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700783 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
784 final TaskStack stack = mTaskStackContainers.get(i);
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700785 if (stack.mStackId == stackId) {
786 return stack;
787 }
788 }
789 return null;
790 }
791
Andrii Kulian441e4492016-09-29 15:25:00 -0700792 @Override
793 void onConfigurationChanged(Configuration newParentConfig) {
794 super.onConfigurationChanged(newParentConfig);
795
Andrii Kulian3a507b52016-09-19 18:14:12 -0700796 // The display size information is heavily dependent on the resources in the current
797 // configuration, so we need to reconfigure it every time the configuration changes.
798 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
799 mService.reconfigureDisplayLocked(this);
800
801 getDockedDividerController().onConfigurationChanged();
Winson Chung655332c2016-10-31 13:14:28 -0700802 getPinnedStackController().onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700803 }
Andrii Kulian3a507b52016-09-19 18:14:12 -0700804
Andrii Kulian441e4492016-09-29 15:25:00 -0700805 /**
806 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
807 * bounds were updated.
808 */
809 void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700810 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
811 final TaskStack stack = mTaskStackContainers.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700812 if (stack.updateBoundsAfterConfigChange()) {
Andrii Kulian3a507b52016-09-19 18:14:12 -0700813 changedStackList.add(stack.mStackId);
814 }
815 }
816 }
817
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700818 @Override
819 boolean fillsParent() {
820 return true;
821 }
822
823 @Override
824 boolean isVisible() {
825 return true;
826 }
827
828 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700829 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700830 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000831 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700832 }
833
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700834 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800835 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
836 // Special handling so we can process IME windows with #forAllImeWindows above their IME
837 // target, or here in order if there isn't an IME target.
838 if (traverseTopToBottom) {
839 for (int i = mChildren.size() - 1; i >= 0; --i) {
840 final DisplayChildWindowContainer child = mChildren.get(i);
841 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
842 // In this case the Ime windows will be processed above their target so we skip
843 // here.
844 continue;
845 }
846 if (child.forAllWindows(callback, traverseTopToBottom)) {
847 return true;
848 }
849 }
850 } else {
851 final int count = mChildren.size();
852 for (int i = 0; i < count; i++) {
853 final DisplayChildWindowContainer child = mChildren.get(i);
854 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
855 // In this case the Ime windows will be processed above their target so we skip
856 // here.
857 continue;
858 }
859 if (child.forAllWindows(callback, traverseTopToBottom)) {
860 return true;
861 }
862 }
863 }
864 return false;
865 }
866
867 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
868 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
869 }
870
871 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -0700872 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700873 final WindowManagerPolicy policy = mService.mPolicy;
874
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700875 if (mService.mDisplayFrozen) {
876 if (mService.mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
877 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
878 "Display is frozen, return " + mService.mLastWindowForcedOrientation);
879 // If the display is frozen, some activities may be in the middle of restarting, and
880 // thus have removed their old window. If the window has the flag to hide the lock
881 // screen, then the lock screen can re-appear and inflict its own orientation on us.
882 // Keep the orientation stable until this all settles down.
883 return mService.mLastWindowForcedOrientation;
884 } else if (policy.isKeyguardLocked()) {
885 // Use the last orientation the while the display is frozen with the keyguard
886 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
887 // window. We don't want to check the show when locked window directly though as
888 // things aren't stable while the display is frozen, for example the window could be
889 // momentarily unavailable due to activity relaunch.
890 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
891 + "return " + mService.mLastOrientation);
892 return mService.mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -0700893 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700894 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000895 final int orientation = mAboveAppWindowsContainers.getOrientation();
896 if (orientation != SCREEN_ORIENTATION_UNSET) {
897 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700898 }
Wale Ogunwale51362492016-09-08 17:49:17 -0700899 }
900
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700901 // Top system windows are not requesting an orientation. Start searching from apps.
902 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -0700903 }
904
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700905 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700906 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700907 mDisplay.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700908 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
909 mTaskStackContainers.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800910 }
Craig Mautner722285e2012-09-07 13:55:58 -0700911 }
912
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700913 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700914 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
915 if (displayManagerInternal != null) {
916 // Bootstrap the default logical display from the display manager.
917 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
918 if (newDisplayInfo != null) {
919 mDisplayInfo.copyFrom(newDisplayInfo);
920 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700921 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700922
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800923 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
924 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
925 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
926 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700927 }
928
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700929 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700930 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800931 final int orientation = mDisplayInfo.rotation;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700932 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
Craig Mautner4a1cb222013-12-04 16:14:06 -0800933 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
934 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700935 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800936 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700937 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800938 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700939 out.set(left, top, left + width, top + height);
940 }
941
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700942 private void getLogicalDisplayRect(Rect out, int orientation) {
943 getLogicalDisplayRect(out);
944
945 // Rotate the Rect if needed.
946 final int currentRotation = mDisplayInfo.rotation;
947 final int rotationDelta = deltaRotation(currentRotation, orientation);
948 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
949 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
950 mTmpRectF.set(out);
951 mTmpMatrix.mapRect(mTmpRectF);
952 mTmpRectF.round(out);
953 }
954 }
955
Chong Zhangf66db432016-01-13 10:39:51 -0800956 void getContentRect(Rect out) {
957 out.set(mContentRect);
958 }
959
Andrii Kulian839def92016-11-02 10:58:58 -0700960 /**
961 * Adds the stack to this display.
962 * @see WindowManagerService#addStackToDisplay(int, int, boolean)
963 */
964 Rect addStackToDisplay(int stackId, boolean onTop) {
965 boolean attachedToDisplay = false;
966 TaskStack stack = mService.mStackIdToStack.get(stackId);
967 if (stack == null) {
968 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
969 + mDisplayId);
970
971 stack = getStackById(stackId);
972 if (stack != null) {
973 // It's already attached to the display...clear mDeferRemoval and move stack to
974 // appropriate z-order on display as needed.
975 stack.mDeferRemoval = false;
Andrii Kuliand2765632016-12-12 22:26:34 -0800976 // We're not moving the display to front when we're adding stacks, only when
977 // requested to change the position of stack explicitly.
978 mTaskStackContainers.positionChildAt(onTop ? POSITION_TOP : POSITION_BOTTOM, stack,
979 false /* includingParents */);
Andrii Kulian839def92016-11-02 10:58:58 -0700980 attachedToDisplay = true;
981 } else {
982 stack = new TaskStack(mService, stackId);
983 }
984
985 mService.mStackIdToStack.put(stackId, stack);
986 if (stackId == DOCKED_STACK_ID) {
987 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
988 }
989 } else {
990 final DisplayContent currentDC = stack.getDisplayContent();
991 if (currentDC != null) {
992 throw new IllegalStateException("Trying to add stackId=" + stackId
993 + "to displayId=" + mDisplayId + ", but it's already attached to displayId="
994 + currentDC.getDisplayId());
995 }
996 }
997
998 if (!attachedToDisplay) {
999 mTaskStackContainers.addStackToDisplay(stack, onTop);
1000 }
1001
1002 if (stack.getRawFullscreen()) {
1003 return null;
1004 }
1005 final Rect bounds = new Rect();
1006 stack.getRawBounds(bounds);
1007 return bounds;
1008 }
1009
1010 /** Removes the stack from the display and prepares for changing the parent. */
1011 private void removeStackFromDisplay(TaskStack stack) {
1012 mTaskStackContainers.removeStackFromDisplay(stack);
1013 }
1014
1015 /** Moves the stack to this display and returns the updated bounds. */
1016 Rect moveStackToDisplay(TaskStack stack) {
1017 final DisplayContent currentDisplayContent = stack.getDisplayContent();
1018 if (currentDisplayContent == null) {
1019 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1020 + " which is not currently attached to any display");
1021 }
1022 if (stack.getDisplayContent().getDisplayId() == mDisplayId) {
1023 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1024 + " to its current displayId=" + mDisplayId);
1025 }
1026
1027 currentDisplayContent.removeStackFromDisplay(stack);
1028 return addStackToDisplay(stack.mStackId, true /* onTop */);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001029 }
1030
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001031 @Override
1032 protected void addChild(DisplayChildWindowContainer child,
1033 Comparator<DisplayChildWindowContainer> comparator) {
1034 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1035 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001036
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001037 @Override
1038 protected void addChild(DisplayChildWindowContainer child, int index) {
1039 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1040 }
1041
1042 @Override
1043 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001044 // Only allow removal of direct children from this display if the display is in the process
1045 // of been removed.
1046 if (mRemovingDisplay) {
1047 super.removeChild(child);
1048 return;
1049 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001050 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001051 }
1052
Andrii Kuliand2765632016-12-12 22:26:34 -08001053 @Override
1054 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1055 // Children of the display are statically ordered, so the real intention here is to perform
1056 // the operation on the display and not the static direct children.
1057 getParent().positionChildAt(position, this, includingParents);
1058 }
1059
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001060 int taskIdFromPoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001061 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1062 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001063 final int taskId = stack.taskIdFromPoint(x, y);
1064 if (taskId != -1) {
1065 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001066 }
1067 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001068 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001069 }
1070
Chong Zhang8e89b312015-09-09 15:09:30 -07001071 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001072 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001073 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001074 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001075 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001076 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001077 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001078 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1079 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -07001080 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001081 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001082 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001083
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001084 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1085 if (mTmpTaskForResizePointSearchResult.searchDone) {
1086 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001087 }
1088 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001089 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001090 }
1091
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001092 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -07001093 mTouchExcludeRegion.set(mBaseDisplayRect);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001094 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001095 mTmpRect2.setEmpty();
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001096 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1097 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001098 stack.setTouchExcludeRegion(
1099 focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2);
Craig Mautner6601b7b2013-04-29 10:29:11 -07001100 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001101 // If we removed the focused task above, add it back and only leave its
1102 // outside touch area in the exclusion. TapDectector is not interested in
1103 // any touch inside the focused task itself.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001104 if (!mTmpRect2.isEmpty()) {
Chong Zhangd8ceb852015-11-11 14:53:41 -08001105 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1106 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001107 final WindowState inputMethod = mService.mInputMethodWindow;
1108 if (inputMethod != null && inputMethod.isVisibleLw()) {
1109 // If the input method is visible and the user is typing, we don't want these touch
1110 // events to be intercepted and used to change focus. This would likely cause a
1111 // disappearance of the input method.
1112 inputMethod.getTouchableRegion(mTmpRegion);
1113 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1114 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001115 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
1116 WindowState win = mTapExcludedWindows.get(i);
1117 win.getTouchableRegion(mTmpRegion);
1118 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1119 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001120 // TODO(multi-display): Support docked stacks on secondary displays.
1121 if (mDisplayId == DEFAULT_DISPLAY && getDockedStackLocked() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001122 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001123 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001124 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1125 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001126 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001127 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001128 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001129 }
1130
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001131 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001132 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001133 super.switchUser();
1134 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001135 }
1136
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001137 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001138 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1139 mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001140 }
1141 }
1142
1143 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001144 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -07001145 }
1146
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001147 private void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001148 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -07001149 }
1150
1151 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001152 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -07001153 }
1154
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001155 private void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001156 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -07001157 }
1158
Wale Ogunwale10124582016-09-15 20:25:50 -07001159 @Override
1160 void removeIfPossible() {
1161 if (isAnimating()) {
1162 mDeferredRemoval = true;
1163 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001164 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001165 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001166 }
1167
Wale Ogunwale10124582016-09-15 20:25:50 -07001168 @Override
1169 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001170 mRemovingDisplay = true;
1171 try {
1172 super.removeImmediately();
1173 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
1174 mDimLayerController.close();
1175 if (mDisplayId == DEFAULT_DISPLAY) {
1176 mService.unregisterPointerEventListener(mTapDetector);
1177 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1178 }
1179 } finally {
1180 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001181 }
Craig Mautner95da1082014-02-24 17:54:35 -08001182 }
1183
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001184 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001185 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001186 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001187 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1188
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001189 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001190 removeImmediately();
Craig Mautner95da1082014-02-24 17:54:35 -08001191 mService.onDisplayRemoved(mDisplayId);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001192 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001193 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001194 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001195 }
1196
Wale Ogunwale10124582016-09-15 20:25:50 -07001197 boolean animateForIme(float interpolatedValue, float animationTarget,
1198 float dividerAnimationTarget) {
1199 boolean updated = false;
1200
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001201 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1202 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001203 if (stack == null || !stack.isAdjustedForIme()) {
1204 continue;
1205 }
1206
1207 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
1208 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1209 updated = true;
1210 } else {
1211 mDividerControllerLocked.mLastAnimationProgress =
1212 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
1213 mDividerControllerLocked.mLastDividerProgress =
1214 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
1215 updated |= stack.updateAdjustForIme(
1216 mDividerControllerLocked.mLastAnimationProgress,
1217 mDividerControllerLocked.mLastDividerProgress,
1218 false /* force */);
1219 }
1220 if (interpolatedValue >= 1f) {
1221 stack.endImeAdjustAnimation();
1222 }
1223 }
1224
1225 return updated;
1226 }
1227
1228 boolean clearImeAdjustAnimation() {
1229 boolean changed = false;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001230 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1231 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001232 if (stack != null && stack.isAdjustedForIme()) {
1233 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1234 changed = true;
1235 }
1236 }
1237 return changed;
1238 }
1239
1240 void beginImeAdjustAnimation() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001241 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1242 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001243 if (stack.isVisible() && stack.isAdjustedForIme()) {
1244 stack.beginImeAdjustAnimation();
1245 }
1246 }
1247 }
1248
1249 void adjustForImeIfNeeded() {
1250 final WindowState imeWin = mService.mInputMethodWindow;
1251 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
1252 && !mDividerControllerLocked.isImeHideRequested();
1253 final boolean dockVisible = mService.isStackVisibleLocked(DOCKED_STACK_ID);
1254 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
1255 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
1256 imeTargetStack.getDockSide() : DOCKED_INVALID;
1257 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
1258 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
1259 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
1260 final int imeHeight = mService.mPolicy.getInputMethodWindowVisibleHeightLw();
1261 final boolean imeHeightChanged = imeVisible &&
1262 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
1263
1264 // The divider could be adjusted for IME position, or be thinner than usual,
1265 // or both. There are three possible cases:
1266 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
1267 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
1268 // - If IME is not visible, divider is not moved and is normal width.
1269
1270 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001271 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1272 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001273 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
1274 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)) {
1275 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
1276 } else {
1277 stack.resetAdjustedForIme(false);
1278 }
1279 }
1280 mDividerControllerLocked.setAdjustedForIme(
1281 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
1282 } else {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001283 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1284 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001285 stack.resetAdjustedForIme(!dockVisible);
1286 }
1287 mDividerControllerLocked.setAdjustedForIme(
1288 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
1289 }
Winson Chung655332c2016-10-31 13:14:28 -07001290 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07001291 }
1292
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001293 void setInputMethodAnimLayerAdjustment(int adj) {
1294 if (DEBUG_LAYERS) Slog.v(TAG_WM, "Setting im layer adj to " + adj);
1295 mInputMethodAnimLayerAdjustment = adj;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001296 mImeWindowsContainers.forAllWindows(mSetInputMethodAnimLayerAdjustment,
1297 true /* traverseTopToBottom */);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001298 }
1299
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001300 /**
1301 * If a window that has an animation specifying a colored background and the current wallpaper
1302 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
1303 * suddenly disappear.
1304 */
1305 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001306 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
1307 w -> w.mIsWallpaper && w.isVisibleNow());
1308
1309 if (visibleWallpaper != null) {
1310 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001311 }
1312 return winAnimator.mAnimLayer;
1313 }
1314
Wale Ogunwale10124582016-09-15 20:25:50 -07001315 void prepareFreezingTaskBounds() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001316 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1317 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07001318 stack.prepareFreezingTaskBounds();
1319 }
1320 }
1321
Wale Ogunwale94744212015-09-21 19:01:47 -07001322 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07001323 getLogicalDisplayRect(mTmpRect, newRotation);
1324
1325 // Compute a transform matrix to undo the coordinate space transformation,
1326 // and present the window at the same physical position it previously occupied.
1327 final int deltaRotation = deltaRotation(newRotation, oldRotation);
1328 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
1329
1330 mTmpRectF.set(bounds);
1331 mTmpMatrix.mapRect(mTmpRectF);
1332 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07001333 }
1334
Wale Ogunwale4a02d812015-02-12 23:01:38 -08001335 static int deltaRotation(int oldRotation, int newRotation) {
1336 int delta = newRotation - oldRotation;
1337 if (delta < 0) delta += 4;
1338 return delta;
1339 }
1340
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001341 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07001342 Matrix outMatrix) {
1343 // For rotations without Z-ordering we don't need the target rectangle's position.
1344 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
1345 displayHeight, outMatrix);
1346 }
1347
1348 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
1349 float displayWidth, float displayHeight, Matrix outMatrix) {
1350 switch (rotation) {
1351 case ROTATION_0:
1352 outMatrix.reset();
1353 break;
1354 case ROTATION_270:
1355 outMatrix.setRotate(270, 0, 0);
1356 outMatrix.postTranslate(0, displayHeight);
1357 outMatrix.postTranslate(rectTop, 0);
1358 break;
1359 case ROTATION_180:
1360 outMatrix.reset();
1361 break;
1362 case ROTATION_90:
1363 outMatrix.setRotate(90, 0, 0);
1364 outMatrix.postTranslate(displayWidth, 0);
1365 outMatrix.postTranslate(-rectTop, rectLeft);
1366 break;
1367 }
1368 }
1369
Craig Mautnera91f9e22012-09-14 16:22:08 -07001370 public void dump(String prefix, PrintWriter pw) {
1371 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
1372 final String subPrefix = " " + prefix;
1373 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
1374 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
1375 pw.print("dpi");
1376 if (mInitialDisplayWidth != mBaseDisplayWidth
1377 || mInitialDisplayHeight != mBaseDisplayHeight
1378 || mInitialDisplayDensity != mBaseDisplayDensity) {
1379 pw.print(" base=");
1380 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
1381 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
1382 }
Jeff Brownd46747a2015-04-15 19:02:36 -07001383 if (mDisplayScalingDisabled) {
1384 pw.println(" noscale");
1385 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07001386 pw.print(" cur=");
1387 pw.print(mDisplayInfo.logicalWidth);
1388 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
1389 pw.print(" app=");
1390 pw.print(mDisplayInfo.appWidth);
1391 pw.print("x"); pw.print(mDisplayInfo.appHeight);
1392 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
1393 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
1394 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
1395 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001396 pw.println(subPrefix + "deferred=" + mDeferredRemoval
1397 + " mLayoutNeeded=" + mLayoutNeeded);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001398
Craig Mautnerdc548482014-02-05 13:35:24 -08001399 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001400 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001401 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1402 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001403 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001404 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001405
Craig Mautnerdc548482014-02-05 13:35:24 -08001406 pw.println();
1407 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07001408 pw.println();
1409 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001410 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001411 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001412 pw.print(" Exiting #"); pw.print(i);
1413 pw.print(' '); pw.print(token);
1414 pw.println(':');
1415 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08001416 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07001417 }
Craig Mautner59c00972012-07-30 12:10:24 -07001418 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001419 mDimLayerController.dump(prefix, pw);
Jorim Jaggi31f71702016-05-04 16:43:04 -07001420 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001421 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07001422 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001423 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001424
1425 if (mInputMethodAnimLayerAdjustment != 0) {
1426 pw.println(subPrefix
1427 + "mInputMethodAnimLayerAdjustment=" + mInputMethodAnimLayerAdjustment);
1428 }
Craig Mautner59c00972012-07-30 12:10:24 -07001429 }
Craig Mautnere0a38842013-12-16 16:14:02 -08001430
1431 @Override
1432 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001433 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001434 }
1435
1436 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001437 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08001438 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001439
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08001440 /** Checks if stack with provided id is visible on this display. */
1441 boolean isStackVisible(int stackId) {
1442 final TaskStack stack = getStackById(stackId);
1443 return (stack != null && stack.isVisible());
1444 }
1445
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001446 /**
1447 * @return The docked stack, but only if it is visible, and {@code null} otherwise.
1448 */
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001449 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -07001450 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001451 return (stack != null && stack.isVisible()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001452 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001453
1454 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001455 * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not
Jorim Jaggife762342016-10-13 14:33:27 +02001456 * visible.
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001457 */
Jorim Jaggife762342016-10-13 14:33:27 +02001458 TaskStack getDockedStackIgnoringVisibility() {
1459 return mService.mStackIdToStack.get(DOCKED_STACK_ID);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001460 }
1461
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001462 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001463 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001464 final int x = (int) xf;
1465 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001466 final WindowState touchedWin = getWindow(w -> {
1467 final int flags = w.mAttrs.flags;
1468 if (!w.isVisibleLw()) {
1469 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001470 }
1471 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001472 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001473 }
1474
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001475 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001476 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001477 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001478 }
1479
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001480 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001481
1482 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001483 return mTmpRegion.contains(x, y) || touchFlags == 0;
1484 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001485
1486 return touchedWin;
1487 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07001488
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001489 boolean canAddToastWindowForUid(int uid) {
1490 // We allow one toast window per UID being shown at a time.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001491 final WindowState win = getWindow(w ->
1492 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
1493 && !w.mWindowRemovalAllowed);
1494 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001495 }
1496
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001497 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001498 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
1499 return;
1500 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001501
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001502 // Used to communicate the old focus to the callback method.
1503 mTmpWindow = oldFocus;
1504
1505 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001506 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001507
1508 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001509 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001510
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001511 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001512
1513 if (mTmpWindow == null) {
1514 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
1515 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001516 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001517 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001518 }
1519
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001520 /** Updates the layer assignment of windows on this display. */
1521 void assignWindowLayers(boolean setLayoutNeeded) {
Wale Ogunwaled1880962016-11-08 10:31:59 -08001522 mLayersController.assignWindowLayers(this);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001523 if (setLayoutNeeded) {
1524 setLayoutNeeded();
1525 }
1526 }
1527
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001528 void layoutAndAssignWindowLayersIfNeeded() {
1529 mService.mWindowsChanged = true;
1530 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001531
1532 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
1533 false /*updateInputWindows*/)) {
1534 assignWindowLayers(false /* setLayoutNeeded */);
1535 }
1536
1537 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
1538 mService.mWindowPlacerLocked.performSurfacePlacement();
1539 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1540 }
1541
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001542 /** Returns true if a leaked surface was destroyed */
1543 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001544 // Used to indicate that a surface was leaked.
1545 mTmpWindow = null;
1546 forAllWindows(w -> {
1547 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001548 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001549 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001550 }
1551 if (!mService.mSessions.contains(wsa.mSession)) {
1552 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001553 + w + " surface=" + wsa.mSurfaceController
1554 + " token=" + w.mToken
1555 + " pid=" + w.mSession.mPid
1556 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001557 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001558 mService.mForceRemoves.add(w);
1559 mTmpWindow = w;
1560 } else if (w.mAppToken != null && w.mAppToken.clientHidden) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001561 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001562 + w + " surface=" + wsa.mSurfaceController
1563 + " token=" + w.mAppToken
1564 + " saved=" + w.hasSavedSurface());
1565 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001566 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001567 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001568 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001569 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001570
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001571 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001572 }
1573
1574 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001575 * Determine and return the window that should be the IME target.
1576 * @param updateImeTarget If true the system IME target will be updated to match what we found.
1577 * @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 +00001578 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001579 WindowState computeImeTarget(boolean updateImeTarget) {
1580 if (mService.mInputMethodWindow == null) {
1581 // There isn't an IME so there shouldn't be a target...That was easy!
1582 if (updateImeTarget) {
1583 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
1584 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
1585 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim, 0);
1586 }
1587 return null;
1588 }
1589
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001590 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
1591 // same display. Or even when the current IME/target are not on the same screen as the next
1592 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001593 mUpdateImeTarget = updateImeTarget;
1594 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001595
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001596
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001597 // Yet more tricksyness! If this window is a "starting" window, we do actually want
1598 // to be on top of it, but it is not -really- where input will go. So look down below
1599 // for a real window to target...
1600 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
1601 final AppWindowToken token = target.mAppToken;
1602 if (token != null) {
1603 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
1604 if (betterTarget != null) {
1605 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001606 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001607 }
1608 }
1609
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001610 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
1611 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001612
1613 // Now, a special case -- if the last target's window is in the process of exiting, and is
1614 // above the new target, keep on the last target to avoid flicker. Consider for example a
1615 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
1616 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
1617 // scrim.
1618 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001619 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
1620 && (target == null
1621 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001622 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001623 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001624 }
1625
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001626 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
1627 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001628
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001629 if (target == null) {
1630 if (updateImeTarget) {
1631 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
1632 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
1633 + Debug.getCallers(4) : ""));
1634 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim, 0);
1635 }
1636
1637 return null;
1638 }
1639
1640 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001641 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
1642 if (token != null) {
1643
1644 // Now some fun for dealing with window animations that modify the Z order. We need
1645 // to look at all windows below the current target that are in this app, finding the
1646 // highest visible one in layering.
1647 WindowState highestTarget = null;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001648 if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001649 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001650 }
1651
1652 if (highestTarget != null) {
1653 final AppTransition appTransition = mService.mAppTransition;
1654 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
1655 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
1656 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001657 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001658
1659 if (appTransition.isTransitionSet()) {
1660 // If we are currently setting up for an animation, hold everything until we
1661 // can find out what will happen.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001662 setInputMethodTarget(highestTarget, true, mInputMethodAnimLayerAdjustment);
1663 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001664 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001665 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001666 // If the window we are currently targeting is involved with an animation,
1667 // and it is on top of the next target we will be over, then hold off on
1668 // moving until that is done.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001669 setInputMethodTarget(highestTarget, true, mInputMethodAnimLayerAdjustment);
1670 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001671 }
1672 }
1673 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001674
1675 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
1676 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
1677 setInputMethodTarget(target, false, target.mAppToken != null
1678 ? target.mAppToken.mAppAnimator.animLayerAdjustment : 0);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001679 }
1680
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001681 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001682 }
1683
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001684 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim, int layerAdj) {
1685 if (target == mService.mInputMethodTarget
1686 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim
1687 && mInputMethodAnimLayerAdjustment == layerAdj) {
1688 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001689 }
1690
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001691 mService.mInputMethodTarget = target;
1692 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
1693 setInputMethodAnimLayerAdjustment(layerAdj);
1694 assignWindowLayers(false /* setLayoutNeeded */);
1695 }
1696
1697 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
1698 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
1699 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
1700 }
1701
1702 // Used to indicate we have reached the first window in the range we are interested in.
1703 mTmpWindow = null;
1704
1705 // TODO: Figure-out a more efficient way to do this.
1706 final WindowState candidate = getWindow(w -> {
1707 if (w == top) {
1708 // Reached the first window in the range we are interested in.
1709 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001710 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001711 if (mTmpWindow == null) {
1712 return false;
1713 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001714
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001715 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
1716 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001717 }
1718 // If we reached the bottom of the range of windows we are considering,
1719 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001720 if (w == bottom) {
1721 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001722 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001723 return false;
1724 });
1725
1726 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001727 }
1728
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001729 void setLayoutNeeded() {
1730 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
1731 mLayoutNeeded = true;
1732 }
1733
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001734 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001735 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
1736 mLayoutNeeded = false;
1737 }
1738
1739 boolean isLayoutNeeded() {
1740 return mLayoutNeeded;
1741 }
1742
Wale Ogunwale02319a62016-09-26 15:21:22 -07001743 void dumpTokens(PrintWriter pw, boolean dumpAll) {
1744 if (mTokenMap.isEmpty()) {
1745 return;
1746 }
1747 pw.println(" Display #" + mDisplayId);
1748 final Iterator<WindowToken> it = mTokenMap.values().iterator();
1749 while (it.hasNext()) {
1750 final WindowToken token = it.next();
1751 pw.print(" ");
1752 pw.print(token);
1753 if (dumpAll) {
1754 pw.println(':');
1755 token.dump(pw, " ");
1756 } else {
1757 pw.println();
1758 }
1759 }
1760 }
1761
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07001762 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001763 final int[] index = new int[1];
1764 forAllWindows(w -> {
1765 final WindowStateAnimator wAnim = w.mWinAnimator;
1766 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
1767 index[0] = index[0] + 1;
1768 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07001769 }
1770
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001771 void enableSurfaceTrace(FileDescriptor fd) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001772 forAllWindows(w -> {
1773 w.mWinAnimator.enableSurfaceTrace(fd);
1774 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001775 }
1776
1777 void disableSurfaceTrace() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001778 forAllWindows(w -> {
1779 w.mWinAnimator.disableSurfaceTrace();
1780 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001781 }
1782
Jorim Jaggife762342016-10-13 14:33:27 +02001783 /**
1784 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
1785 */
1786 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
1787 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001788 forAllWindows(w -> {
1789 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)) {
1790 w.mWinAnimator.setAnimation(
Jorim Jaggife762342016-10-13 14:33:27 +02001791 policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
1792 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001793 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02001794 }
1795
Wale Ogunwale494009b82016-10-21 09:01:38 -07001796 boolean checkWaitingForWindows() {
1797
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001798 mHaveBootMsg = false;
1799 mHaveApp = false;
1800 mHaveWallpaper = false;
1801 mHaveKeyguard = true;
1802
1803 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07001804 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
1805 return true;
1806 }
1807 if (w.isDrawnLw()) {
1808 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001809 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07001810 } else if (w.mAttrs.type == TYPE_APPLICATION
1811 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001812 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07001813 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001814 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07001815 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001816 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07001817 }
1818 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001819 return false;
1820 });
1821
1822 if (visibleWindow != null) {
1823 // We have a visible window.
1824 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07001825 }
1826
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001827 // if the wallpaper service is disabled on the device, we're never going to have
1828 // wallpaper, don't bother waiting for it
1829 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
1830 com.android.internal.R.bool.config_enableWallpaperService)
1831 && !mService.mOnlyCore;
1832
Wale Ogunwale494009b82016-10-21 09:01:38 -07001833 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
1834 "******** booted=" + mService.mSystemBooted
1835 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001836 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
1837 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
1838 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07001839
1840 // If we are turning on the screen to show the boot message, don't do it until the boot
1841 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001842 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07001843 return true;
1844 }
1845
1846 // If we are turning on the screen after the boot is completed normally, don't do so until
1847 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001848 if (mService.mSystemBooted
1849 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07001850 return true;
1851 }
1852
1853 return false;
1854 }
1855
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07001856 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001857 mTmpWindowAnimator = animator;
1858 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07001859 }
1860
1861 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07001862 resetAnimationBackgroundAnimator();
1863
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001864 // Used to indicate a detached wallpaper.
1865 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001866 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07001867
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001868 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07001869
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001870 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07001871 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001872 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
1873 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07001874 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
1875 }
1876 }
1877
1878 void prepareWindowSurfaces() {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001879 forAllWindows(mPrepareWindowSurfaces, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07001880 }
1881
Wale Ogunwale494009b82016-10-21 09:01:38 -07001882 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001883 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001884 if (imFocus == null) {
1885 return false;
1886 }
1887
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001888 if (DEBUG_INPUT_METHOD) {
1889 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
1890 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
1891 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001892 }
1893
Wale Ogunwale494009b82016-10-21 09:01:38 -07001894 final IInputMethodClient imeClient = imFocus.mSession.mClient;
1895
1896 if (DEBUG_INPUT_METHOD) {
1897 Slog.i(TAG_WM, "IM target client: " + imeClient);
1898 if (imeClient != null) {
1899 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
1900 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
1901 }
1902 }
1903
1904 return imeClient != null && imeClient.asBinder() == client.asBinder();
1905 }
1906
1907 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001908 final WindowState win = getWindow(
1909 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
1910 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07001911 }
1912
1913 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001914 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07001915 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001916 final int curValue = w.mSystemUiVisibility;
1917 final int diff = (curValue ^ visibility) & globalDiff;
1918 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07001919 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001920 w.mSeq++;
1921 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07001922 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001923 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
1924 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07001925 visibility, newValue, diff);
1926 }
1927 } catch (RemoteException e) {
1928 // so sorry
1929 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001930 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07001931 }
1932
1933 void onWindowFreezeTimeout() {
1934 Slog.w(TAG_WM, "Window freeze timeout expired.");
1935 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001936
1937 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07001938 if (!w.mOrientationChanging) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001939 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07001940 }
1941 w.mOrientationChanging = false;
1942 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1943 - mService.mDisplayFreezeTime);
1944 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001945 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07001946 mService.mWindowPlacerLocked.performSurfacePlacement();
1947 }
1948
1949 void waitForAllWindowsDrawn() {
1950 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001951 forAllWindows(w -> {
1952 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
1953 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
1954 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07001955 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001956 w.mLastContentInsets.set(-1, -1, -1, -1);
1957 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07001958 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001959 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07001960 }
1961
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001962 // TODO: Super crazy long method that should be broken down...
1963 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
1964
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001965 final int dw = mDisplayInfo.logicalWidth;
1966 final int dh = mDisplayInfo.logicalHeight;
1967 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
1968
1969 mTmpUpdateAllDrawn.clear();
1970
1971 int repeats = 0;
1972 do {
1973 repeats++;
1974 if (repeats > 6) {
1975 Slog.w(TAG, "Animation repeat aborted after too many iterations");
1976 clearLayoutNeeded();
1977 break;
1978 }
1979
1980 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
1981 pendingLayoutChanges);
1982
Andrii Kulian839def92016-11-02 10:58:58 -07001983 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
1984 // the wallpaper window jumping across displays.
1985 // Remove check for default display when there will be support for multiple wallpaper
1986 // targets (on different displays).
1987 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001988 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001989 }
1990
1991 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
1992 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
1993 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
1994 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07001995 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001996 }
1997 }
1998
1999 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2000 setLayoutNeeded();
2001 }
2002
2003 // FIRST LOOP: Perform a layout, if needed.
2004 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2005 performLayout(repeats == 1, false /* updateInputWindows */);
2006 } else {
2007 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2008 }
2009
2010 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2011 pendingLayoutChanges = 0;
2012
2013 if (isDefaultDisplay) {
2014 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002015 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002016 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2017 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2018 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2019 }
2020 } while (pendingLayoutChanges != 0);
2021
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002022 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002023 resetDimming();
2024
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002025 mTmpRecoveringMemory = recoveringMemory;
2026 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002027
2028 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002029 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2030 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2031 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002032 true /* inTraversal, must call performTraversalInTrans... below */);
2033
2034 stopDimmingIfNeeded();
2035
2036 while (!mTmpUpdateAllDrawn.isEmpty()) {
2037 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2038 // See if any windows have been drawn, so they (and others associated with them)
2039 // can now be shown.
2040 atoken.updateAllDrawn(this);
2041 }
2042
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002043 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002044 }
2045
2046 void performLayout(boolean initial, boolean updateInputWindows) {
2047 if (!isLayoutNeeded()) {
2048 return;
2049 }
2050 clearLayoutNeeded();
2051
2052 final int dw = mDisplayInfo.logicalWidth;
2053 final int dh = mDisplayInfo.logicalHeight;
2054
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002055 if (DEBUG_LAYOUT) {
2056 Slog.v(TAG, "-------------------------------------");
2057 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2058 }
2059
2060 mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mService.mRotation,
2061 getConfiguration().uiMode);
2062 if (isDefaultDisplay) {
2063 // Not needed on non-default displays.
2064 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2065 mService.mScreenRect.set(0, 0, dw, dh);
2066 }
2067
2068 mService.mPolicy.getContentRectLw(mContentRect);
2069
2070 int seq = mService.mLayoutSeq + 1;
2071 if (seq < 0) seq = 0;
2072 mService.mLayoutSeq = seq;
2073
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002074 // Used to indicate that we have processed the dream window and all additional windows are
2075 // behind it.
2076 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002077 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002078
2079 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002080 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002081
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002082 // Used to indicate that we have processed the dream window and all additional attached
2083 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002084 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002085 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002086
2087 // Now perform layout of attached windows, which usually depend on the position of the
2088 // window they are attached to. XXX does not deal with windows that are attached to windows
2089 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002090 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002091
2092 // Window frames may have changed. Tell the input dispatcher about it.
2093 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2094 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2095 if (updateInputWindows) {
2096 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2097 }
2098
2099 mService.mPolicy.finishLayoutLw();
2100 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2101 }
2102
2103 /**
2104 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2105 * In portrait mode, it grabs the full screenshot.
2106 *
2107 * @param width the width of the target bitmap
2108 * @param height the height of the target bitmap
2109 * @param includeFullDisplay true if the screen should not be cropped before capture
2110 * @param frameScale the scale to apply to the frame, only used when width = -1 and height = -1
2111 * @param config of the output bitmap
2112 * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
Jorim Jaggi02886a82016-12-06 09:10:06 -08002113 * @param includeDecor whether to include window decors, like the status or navigation bar
2114 * background of the window
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002115 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002116 Bitmap screenshotApplications(IBinder appToken, int width, int height,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002117 boolean includeFullDisplay, float frameScale, Bitmap.Config config,
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01002118 boolean wallpaperOnly, boolean includeDecor) {
2119 Bitmap bitmap = screenshotApplications(appToken, width, height, includeFullDisplay,
2120 frameScale, wallpaperOnly, includeDecor, SurfaceControl::screenshot);
Jorim Jaggi9f9d61f2017-01-17 11:15:37 +01002121 if (bitmap == null) {
2122 return null;
2123 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01002124
2125 if (DEBUG_SCREENSHOT) {
2126 // TEST IF IT's ALL BLACK
2127 int[] buffer = new int[bitmap.getWidth() * bitmap.getHeight()];
2128 bitmap.getPixels(buffer, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(),
2129 bitmap.getHeight());
2130 boolean allBlack = true;
2131 final int firstColor = buffer[0];
2132 for (int i = 0; i < buffer.length; i++) {
2133 if (buffer[i] != firstColor) {
2134 allBlack = false;
2135 break;
2136 }
2137 }
2138 if (allBlack) {
2139 final WindowState appWin = mScreenshotApplicationState.appWin;
2140 final int maxLayer = mScreenshotApplicationState.maxLayer;
2141 final int minLayer = mScreenshotApplicationState.minLayer;
2142 Slog.i(TAG_WM, "Screenshot " + appWin + " was monochrome(" +
2143 Integer.toHexString(firstColor) + ")! mSurfaceLayer=" +
2144 (appWin != null ?
2145 appWin.mWinAnimator.mSurfaceController.getLayer() : "null") +
2146 " minLayer=" + minLayer + " maxLayer=" + maxLayer);
2147 }
2148 }
2149
2150 // Create a copy of the screenshot that is immutable and backed in ashmem.
2151 // This greatly reduces the overhead of passing the bitmap between processes.
2152 Bitmap ret = bitmap.createAshmemBitmap(config);
2153 bitmap.recycle();
2154 return ret;
2155 }
2156
2157 GraphicBuffer screenshotApplicationsToBuffer(IBinder appToken, int width, int height,
2158 boolean includeFullDisplay, float frameScale, boolean wallpaperOnly,
2159 boolean includeDecor) {
2160 return screenshotApplications(appToken, width, height, includeFullDisplay, frameScale,
2161 wallpaperOnly, includeDecor, SurfaceControl::screenshotToBuffer);
2162 }
2163
2164 private <E> E screenshotApplications(IBinder appToken, int width, int height,
2165 boolean includeFullDisplay, float frameScale, boolean wallpaperOnly,
2166 boolean includeDecor, Screenshoter<E> screenshoter) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002167 int dw = mDisplayInfo.logicalWidth;
2168 int dh = mDisplayInfo.logicalHeight;
2169 if (dw == 0 || dh == 0) {
2170 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
2171 + ": returning null. logical widthxheight=" + dw + "x" + dh);
2172 return null;
2173 }
2174
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01002175 E bitmap;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002176
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002177 mScreenshotApplicationState.reset(appToken == null && !wallpaperOnly);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002178 final Rect frame = new Rect();
2179 final Rect stackBounds = new Rect();
2180
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002181 boolean includeImeInScreenshot;
2182 synchronized(mService.mWindowMap) {
2183 final AppWindowToken imeTargetAppToken = mService.mInputMethodTarget != null
2184 ? mService.mInputMethodTarget.mAppToken : null;
2185 // We only include the Ime in the screenshot if the app we are screenshoting is the IME
2186 // target and isn't in multi-window mode. We don't screenshot the IME in multi-window
2187 // mode because the frame of the IME might not overlap with that of the app.
2188 // E.g. IME target app at the top in split-screen mode and the IME at the bottom
2189 // overlapping with the bottom app.
2190 includeImeInScreenshot = imeTargetAppToken != null
2191 && imeTargetAppToken.appToken != null
2192 && imeTargetAppToken.appToken.asBinder() == appToken
2193 && !mService.mInputMethodTarget.isInMultiWindowMode();
2194 }
2195
2196 final int aboveAppLayer = (mService.mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) + 1)
2197 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Jorim Jaggi02886a82016-12-06 09:10:06 -08002198 final MutableBoolean mutableIncludeFullDisplay = new MutableBoolean(includeFullDisplay);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002199 synchronized(mService.mWindowMap) {
2200 // Figure out the part of the screen that is actually the app.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002201 mScreenshotApplicationState.appWin = null;
2202 forAllWindows(w -> {
2203 if (!w.mHasSurface) {
2204 return false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002205 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002206 if (w.mLayer >= aboveAppLayer) {
2207 return false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002208 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002209 if (wallpaperOnly && !w.mIsWallpaper) {
2210 return false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002211 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002212 if (w.mIsImWindow) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002213 if (!includeImeInScreenshot) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002214 return false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002215 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002216 } else if (w.mIsWallpaper) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002217 // If this is the wallpaper layer and we're only looking for the wallpaper layer
2218 // then the target window state is this one.
2219 if (wallpaperOnly) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002220 mScreenshotApplicationState.appWin = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002221 }
2222
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002223 if (mScreenshotApplicationState.appWin == null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002224 // We have not ran across the target window yet, so it is probably behind
2225 // the wallpaper. This can happen when the keyguard is up and all windows
2226 // are moved behind the wallpaper. We don't want to include the wallpaper
2227 // layer in the screenshot as it will cover-up the layer of the target
2228 // window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002229 return false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002230 }
2231 // Fall through. The target window is in front of the wallpaper. For this
2232 // case we want to include the wallpaper layer in the screenshot because
2233 // the target window might have some transparent areas.
2234 } else if (appToken != null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002235 if (w.mAppToken == null || w.mAppToken.token != appToken) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002236 // This app window is of no interest if it is not associated with the
2237 // screenshot app.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002238 return false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002239 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002240 mScreenshotApplicationState.appWin = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002241 }
2242
2243 // Include this window.
2244
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002245 final WindowStateAnimator winAnim = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002246 int layer = winAnim.mSurfaceController.getLayer();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002247 if (mScreenshotApplicationState.maxLayer < layer) {
2248 mScreenshotApplicationState.maxLayer = layer;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002249 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002250 if (mScreenshotApplicationState.minLayer > layer) {
2251 mScreenshotApplicationState.minLayer = layer;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002252 }
2253
2254 // Don't include wallpaper in bounds calculation
Jorim Jaggi02886a82016-12-06 09:10:06 -08002255 if (includeDecor && !stackBounds.isEmpty()) {
2256 frame.set(stackBounds);
2257 } else if (includeDecor) {
2258 mutableIncludeFullDisplay.value = true;
2259 } else if (!mutableIncludeFullDisplay.value && !w.mIsWallpaper) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002260 final Rect wf = w.mFrame;
2261 final Rect cr = w.mContentInsets;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002262 int left = wf.left + cr.left;
2263 int top = wf.top + cr.top;
2264 int right = wf.right - cr.right;
2265 int bottom = wf.bottom - cr.bottom;
2266 frame.union(left, top, right, bottom);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002267 w.getVisibleBounds(stackBounds);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002268 if (!Rect.intersects(frame, stackBounds)) {
2269 // Set frame empty if there's no intersection.
2270 frame.setEmpty();
2271 }
2272 }
2273
2274 final boolean foundTargetWs =
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002275 (w.mAppToken != null && w.mAppToken.token == appToken)
2276 || (mScreenshotApplicationState.appWin != null && wallpaperOnly);
2277 if (foundTargetWs && w.isDisplayedLw() && winAnim.getShown()) {
2278 mScreenshotApplicationState.screenshotReady = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002279 }
2280
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002281 if (w.isObscuringDisplay()){
2282 return true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002283 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002284 return false;
2285 }, true /* traverseTopToBottom */);
2286
2287 final WindowState appWin = mScreenshotApplicationState.appWin;
2288 final boolean screenshotReady = mScreenshotApplicationState.screenshotReady;
2289 final int maxLayer = mScreenshotApplicationState.maxLayer;
2290 final int minLayer = mScreenshotApplicationState.minLayer;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002291
2292 if (appToken != null && appWin == null) {
2293 // Can't find a window to snapshot.
2294 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM,
2295 "Screenshot: Couldn't find a surface matching " + appToken);
2296 return null;
2297 }
2298
2299 if (!screenshotReady) {
2300 Slog.i(TAG_WM, "Failed to capture screenshot of " + appToken +
2301 " appWin=" + (appWin == null ? "null" : (appWin + " drawState=" +
2302 appWin.mWinAnimator.mDrawState)));
2303 return null;
2304 }
2305
2306 // Screenshot is ready to be taken. Everything from here below will continue
2307 // through the bottom of the loop and return a value. We only stay in the loop
2308 // because we don't want to release the mWindowMap lock until the screenshot is
2309 // taken.
2310
2311 if (maxLayer == 0) {
2312 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
2313 + ": returning null maxLayer=" + maxLayer);
2314 return null;
2315 }
2316
Jorim Jaggi02886a82016-12-06 09:10:06 -08002317 if (!mutableIncludeFullDisplay.value) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002318 // Constrain frame to the screen size.
2319 if (!frame.intersect(0, 0, dw, dh)) {
2320 frame.setEmpty();
2321 }
2322 } else {
2323 // Caller just wants entire display.
2324 frame.set(0, 0, dw, dh);
2325 }
2326 if (frame.isEmpty()) {
2327 return null;
2328 }
2329
2330 if (width < 0) {
2331 width = (int) (frame.width() * frameScale);
2332 }
2333 if (height < 0) {
2334 height = (int) (frame.height() * frameScale);
2335 }
2336
2337 // Tell surface flinger what part of the image to crop. Take the top
2338 // right part of the application, and crop the larger dimension to fit.
2339 Rect crop = new Rect(frame);
2340 if (width / (float) frame.width() < height / (float) frame.height()) {
2341 int cropWidth = (int)((float)width / (float)height * frame.height());
2342 crop.right = crop.left + cropWidth;
2343 } else {
2344 int cropHeight = (int)((float)height / (float)width * frame.width());
2345 crop.bottom = crop.top + cropHeight;
2346 }
2347
2348 // The screenshot API does not apply the current screen rotation.
2349 int rot = mDisplay.getRotation();
2350
2351 if (rot == ROTATION_90 || rot == ROTATION_270) {
2352 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
2353 }
2354
2355 // Surfaceflinger is not aware of orientation, so convert our logical
2356 // crop to surfaceflinger's portrait orientation.
2357 convertCropForSurfaceFlinger(crop, rot, dw, dh);
2358
2359 if (DEBUG_SCREENSHOT) {
2360 Slog.i(TAG_WM, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to "
2361 + maxLayer + " appToken=" + appToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002362 forAllWindows(w -> {
2363 final WindowSurfaceController controller = w.mWinAnimator.mSurfaceController;
2364 Slog.i(TAG_WM, w + ": " + w.mLayer
2365 + " animLayer=" + w.mWinAnimator.mAnimLayer
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002366 + " surfaceLayer=" + ((controller == null)
2367 ? "null" : controller.getLayer()));
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002368 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002369 }
2370
2371 final ScreenRotationAnimation screenRotationAnimation =
2372 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
2373 final boolean inRotation = screenRotationAnimation != null &&
2374 screenRotationAnimation.isAnimating();
2375 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM,
2376 "Taking screenshot while rotating");
2377
2378 // We force pending transactions to flush before taking
2379 // the screenshot by pushing an empty synchronous transaction.
2380 SurfaceControl.openTransaction();
2381 SurfaceControl.closeTransactionSync();
2382
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01002383 bitmap = screenshoter.screenshot(crop, width, height, minLayer, maxLayer,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002384 inRotation, rot);
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01002385 if (bitmap == null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002386 Slog.w(TAG_WM, "Screenshot failure taking screenshot for (" + dw + "x" + dh
2387 + ") to layer " + maxLayer);
2388 return null;
2389 }
2390 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01002391 return bitmap;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002392 }
2393
2394 // TODO: Can this use createRotationMatrix()?
2395 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
2396 if (rot == Surface.ROTATION_90) {
2397 final int tmp = crop.top;
2398 crop.top = dw - crop.right;
2399 crop.right = crop.bottom;
2400 crop.bottom = dw - crop.left;
2401 crop.left = tmp;
2402 } else if (rot == Surface.ROTATION_180) {
2403 int tmp = crop.top;
2404 crop.top = dh - crop.bottom;
2405 crop.bottom = dh - tmp;
2406 tmp = crop.right;
2407 crop.right = dw - crop.left;
2408 crop.left = dw - tmp;
2409 } else if (rot == Surface.ROTATION_270) {
2410 final int tmp = crop.top;
2411 crop.top = crop.left;
2412 crop.left = dh - crop.bottom;
2413 crop.bottom = crop.right;
2414 crop.right = dh - tmp;
2415 }
2416 }
2417
2418 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002419 // Used to indicate the layout is needed.
2420 mTmpWindow = null;
2421
2422 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002423 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002424 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002425 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002426 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002427 w.setDisplayLayoutNeeded();
2428 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002429 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002430
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002431 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002432 mService.mWindowPlacerLocked.performSurfacePlacement();
2433 }
2434 }
2435
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002436 static final class TaskForResizePointSearchResult {
2437 boolean searchDone;
2438 Task taskForResize;
2439
2440 void reset() {
2441 searchDone = false;
2442 taskForResize = null;
2443 }
2444 }
Robert Carr3b716242016-08-16 16:02:21 -07002445
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002446 private static final class ApplySurfaceChangesTransactionState {
2447 boolean displayHasContent;
2448 boolean obscured;
2449 boolean syswin;
2450 boolean focusDisplayed;
2451 float preferredRefreshRate;
2452 int preferredModeId;
2453
2454 void reset() {
2455 displayHasContent = false;
2456 obscured = false;
2457 syswin = false;
2458 focusDisplayed = false;
2459 preferredRefreshRate = 0;
2460 preferredModeId = 0;
2461 }
2462 }
2463
2464 private static final class ScreenshotApplicationState {
2465 WindowState appWin;
2466 int maxLayer;
2467 int minLayer;
2468 boolean screenshotReady;
2469
2470 void reset(boolean screenshotReady) {
2471 appWin = null;
2472 maxLayer = 0;
2473 minLayer = 0;
2474 this.screenshotReady = screenshotReady;
2475 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
2476 }
2477 }
2478
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002479 /**
2480 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
2481 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
2482 * homogeneous children type which is currently required by sub-classes of
2483 * {@link WindowContainer} class.
2484 */
2485 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
2486
2487 int size() {
2488 return mChildren.size();
2489 }
2490
2491 E get(int index) {
2492 return mChildren.get(index);
2493 }
2494
2495 @Override
2496 boolean fillsParent() {
2497 return true;
2498 }
2499
2500 @Override
2501 boolean isVisible() {
2502 return true;
Robert Carr3b716242016-08-16 16:02:21 -07002503 }
2504 }
2505
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002506 /**
2507 * Window container class that contains all containers on this display relating to Apps.
2508 * I.e Activities.
2509 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07002510 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002511
Andrii Kulian839def92016-11-02 10:58:58 -07002512 /**
2513 * Adds the stack to this container.
2514 * @see WindowManagerService#addStackToDisplay(int, int, boolean)
2515 */
2516 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002517 if (stack.mStackId == HOME_STACK_ID) {
2518 if (mHomeStack != null) {
2519 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
2520 }
2521 mHomeStack = stack;
2522 }
2523 addChild(stack, onTop);
2524 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07002525 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002526
Andrii Kulian839def92016-11-02 10:58:58 -07002527 /** Removes the stack from its container and prepare for changing the parent. */
2528 void removeStackFromDisplay(TaskStack stack) {
2529 removeChild(stack);
2530 stack.onRemovedFromDisplay();
Andrii Kulian839def92016-11-02 10:58:58 -07002531 }
2532
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002533 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08002534 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
2535 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002536 addChild(stack, addIndex);
2537 setLayoutNeeded();
2538 }
2539
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002540 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08002541 void positionChildAt(int position, TaskStack child, boolean includingParents) {
2542 if (StackId.isAlwaysOnTop(child.mStackId) && position != POSITION_TOP) {
2543 // This stack is always-on-top, override the default behavior.
2544 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
2545
2546 // Moving to its current position, as we must call super but we don't want to
2547 // perform any meaningful action.
2548 final int currentPosition = mChildren.indexOf(child);
2549 super.positionChildAt(currentPosition, child, false /* includingParents */);
2550 return;
2551 }
2552
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08002553 final int targetPosition = findPositionForStack(position, child, false /* adding */);
2554 super.positionChildAt(targetPosition, child, includingParents);
2555
2556 setLayoutNeeded();
2557 }
2558
2559 /**
2560 * When stack is added or repositioned, find a proper position for it.
2561 * This will make sure that pinned stack always stays on top.
2562 * @param requestedPosition Position requested by caller.
2563 * @param stack Stack to be added or positioned.
2564 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
2565 * @return The proper position for the stack.
2566 */
2567 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
2568 final int topChildPosition = mChildren.size() - 1;
2569 boolean toTop = requestedPosition == POSITION_TOP;
2570 toTop |= adding ? requestedPosition >= topChildPosition + 1
2571 : requestedPosition >= topChildPosition;
2572 int targetPosition = requestedPosition;
2573
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002574 if (toTop && isStackVisible(PINNED_STACK_ID) && stack.mStackId != PINNED_STACK_ID) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08002575 // The pinned stack is always the top most stack (always-on-top) when it is visible.
2576 TaskStack topStack = mChildren.get(topChildPosition);
2577 if (topStack.mStackId != PINNED_STACK_ID) {
2578 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
2579 }
2580
2581 // So, stack is moved just below the pinned stack.
2582 // When we're adding a new stack the target is the current pinned stack position.
2583 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002584 // stack, because WindowContainer#positionAt() first removes element and then adds
2585 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08002586 targetPosition = adding ? topChildPosition : topChildPosition - 1;
2587 }
2588
2589 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08002590 }
2591
2592 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08002593 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
2594 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07002595 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08002596 if (super.forAllWindows(callback, traverseTopToBottom)) {
2597 return true;
2598 }
2599 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
2600 return true;
2601 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07002602 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08002603 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
2604 return true;
2605 }
2606 if (super.forAllWindows(callback, traverseTopToBottom)) {
2607 return true;
2608 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07002609 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08002610 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07002611 }
2612
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08002613 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07002614 boolean traverseTopToBottom) {
2615 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
2616 // app tokens.
2617 // TODO: Investigate if we need to continue to do this or if we can just process them
2618 // in-order.
2619 if (traverseTopToBottom) {
2620 for (int i = mChildren.size() - 1; i >= 0; --i) {
2621 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
2622 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08002623 if (appTokens.get(j).forAllWindowsUnchecked(callback,
2624 traverseTopToBottom)) {
2625 return true;
2626 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07002627 }
2628 }
2629 } else {
2630 final int count = mChildren.size();
2631 for (int i = 0; i < count; ++i) {
2632 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
2633 final int appTokensCount = appTokens.size();
2634 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08002635 if (appTokens.get(j).forAllWindowsUnchecked(callback,
2636 traverseTopToBottom)) {
2637 return true;
2638 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07002639 }
2640 }
2641 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08002642 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07002643 }
2644
2645 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002646 int getOrientation() {
2647 if (mService.isStackVisibleLocked(DOCKED_STACK_ID)
2648 || mService.isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID)) {
2649 // Apps and their containers are not allowed to specify an orientation while the
2650 // docked or freeform stack is visible...except for the home stack/task if the
2651 // docked stack is minimized and it actually set something.
2652 if (mHomeStack != null && mHomeStack.isVisible()
2653 && mDividerControllerLocked.isMinimizedDock()) {
2654 final int orientation = mHomeStack.getOrientation();
2655 if (orientation != SCREEN_ORIENTATION_UNSET) {
2656 return orientation;
2657 }
2658 }
2659 return SCREEN_ORIENTATION_UNSPECIFIED;
2660 }
2661
2662 final int orientation = super.getOrientation();
2663 if (orientation != SCREEN_ORIENTATION_UNSET
2664 && orientation != SCREEN_ORIENTATION_BEHIND) {
2665 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
2666 "App is requesting an orientation, return " + orientation);
2667 return orientation;
2668 }
2669
2670 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
2671 "No app is requesting an orientation, return " + mService.mLastOrientation);
2672 // The next app has not been requested to be visible, so we keep the current orientation
2673 // to prevent freezing/unfreezing the display too early.
2674 return mService.mLastOrientation;
2675 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002676 }
2677
2678 /**
2679 * Window container class that contains all containers on this display that are not related to
2680 * Apps. E.g. status bar.
2681 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07002682 private final class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
2683 /**
2684 * Compares two child window tokens returns -1 if the first is lesser than the second in
2685 * terms of z-order and 1 otherwise.
2686 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002687 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07002688 // Tokens with higher base layer are z-ordered on-top.
2689 mService.mPolicy.windowTypeToLayerLw(token1.windowType)
2690 < mService.mPolicy.windowTypeToLayerLw(token2.windowType) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002691
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002692 private final Predicate<WindowState> mGetOrientingWindow = w -> {
2693 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
2694 return false;
2695 }
2696 final int req = w.mAttrs.screenOrientation;
2697 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
2698 || req == SCREEN_ORIENTATION_UNSET) {
2699 return false;
2700 }
2701 return true;
2702 };
2703
Wale Ogunwale3a931692016-11-02 16:49:48 -07002704 private final String mName;
2705 NonAppWindowContainers(String name) {
2706 mName = name;
2707 }
2708
2709 void addChild(WindowToken token) {
2710 addChild(token, mWindowComparator);
2711 }
2712
2713 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002714 int getOrientation() {
2715 final WindowManagerPolicy policy = mService.mPolicy;
2716 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002717 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002718
2719 if (win != null) {
2720 final int req = win.mAttrs.screenOrientation;
2721 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
2722 if (policy.isKeyguardHostWindow(win.mAttrs)) {
2723 mService.mLastKeyguardForcedOrientation = req;
2724 }
2725 return (mService.mLastWindowForcedOrientation = req);
2726 }
2727
2728 mService.mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
2729
2730 if (policy.isKeyguardShowingAndNotOccluded()) {
2731 return mService.mLastKeyguardForcedOrientation;
2732 }
2733
2734 return SCREEN_ORIENTATION_UNSET;
2735 }
2736
2737 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07002738 String getName() {
2739 return mName;
2740 }
Robert Carr3b716242016-08-16 16:02:21 -07002741 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01002742
2743 /**
2744 * Interface to screenshot into various types, i.e. {@link Bitmap} and {@link GraphicBuffer}.
2745 */
2746 @FunctionalInterface
2747 private interface Screenshoter<E> {
2748 E screenshot(Rect sourceCrop, int width, int height, int minLayer, int maxLayer,
2749 boolean useIdentityTransform, int rotation);
2750 }
Craig Mautner59c00972012-07-30 12:10:24 -07002751}