blob: e73acde65a3d4e28b5bfcf757d1fec1b1321787d [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;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +000036import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION;
37import static android.view.WindowManager.INPUT_CONSUMER_PIP;
38import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER;
39import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080040import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
41import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
42import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale494009b82016-10-21 09:01:38 -070043import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070044import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070045import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
46import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +000047import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070048import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwale494009b82016-10-21 09:01:38 -070049import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070050import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +000051import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale494009b82016-10-21 09:01:38 -070052import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +000053import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwale494009b82016-10-21 09:01:38 -070054import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070055import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Wale Ogunwale3a931692016-11-02 16:49:48 -070056import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
57import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale494009b82016-10-21 09:01:38 -070058import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070059import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
60import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070061import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070062import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070063import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070064import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
65import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070066import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +000067import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070069import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070070import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
71import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070072import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwalec69694a2016-10-18 13:51:15 -070073import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070074import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070075import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020076import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070077import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070078import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070079import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +000080import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070081import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070082import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +000083import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070084import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070085import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070086import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080087import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070088import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
89import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -070090import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070091import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
92import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
93import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
94import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale494009b82016-10-21 09:01:38 -070095import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070096import static com.android.server.wm.WindowManagerService.dipToPixel;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +000097import static com.android.server.wm.WindowManagerService.localLOGV;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070098import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070099import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700100import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700101import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700102import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700103
Andrii Kulian3a507b52016-09-19 18:14:12 -0700104import android.annotation.NonNull;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700105import android.app.ActivityManager.StackId;
Andrii Kulian441e4492016-09-29 15:25:00 -0700106import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700107import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700108import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800109import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700110import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700111import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100112import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700113import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700114import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700115import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700116import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700117import android.os.RemoteException;
118import android.os.SystemClock;
Chong Zhang8e89b312015-09-09 15:09:30 -0700119import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700120import android.util.Slog;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700121import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -0700122import android.view.DisplayInfo;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000123import android.view.IWindow;
124import android.view.InputChannel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700125import android.view.Surface;
126import android.view.SurfaceControl;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700127import android.view.WindowManagerPolicy;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700128
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000129import com.android.internal.util.FastPrintWriter;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800130import com.android.internal.util.ToBooleanFunction;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700131import com.android.internal.view.IInputMethodClient;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000132import com.android.server.input.InputWindowHandle;
Craig Mautner59c00972012-07-30 12:10:24 -0700133
Robert Carr3b716242016-08-16 16:02:21 -0700134import java.io.FileDescriptor;
Craig Mautner59c00972012-07-30 12:10:24 -0700135import java.io.PrintWriter;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000136import java.io.StringWriter;
Craig Mautner59c00972012-07-30 12:10:24 -0700137import java.util.ArrayList;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000138import java.util.Arrays;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700139import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700140import java.util.HashMap;
141import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700142import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700143import java.util.List;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000144import java.util.function.Consumer;
145import java.util.function.Function;
Craig Mautner59c00972012-07-30 12:10:24 -0700146
Craig Mautner59c00972012-07-30 12:10:24 -0700147/**
148 * Utility class for keeping track of the WindowStates and other pertinent contents of a
149 * particular Display.
150 *
151 * IMPORTANT: No method from this class should ever be used without holding
152 * WindowManagerService.mWindowMap.
153 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700154class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700155 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700156
157 /** Unique identifier of this stack. */
158 private final int mDisplayId;
159
Wale Ogunwale3a931692016-11-02 16:49:48 -0700160 /** The containers below are the only child containers the display can have. */
161 // Contains all window containers that are related to apps (Activities)
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700162 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers();
Wale Ogunwale3a931692016-11-02 16:49:48 -0700163 // Contains all non-app window containers that should be displayed above the app containers
164 // (e.g. Status bar)
165 private final NonAppWindowContainers mAboveAppWindowsContainers =
166 new NonAppWindowContainers("mAboveAppWindowsContainers");
167 // Contains all non-app window containers that should be displayed below the app containers
168 // (e.g. Wallpaper).
169 private final NonAppWindowContainers mBelowAppWindowsContainers =
170 new NonAppWindowContainers("mBelowAppWindowsContainers");
171 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
172 // on the IME target. We mainly have this container grouping so we can keep track of all the IME
173 // window containers together and move them in-sync if/when needed.
174 private final NonAppWindowContainers mImeWindowsContainers =
175 new NonAppWindowContainers("mImeWindowsContainers");
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700176
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000177 // Z-ordered (bottom-most first) list of all Window objects.
178 private final WindowList mWindows = new WindowList();
Craig Mautner59c00972012-07-30 12:10:24 -0700179
Wale Ogunwale02319a62016-09-26 15:21:22 -0700180 // Mapping from a token IBinder to a WindowToken object on this display.
181 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
182
Craig Mautner59c00972012-07-30 12:10:24 -0700183 int mInitialDisplayWidth = 0;
184 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700185 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -0700186 int mBaseDisplayWidth = 0;
187 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700188 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700189 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700190 private final DisplayInfo mDisplayInfo = new DisplayInfo();
191 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700192 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -0700193
Craig Mautner6601b7b2013-04-29 10:29:11 -0700194 Rect mBaseDisplayRect = new Rect();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700195 private Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700196
Craig Mautner39834192012-09-02 07:47:24 -0700197 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700198 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700199 int pendingLayoutChanges;
Andrii Kulian839def92016-11-02 10:58:58 -0700200 // TODO(multi-display): remove some of the usages.
Craig Mautner69b08182012-09-05 13:07:13 -0700201 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700202
Craig Mautnerdc548482014-02-05 13:35:24 -0800203 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700204 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800205
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800206 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
207 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -0700208 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700209
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700210 /** Detect user tapping outside of current focused task bounds .*/
211 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700212
Craig Mautner6601b7b2013-04-29 10:29:11 -0700213 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700214 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700215
Craig Mautner6601b7b2013-04-29 10:29:11 -0700216 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800217 private final Rect mTmpRect = new Rect();
218 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700219 private final RectF mTmpRectF = new RectF();
220 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800221 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700222
Craig Mautner9d808b12013-08-06 18:00:25 -0700223 final WindowManagerService mService;
224
Craig Mautner95da1082014-02-24 17:54:35 -0800225 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700226 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800227
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700228 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700229 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700230
Chong Zhang112eb8c2015-11-02 11:17:00 -0800231 final DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700232
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800233 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
234
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000235 /** Used when rebuilding window list to keep track of windows that have been removed. */
236 private WindowState[] mRebuildTmp = new WindowState[20];
237
238 /**
239 * Temporary list for comparison. Always clear this after use so we don't end up with
240 * orphaned windows references
241 */
242 private final ArrayList<WindowState> mTmpWindows = new ArrayList<>();
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700243
244 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
245
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700246 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
247 new TaskForResizePointSearchResult();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000248 private final GetWindowOnDisplaySearchResult mTmpGetWindowOnDisplaySearchResult =
249 new GetWindowOnDisplaySearchResult();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700250
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700251 // True if this display is in the process of being removed. Used to determine if the removal of
252 // the display's direct children should be allowed.
253 private boolean mRemovingDisplay = false;
254
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700255 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700256 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700257 int mInputMethodAnimLayerAdjustment;
258
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800259 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700260 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800261 * @param service You know.
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700262 * @param layersController window layer controller used to assign layer to the windows on this
263 * display.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700264 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
265 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700266 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700267 DisplayContent(Display display, WindowManagerService service,
Wale Ogunwale0303c572016-10-20 10:16:29 -0700268 WindowLayersController layersController, WallpaperController wallpaperController) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700269 mDisplay = display;
270 mDisplayId = display.getDisplayId();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700271 mLayersController = layersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700272 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700273 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700274 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700275 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700276 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700277 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800278 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700279 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800280 mDimLayerController = new DimLayerController(this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700281
282 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700283 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700284 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700285 super.addChild(mAboveAppWindowsContainers, null);
286 super.addChild(mImeWindowsContainers, null);
Craig Mautner59c00972012-07-30 12:10:24 -0700287 }
288
289 int getDisplayId() {
290 return mDisplayId;
291 }
292
Wale Ogunwale02319a62016-09-26 15:21:22 -0700293 WindowToken getWindowToken(IBinder binder) {
294 return mTokenMap.get(binder);
295 }
296
297 AppWindowToken getAppWindowToken(IBinder binder) {
298 final WindowToken token = getWindowToken(binder);
299 if (token == null) {
300 return null;
301 }
302 return token.asAppWindowToken();
303 }
304
305 void setWindowToken(IBinder binder, WindowToken token) {
306 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
307 if (dc != null) {
308 // We currently don't support adding a window token to the display if the display
309 // already has the binder mapped to another token. If there is a use case for supporting
310 // this moving forward we will either need to merge the WindowTokens some how or have
311 // the binder map to a list of window tokens.
312 throw new IllegalArgumentException("Can't map token=" + token + " to display=" + this
313 + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
314 }
315 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700316
317 if (token.asAppWindowToken() == null) {
318 // Add non-app token to container hierarchy on the display. App tokens are added through
319 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700320 switch (token.windowType) {
321 case TYPE_WALLPAPER:
322 mBelowAppWindowsContainers.addChild(token);
323 break;
324 case TYPE_INPUT_METHOD:
325 case TYPE_INPUT_METHOD_DIALOG:
326 mImeWindowsContainers.addChild(token);
327 break;
328 default:
329 mAboveAppWindowsContainers.addChild(token);
330 break;
331 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700332 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700333 }
334
335 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700336 final WindowToken token = mTokenMap.remove(binder);
337 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3a931692016-11-02 16:49:48 -0700338 switch (token.windowType) {
339 case TYPE_WALLPAPER:
340 mBelowAppWindowsContainers.removeChild(token);
341 break;
342 case TYPE_INPUT_METHOD:
343 case TYPE_INPUT_METHOD_DIALOG:
344 mImeWindowsContainers.removeChild(token);
345 break;
346 default:
347 mAboveAppWindowsContainers.removeChild(token);
348 break;
349 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700350 }
351 return token;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700352 }
353
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700354 void removeAppToken(IBinder binder) {
355 final WindowToken token = removeWindowToken(binder);
356 if (token == null) {
357 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
358 return;
359 }
360
361 final AppWindowToken appToken = token.asAppWindowToken();
362
363 if (appToken == null) {
364 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
365 return;
366 }
367
368 appToken.onRemovedFromDisplay();
369 }
370
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700371 Display getDisplay() {
372 return mDisplay;
373 }
374
Craig Mautner59c00972012-07-30 12:10:24 -0700375 DisplayInfo getDisplayInfo() {
376 return mDisplayInfo;
377 }
378
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700379 DisplayMetrics getDisplayMetrics() {
380 return mDisplayMetrics;
381 }
382
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100383 DockedStackDividerController getDockedDividerController() {
384 return mDividerControllerLocked;
385 }
386
Winson Chung655332c2016-10-31 13:14:28 -0700387 PinnedStackController getPinnedStackController() {
388 return mPinnedStackControllerLocked;
389 }
390
Jeff Browna506a6e2013-06-04 00:02:38 -0700391 /**
392 * Returns true if the specified UID has access to this display.
393 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700394 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700395 return mDisplay.hasAccess(uid);
396 }
397
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700398 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700399 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -0700400 }
401
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700402 TaskStack getHomeStack() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700403 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800404 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
Craig Mautnere0a38842013-12-16 16:14:02 -0800405 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700406 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700407 }
408
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700409 TaskStack getStackById(int stackId) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700410 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
411 final TaskStack stack = mTaskStackContainers.get(i);
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700412 if (stack.mStackId == stackId) {
413 return stack;
414 }
415 }
416 return null;
417 }
418
Andrii Kulian441e4492016-09-29 15:25:00 -0700419 @Override
420 void onConfigurationChanged(Configuration newParentConfig) {
421 super.onConfigurationChanged(newParentConfig);
422
Andrii Kulian3a507b52016-09-19 18:14:12 -0700423 // The display size information is heavily dependent on the resources in the current
424 // configuration, so we need to reconfigure it every time the configuration changes.
425 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
426 mService.reconfigureDisplayLocked(this);
427
428 getDockedDividerController().onConfigurationChanged();
Winson Chung655332c2016-10-31 13:14:28 -0700429 getPinnedStackController().onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700430 }
Andrii Kulian3a507b52016-09-19 18:14:12 -0700431
Andrii Kulian441e4492016-09-29 15:25:00 -0700432 /**
433 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
434 * bounds were updated.
435 */
436 void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700437 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
438 final TaskStack stack = mTaskStackContainers.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700439 if (stack.updateBoundsAfterConfigChange()) {
Andrii Kulian3a507b52016-09-19 18:14:12 -0700440 changedStackList.add(stack.mStackId);
441 }
442 }
443 }
444
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700445 @Override
446 boolean fillsParent() {
447 return true;
448 }
449
450 @Override
451 boolean isVisible() {
452 return true;
453 }
454
455 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700456 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700457 super.onAppTransitionDone();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000458 rebuildAppWindowList();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700459 }
460
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700461 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -0700462 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700463 final WindowManagerPolicy policy = mService.mPolicy;
464
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000465 // TODO: All the logic before the last return statement in this method should really go in
466 // #NonAppWindowContainer.getOrientation() since it is trying to decide orientation based
467 // on non-app windows. But, we can not do that until the window list is always correct in
468 // terms of z-ordering based on layers.
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700469 if (mService.mDisplayFrozen) {
470 if (mService.mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
471 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
472 "Display is frozen, return " + mService.mLastWindowForcedOrientation);
473 // If the display is frozen, some activities may be in the middle of restarting, and
474 // thus have removed their old window. If the window has the flag to hide the lock
475 // screen, then the lock screen can re-appear and inflict its own orientation on us.
476 // Keep the orientation stable until this all settles down.
477 return mService.mLastWindowForcedOrientation;
478 } else if (policy.isKeyguardLocked()) {
479 // Use the last orientation the while the display is frozen with the keyguard
480 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
481 // window. We don't want to check the show when locked window directly though as
482 // things aren't stable while the display is frozen, for example the window could be
483 // momentarily unavailable due to activity relaunch.
484 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
485 + "return " + mService.mLastOrientation);
486 return mService.mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -0700487 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700488 } else {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000489 for (int pos = mWindows.size() - 1; pos >= 0; --pos) {
490 final WindowState win = mWindows.get(pos);
491 if (win.mAppToken != null) {
492 // We hit an application window. so the orientation will be determined by the
493 // app window. No point in continuing further.
494 break;
495 }
496 if (!win.isVisibleLw() || !win.mPolicyVisibilityAfterAnim) {
497 continue;
498 }
499 int req = win.mAttrs.screenOrientation;
500 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND) {
501 continue;
502 }
503
504 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
505 if (policy.isKeyguardHostWindow(win.mAttrs)) {
506 mService.mLastKeyguardForcedOrientation = req;
507 }
508 return (mService.mLastWindowForcedOrientation = req);
509 }
510 mService.mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
511
512 if (policy.isKeyguardShowingAndNotOccluded()) {
513 return mService.mLastKeyguardForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700514 }
Wale Ogunwale51362492016-09-08 17:49:17 -0700515 }
516
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700517 // Top system windows are not requesting an orientation. Start searching from apps.
518 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -0700519 }
520
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700521 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700522 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700523 mDisplay.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700524 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
525 mTaskStackContainers.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800526 }
Craig Mautner722285e2012-09-07 13:55:58 -0700527 }
528
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700529 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700530 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
531 if (displayManagerInternal != null) {
532 // Bootstrap the default logical display from the display manager.
533 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
534 if (newDisplayInfo != null) {
535 mDisplayInfo.copyFrom(newDisplayInfo);
536 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700537 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700538
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800539 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
540 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
541 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
542 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700543 }
544
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700545 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700546 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800547 final int orientation = mDisplayInfo.rotation;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700548 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
Craig Mautner4a1cb222013-12-04 16:14:06 -0800549 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
550 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700551 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800552 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700553 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800554 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700555 out.set(left, top, left + width, top + height);
556 }
557
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700558 private void getLogicalDisplayRect(Rect out, int orientation) {
559 getLogicalDisplayRect(out);
560
561 // Rotate the Rect if needed.
562 final int currentRotation = mDisplayInfo.rotation;
563 final int rotationDelta = deltaRotation(currentRotation, orientation);
564 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
565 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
566 mTmpRectF.set(out);
567 mTmpMatrix.mapRect(mTmpRectF);
568 mTmpRectF.round(out);
569 }
570 }
571
Chong Zhangf66db432016-01-13 10:39:51 -0800572 void getContentRect(Rect out) {
573 out.set(mContentRect);
574 }
575
Andrii Kulian839def92016-11-02 10:58:58 -0700576 /**
577 * Adds the stack to this display.
578 * @see WindowManagerService#addStackToDisplay(int, int, boolean)
579 */
580 Rect addStackToDisplay(int stackId, boolean onTop) {
581 boolean attachedToDisplay = false;
582 TaskStack stack = mService.mStackIdToStack.get(stackId);
583 if (stack == null) {
584 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
585 + mDisplayId);
586
587 stack = getStackById(stackId);
588 if (stack != null) {
589 // It's already attached to the display...clear mDeferRemoval and move stack to
590 // appropriate z-order on display as needed.
591 stack.mDeferRemoval = false;
592 moveStack(stack, onTop);
593 attachedToDisplay = true;
594 } else {
595 stack = new TaskStack(mService, stackId);
596 }
597
598 mService.mStackIdToStack.put(stackId, stack);
599 if (stackId == DOCKED_STACK_ID) {
600 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
601 }
602 } else {
603 final DisplayContent currentDC = stack.getDisplayContent();
604 if (currentDC != null) {
605 throw new IllegalStateException("Trying to add stackId=" + stackId
606 + "to displayId=" + mDisplayId + ", but it's already attached to displayId="
607 + currentDC.getDisplayId());
608 }
609 }
610
611 if (!attachedToDisplay) {
612 mTaskStackContainers.addStackToDisplay(stack, onTop);
613 }
614
615 if (stack.getRawFullscreen()) {
616 return null;
617 }
618 final Rect bounds = new Rect();
619 stack.getRawBounds(bounds);
620 return bounds;
621 }
622
623 /** Removes the stack from the display and prepares for changing the parent. */
624 private void removeStackFromDisplay(TaskStack stack) {
625 mTaskStackContainers.removeStackFromDisplay(stack);
626 }
627
628 /** Moves the stack to this display and returns the updated bounds. */
629 Rect moveStackToDisplay(TaskStack stack) {
630 final DisplayContent currentDisplayContent = stack.getDisplayContent();
631 if (currentDisplayContent == null) {
632 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
633 + " which is not currently attached to any display");
634 }
635 if (stack.getDisplayContent().getDisplayId() == mDisplayId) {
636 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
637 + " to its current displayId=" + mDisplayId);
638 }
639
640 currentDisplayContent.removeStackFromDisplay(stack);
641 return addStackToDisplay(stack.mStackId, true /* onTop */);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800642 }
643
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800644 void moveStack(TaskStack stack, boolean toTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700645 mTaskStackContainers.moveStack(stack, toTop);
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700646 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700647
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700648 @Override
649 protected void addChild(DisplayChildWindowContainer child,
650 Comparator<DisplayChildWindowContainer> comparator) {
651 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
652 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700653
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700654 @Override
655 protected void addChild(DisplayChildWindowContainer child, int index) {
656 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
657 }
658
659 @Override
660 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700661 // Only allow removal of direct children from this display if the display is in the process
662 // of been removed.
663 if (mRemovingDisplay) {
664 super.removeChild(child);
665 return;
666 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700667 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800668 }
669
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700670 int taskIdFromPoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700671 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
672 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700673 final int taskId = stack.taskIdFromPoint(x, y);
674 if (taskId != -1) {
675 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -0700676 }
677 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800678 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700679 }
680
Chong Zhang8e89b312015-09-09 15:09:30 -0700681 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -0800682 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -0700683 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700684 */
Wale Ogunwale15ead902016-09-02 14:30:11 -0700685 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700686 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700687 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700688 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
689 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -0700690 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700691 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700692 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700693
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700694 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
695 if (mTmpTaskForResizePointSearchResult.searchDone) {
696 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -0700697 }
698 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700699 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700700 }
701
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700702 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700703 mTouchExcludeRegion.set(mBaseDisplayRect);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700704 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700705 mTmpRect2.setEmpty();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700706 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
707 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700708 stack.setTouchExcludeRegion(
709 focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2);
Craig Mautner6601b7b2013-04-29 10:29:11 -0700710 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800711 // If we removed the focused task above, add it back and only leave its
712 // outside touch area in the exclusion. TapDectector is not interested in
713 // any touch inside the focused task itself.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700714 if (!mTmpRect2.isEmpty()) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800715 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
716 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800717 final WindowState inputMethod = mService.mInputMethodWindow;
718 if (inputMethod != null && inputMethod.isVisibleLw()) {
719 // If the input method is visible and the user is typing, we don't want these touch
720 // events to be intercepted and used to change focus. This would likely cause a
721 // disappearance of the input method.
722 inputMethod.getTouchableRegion(mTmpRegion);
723 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
724 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800725 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
726 WindowState win = mTapExcludedWindows.get(i);
727 win.getTouchableRegion(mTmpRegion);
728 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
729 }
Andrii Kulian03c403d2016-11-11 11:14:12 -0800730 // TODO(multi-display): Support docked stacks on secondary displays.
731 if (mDisplayId == DEFAULT_DISPLAY && getDockedStackLocked() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100732 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -0700733 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100734 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
735 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800736 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700737 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -0800738 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700739 }
740
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700741 void switchUser() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000742 final int count = mWindows.size();
743 for (int i = 0; i < count; i++) {
744 final WindowState win = mWindows.get(i);
745 if (win.isHiddenFromUserLocked()) {
746 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win
747 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
748 win.hideLw(false);
749 }
750 }
751
752 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
753 mTaskStackContainers.get(stackNdx).switchUser();
754 }
755
756 rebuildAppWindowList();
Craig Mautner858d8a62013-04-23 17:08:34 -0700757 }
758
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700759 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700760 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
761 mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700762 }
763 }
764
765 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800766 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700767 }
768
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700769 private void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800770 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700771 }
772
773 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800774 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700775 }
776
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700777 private void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800778 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700779 }
780
Wale Ogunwale10124582016-09-15 20:25:50 -0700781 @Override
782 void removeIfPossible() {
783 if (isAnimating()) {
784 mDeferredRemoval = true;
785 return;
Craig Mautner2eb15342013-08-07 13:13:35 -0700786 }
Wale Ogunwale10124582016-09-15 20:25:50 -0700787 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -0700788 }
789
Wale Ogunwale10124582016-09-15 20:25:50 -0700790 @Override
791 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700792 mRemovingDisplay = true;
793 try {
794 super.removeImmediately();
795 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
796 mDimLayerController.close();
797 if (mDisplayId == DEFAULT_DISPLAY) {
798 mService.unregisterPointerEventListener(mTapDetector);
799 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
800 }
801 } finally {
802 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -0800803 }
Craig Mautner95da1082014-02-24 17:54:35 -0800804 }
805
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700806 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -0700807 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700808 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700809 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
810
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700811 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -0700812 removeImmediately();
Craig Mautner95da1082014-02-24 17:54:35 -0800813 mService.onDisplayRemoved(mDisplayId);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700814 return false;
Craig Mautner95da1082014-02-24 17:54:35 -0800815 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700816 return true;
Craig Mautner95da1082014-02-24 17:54:35 -0800817 }
818
Wale Ogunwale10124582016-09-15 20:25:50 -0700819 boolean animateForIme(float interpolatedValue, float animationTarget,
820 float dividerAnimationTarget) {
821 boolean updated = false;
822
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700823 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
824 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700825 if (stack == null || !stack.isAdjustedForIme()) {
826 continue;
827 }
828
829 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
830 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
831 updated = true;
832 } else {
833 mDividerControllerLocked.mLastAnimationProgress =
834 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
835 mDividerControllerLocked.mLastDividerProgress =
836 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
837 updated |= stack.updateAdjustForIme(
838 mDividerControllerLocked.mLastAnimationProgress,
839 mDividerControllerLocked.mLastDividerProgress,
840 false /* force */);
841 }
842 if (interpolatedValue >= 1f) {
843 stack.endImeAdjustAnimation();
844 }
845 }
846
847 return updated;
848 }
849
850 boolean clearImeAdjustAnimation() {
851 boolean changed = false;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700852 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
853 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700854 if (stack != null && stack.isAdjustedForIme()) {
855 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
856 changed = true;
857 }
858 }
859 return changed;
860 }
861
862 void beginImeAdjustAnimation() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700863 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
864 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700865 if (stack.isVisible() && stack.isAdjustedForIme()) {
866 stack.beginImeAdjustAnimation();
867 }
868 }
869 }
870
871 void adjustForImeIfNeeded() {
872 final WindowState imeWin = mService.mInputMethodWindow;
873 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
874 && !mDividerControllerLocked.isImeHideRequested();
875 final boolean dockVisible = mService.isStackVisibleLocked(DOCKED_STACK_ID);
876 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
877 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
878 imeTargetStack.getDockSide() : DOCKED_INVALID;
879 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
880 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
881 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
882 final int imeHeight = mService.mPolicy.getInputMethodWindowVisibleHeightLw();
883 final boolean imeHeightChanged = imeVisible &&
884 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
885
886 // The divider could be adjusted for IME position, or be thinner than usual,
887 // or both. There are three possible cases:
888 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
889 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
890 // - If IME is not visible, divider is not moved and is normal width.
891
892 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700893 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
894 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700895 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
896 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)) {
897 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
898 } else {
899 stack.resetAdjustedForIme(false);
900 }
901 }
902 mDividerControllerLocked.setAdjustedForIme(
903 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
904 } else {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700905 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
906 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700907 stack.resetAdjustedForIme(!dockVisible);
908 }
909 mDividerControllerLocked.setAdjustedForIme(
910 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
911 }
Winson Chung655332c2016-10-31 13:14:28 -0700912 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -0700913 }
914
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700915 void setInputMethodAnimLayerAdjustment(int adj) {
916 if (DEBUG_LAYERS) Slog.v(TAG_WM, "Setting im layer adj to " + adj);
917 mInputMethodAnimLayerAdjustment = adj;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000918 final WindowState imw = mService.mInputMethodWindow;
919 if (imw != null) {
920 imw.adjustAnimLayer(adj);
921 }
922 for (int i = mService.mInputMethodDialogs.size() - 1; i >= 0; i--) {
923 final WindowState dialog = mService.mInputMethodDialogs.get(i);
924 // TODO: This and other places setting mAnimLayer can probably use WS.adjustAnimLayer,
925 // but need to make sure we are not setting things twice for child windows that are
926 // already in the list.
927 dialog.mWinAnimator.mAnimLayer = dialog.mLayer + adj;
928 if (DEBUG_LAYERS) Slog.v(TAG_WM, "IM win " + imw
929 + " anim layer: " + dialog.mWinAnimator.mAnimLayer);
930 }
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700931 }
932
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700933 /**
934 * If a window that has an animation specifying a colored background and the current wallpaper
935 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
936 * suddenly disappear.
937 */
938 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000939 for (int i = mWindows.size() - 1; i >= 0; --i) {
940 final WindowState win = mWindows.get(i);
941 if (win.mIsWallpaper && win.isVisibleNow()) {
942 return win.mWinAnimator.mAnimLayer;
943 }
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700944 }
945 return winAnimator.mAnimLayer;
946 }
947
Wale Ogunwale10124582016-09-15 20:25:50 -0700948 void prepareFreezingTaskBounds() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700949 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
950 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -0700951 stack.prepareFreezingTaskBounds();
952 }
953 }
954
Wale Ogunwale94744212015-09-21 19:01:47 -0700955 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700956 getLogicalDisplayRect(mTmpRect, newRotation);
957
958 // Compute a transform matrix to undo the coordinate space transformation,
959 // and present the window at the same physical position it previously occupied.
960 final int deltaRotation = deltaRotation(newRotation, oldRotation);
961 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
962
963 mTmpRectF.set(bounds);
964 mTmpMatrix.mapRect(mTmpRectF);
965 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -0700966 }
967
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800968 static int deltaRotation(int oldRotation, int newRotation) {
969 int delta = newRotation - oldRotation;
970 if (delta < 0) delta += 4;
971 return delta;
972 }
973
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700974 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700975 Matrix outMatrix) {
976 // For rotations without Z-ordering we don't need the target rectangle's position.
977 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
978 displayHeight, outMatrix);
979 }
980
981 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
982 float displayWidth, float displayHeight, Matrix outMatrix) {
983 switch (rotation) {
984 case ROTATION_0:
985 outMatrix.reset();
986 break;
987 case ROTATION_270:
988 outMatrix.setRotate(270, 0, 0);
989 outMatrix.postTranslate(0, displayHeight);
990 outMatrix.postTranslate(rectTop, 0);
991 break;
992 case ROTATION_180:
993 outMatrix.reset();
994 break;
995 case ROTATION_90:
996 outMatrix.setRotate(90, 0, 0);
997 outMatrix.postTranslate(displayWidth, 0);
998 outMatrix.postTranslate(-rectTop, rectLeft);
999 break;
1000 }
1001 }
1002
Craig Mautnera91f9e22012-09-14 16:22:08 -07001003 public void dump(String prefix, PrintWriter pw) {
1004 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
1005 final String subPrefix = " " + prefix;
1006 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
1007 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
1008 pw.print("dpi");
1009 if (mInitialDisplayWidth != mBaseDisplayWidth
1010 || mInitialDisplayHeight != mBaseDisplayHeight
1011 || mInitialDisplayDensity != mBaseDisplayDensity) {
1012 pw.print(" base=");
1013 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
1014 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
1015 }
Jeff Brownd46747a2015-04-15 19:02:36 -07001016 if (mDisplayScalingDisabled) {
1017 pw.println(" noscale");
1018 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07001019 pw.print(" cur=");
1020 pw.print(mDisplayInfo.logicalWidth);
1021 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
1022 pw.print(" app=");
1023 pw.print(mDisplayInfo.appWidth);
1024 pw.print("x"); pw.print(mDisplayInfo.appHeight);
1025 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
1026 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
1027 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
1028 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001029 pw.println(subPrefix + "deferred=" + mDeferredRemoval
1030 + " mLayoutNeeded=" + mLayoutNeeded);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001031
Craig Mautnerdc548482014-02-05 13:35:24 -08001032 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001033 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001034 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1035 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001036 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001037 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001038
Craig Mautnerdc548482014-02-05 13:35:24 -08001039 pw.println();
1040 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07001041 pw.println();
1042 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001043 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001044 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001045 pw.print(" Exiting #"); pw.print(i);
1046 pw.print(' '); pw.print(token);
1047 pw.println(':');
1048 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08001049 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07001050 }
Craig Mautner59c00972012-07-30 12:10:24 -07001051 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001052 mDimLayerController.dump(prefix, pw);
Jorim Jaggi31f71702016-05-04 16:43:04 -07001053 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001054 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07001055 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001056 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001057
1058 if (mInputMethodAnimLayerAdjustment != 0) {
1059 pw.println(subPrefix
1060 + "mInputMethodAnimLayerAdjustment=" + mInputMethodAnimLayerAdjustment);
1061 }
Craig Mautner59c00972012-07-30 12:10:24 -07001062 }
Craig Mautnere0a38842013-12-16 16:14:02 -08001063
1064 @Override
1065 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001066 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001067 }
1068
1069 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001070 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08001071 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001072
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001073 /**
1074 * @return The docked stack, but only if it is visible, and {@code null} otherwise.
1075 */
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001076 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -07001077 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001078 return (stack != null && stack.isVisible()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001079 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001080
1081 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001082 * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not
Jorim Jaggife762342016-10-13 14:33:27 +02001083 * visible.
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001084 */
Jorim Jaggife762342016-10-13 14:33:27 +02001085 TaskStack getDockedStackIgnoringVisibility() {
1086 return mService.mStackIdToStack.get(DOCKED_STACK_ID);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001087 }
1088
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001089 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001090 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001091 WindowState touchedWin = null;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001092 final int x = (int) xf;
1093 final int y = (int) yf;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001094
1095 for (int i = mWindows.size() - 1; i >= 0; i--) {
1096 WindowState window = mWindows.get(i);
1097 final int flags = window.mAttrs.flags;
1098 if (!window.isVisibleLw()) {
1099 continue;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001100 }
1101 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001102 continue;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001103 }
1104
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001105 window.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001106 if (!mTmpRect.contains(x, y)) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001107 continue;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001108 }
1109
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001110 window.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001111
1112 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001113 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
1114 touchedWin = window;
1115 break;
1116 }
1117 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001118
1119 return touchedWin;
1120 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07001121
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001122 boolean canAddToastWindowForUid(int uid) {
1123 // We allow one toast window per UID being shown at a time.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001124 final int windowCount = mWindows.size();
1125 for (int i = 0; i < windowCount; i++) {
1126 final WindowState window = mWindows.get(i);
1127 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == uid
1128 && !window.mPermanentlyHidden && !window.mWindowRemovalAllowed) {
1129 return false;
1130 }
1131 }
1132 return true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001133 }
1134
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001135 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001136 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
1137 return;
1138 }
1139 final int lostFocusUid = oldFocus.mOwnerUid;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001140 final int windowCount = mWindows.size();
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001141 final Handler handler = mService.mH;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001142 for (int i = 0; i < windowCount; i++) {
1143 final WindowState window = mWindows.get(i);
1144 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == lostFocusUid) {
1145 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, window)) {
1146 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, window),
1147 window.mAttrs.hideTimeoutMilliseconds);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001148 }
1149 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001150 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001151 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001152
1153 WindowState findFocusedWindow() {
1154 final AppWindowToken focusedApp = mService.mFocusedApp;
1155
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001156 for (int i = mWindows.size() - 1; i >= 0; i--) {
1157 final WindowState win = mWindows.get(i);
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001158
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001159 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + i + " = " + win
1160 + ", flags=" + win.mAttrs.flags + ", canReceive=" + win.canReceiveKeys());
1161
1162 if (!win.canReceiveKeys()) {
1163 continue;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001164 }
1165
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001166 final AppWindowToken wtoken = win.mAppToken;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001167
1168 // If this window's application has been removed, just skip it.
1169 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
1170 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
1171 + (wtoken.removed ? "removed" : "sendingToBottom"));
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001172 continue;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001173 }
1174
1175 if (focusedApp == null) {
1176 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001177 + " using new focus @ " + i + " = " + win);
1178 return win;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001179 }
1180
1181 if (!focusedApp.windowsAreFocusable()) {
1182 // Current focused app windows aren't focusable...
1183 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001184 + " focusable using new focus @ " + i + " = " + win);
1185 return win;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001186 }
1187
1188 // Descend through all of the app tokens and find the first that either matches
1189 // win.mAppToken (return win) or mFocusedApp (return null).
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001190 if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001191 if (focusedApp.compareTo(wtoken) > 0) {
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001192 // App stack below focused app stack. No focus for you!!!
1193 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
1194 "findFocusedWindow: Reached focused app=" + focusedApp);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001195 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001196 }
1197 }
1198
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001199 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ "
1200 + i + " = " + win);
1201 return win;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001202 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001203
1204 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
1205 return null;
1206 }
1207
1208 void addAppWindowToWindowList(final WindowState win) {
1209 final IWindow client = win.mClient;
1210
1211 WindowList tokenWindowList = getTokenWindowsOnDisplay(win.mToken);
1212 if (!tokenWindowList.isEmpty()) {
1213 addAppWindowExisting(win, tokenWindowList);
1214 return;
1215 }
1216
1217 // No windows from this token on this display
1218 if (localLOGV) Slog.v(TAG_WM, "Figuring out where to add app window "
1219 + client.asBinder() + " (token=" + this + ")");
1220
1221 final WindowToken wToken = win.mToken;
1222
1223 // Figure out where the window should go, based on the order of applications.
1224 mTmpGetWindowOnDisplaySearchResult.reset();
1225 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1226 final TaskStack stack = mTaskStackContainers.get(i);
1227 stack.getWindowOnDisplayBeforeToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
1228 if (mTmpGetWindowOnDisplaySearchResult.reachedToken) {
1229 // We have reach the token we are interested in. End search.
1230 break;
1231 }
1232 }
1233
1234 WindowState pos = mTmpGetWindowOnDisplaySearchResult.foundWindow;
1235
1236 // We now know the index into the apps. If we found an app window above, that gives us the
1237 // position; else we need to look some more.
1238 if (pos != null) {
1239 // Move behind any windows attached to this one.
1240 final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
1241 if (atoken != null) {
1242 tokenWindowList = getTokenWindowsOnDisplay(atoken);
1243 final int NC = tokenWindowList.size();
1244 if (NC > 0) {
1245 WindowState bottom = tokenWindowList.get(0);
1246 if (bottom.mSubLayer < 0) {
1247 pos = bottom;
1248 }
1249 }
1250 }
1251 addWindowToListBefore(win, pos);
1252 return;
1253 }
1254
1255 // Continue looking down until we find the first token that has windows on this display.
1256 mTmpGetWindowOnDisplaySearchResult.reset();
1257 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1258 final TaskStack stack = mTaskStackContainers.get(i);
1259 stack.getWindowOnDisplayAfterToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
1260 if (mTmpGetWindowOnDisplaySearchResult.foundWindow != null) {
1261 // We have found a window after the token. End search.
1262 break;
1263 }
1264 }
1265
1266 pos = mTmpGetWindowOnDisplaySearchResult.foundWindow;
1267
1268 if (pos != null) {
1269 // Move in front of any windows attached to this one.
1270 final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
1271 if (atoken != null) {
1272 final WindowState top = atoken.getTopWindow();
1273 if (top != null && top.mSubLayer >= 0) {
1274 pos = top;
1275 }
1276 }
1277 addWindowToListAfter(win, pos);
1278 return;
1279 }
1280
1281 // Just search for the start of this layer.
1282 final int myLayer = win.mBaseLayer;
1283 int i;
1284 for (i = mWindows.size() - 1; i >= 0; --i) {
1285 final WindowState w = mWindows.get(i);
1286 // Dock divider shares the base layer with application windows, but we want to always
1287 // keep it above the application windows. The sharing of the base layer is intended
1288 // for window animations, which need to be above the dock divider for the duration
1289 // of the animation.
1290 if (w.mBaseLayer <= myLayer && w.mAttrs.type != TYPE_DOCK_DIVIDER) {
1291 break;
1292 }
1293 }
1294 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1295 "Based on layer: Adding window " + win + " at " + (i + 1) + " of "
1296 + mWindows.size());
1297 mWindows.add(i + 1, win);
1298 mService.mWindowsChanged = true;
1299 }
1300
1301 /** Adds this non-app window to the window list. */
1302 void addNonAppWindowToWindowList(WindowState win) {
1303 // Figure out where window should go, based on layer.
1304 int i;
1305 for (i = mWindows.size() - 1; i >= 0; i--) {
1306 final WindowState otherWin = mWindows.get(i);
1307 if (otherWin.getBaseType() != TYPE_WALLPAPER && otherWin.mBaseLayer <= win.mBaseLayer) {
1308 // Wallpaper wanders through the window list, for example to position itself
1309 // directly behind keyguard. Because of this it will break the ordering based on
1310 // WindowState.mBaseLayer. There might windows with higher mBaseLayer behind it and
1311 // we don't want the new window to appear above them. An example of this is adding
1312 // of the docked stack divider. Consider a scenario with the following ordering (top
1313 // to bottom): keyguard, wallpaper, assist preview, apps. We want the dock divider
1314 // to land below the assist preview, so the dock divider must ignore the wallpaper,
1315 // with which it shares the base layer.
1316 break;
1317 }
1318 }
1319
1320 i++;
1321 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1322 "Free window: Adding window " + this + " at " + i + " of " + mWindows.size());
1323 mWindows.add(i, win);
1324 mService.mWindowsChanged = true;
1325 }
1326
1327 void addToWindowList(WindowState win, int index) {
1328 mService.mWindowsChanged = true;
1329 mWindows.add(index, win);
1330 }
1331
1332 boolean removeFromWindowList(WindowState win) {
1333 mService.mWindowsChanged = true;
1334 return mWindows.remove(win);
1335 }
1336
1337 private int removeWindowAndChildrenFromWindowList(WindowState win, int interestingPos) {
1338 int wpos = mWindows.indexOf(win);
1339 if (wpos < 0) {
1340 return interestingPos;
1341 }
1342
1343 if (wpos < interestingPos) interestingPos--;
1344 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + this);
1345 mWindows.remove(wpos);
1346 mService.mWindowsChanged = true;
1347 int childWinCount = win.mChildren.size();
1348 while (childWinCount > 0) {
1349 childWinCount--;
1350 final WindowState cw = win.mChildren.get(childWinCount);
1351 int cpos = mWindows.indexOf(cw);
1352 if (cpos >= 0) {
1353 if (cpos < interestingPos) interestingPos--;
1354 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
1355 "Temp removing child at " + cpos + ": " + cw);
1356 mWindows.remove(cpos);
1357 }
1358 }
1359 return interestingPos;
1360 }
1361
1362 void addChildWindowToWindowList(WindowState win) {
1363 final WindowState parentWindow = win.getParentWindow();
1364
1365 WindowList windowsOnSameDisplay = getTokenWindowsOnDisplay(win.mToken);
1366
1367 // Figure out this window's ordering relative to the parent window.
1368 final int wCount = windowsOnSameDisplay.size();
1369 final int sublayer = win.mSubLayer;
1370 int largestSublayer = Integer.MIN_VALUE;
1371 WindowState windowWithLargestSublayer = null;
1372 int i;
1373 for (i = 0; i < wCount; i++) {
1374 WindowState w = windowsOnSameDisplay.get(i);
1375 final int wSublayer = w.mSubLayer;
1376 if (wSublayer >= largestSublayer) {
1377 largestSublayer = wSublayer;
1378 windowWithLargestSublayer = w;
1379 }
1380 if (sublayer < 0) {
1381 // For negative sublayers, we go below all windows in the same sublayer.
1382 if (wSublayer >= sublayer) {
1383 addWindowToListBefore(win, wSublayer >= 0 ? parentWindow : w);
1384 break;
1385 }
1386 } else {
1387 // For positive sublayers, we go above all windows in the same sublayer.
1388 if (wSublayer > sublayer) {
1389 addWindowToListBefore(win, w);
1390 break;
1391 }
1392 }
1393 }
1394 if (i >= wCount) {
1395 if (sublayer < 0) {
1396 addWindowToListBefore(win, parentWindow);
1397 } else {
1398 addWindowToListAfter(win,
1399 largestSublayer >= 0 ? windowWithLargestSublayer : parentWindow);
1400 }
1401 }
Wale Ogunwaleec731152016-09-08 20:18:57 -07001402 }
1403
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001404 /** Updates the layer assignment of windows on this display. */
1405 void assignWindowLayers(boolean setLayoutNeeded) {
Wale Ogunwaled1880962016-11-08 10:31:59 -08001406 mLayersController.assignWindowLayers(this);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001407 if (setLayoutNeeded) {
1408 setLayoutNeeded();
1409 }
1410 }
1411
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001412 void adjustWallpaperWindows() {
1413 mWallpaperController.adjustWallpaperWindows(this);
1414 }
1415
1416 /**
1417 * Z-orders the display window list so that:
1418 * <ul>
1419 * <li>Any windows that are currently below the wallpaper window stay below the wallpaper
1420 * window.
1421 * <li>Exiting application windows are at the bottom, but above the wallpaper window.
1422 * <li>All other application windows are above the exiting application windows and ordered based
1423 * on the ordering of their stacks and tasks on the display.
1424 * <li>Non-application windows are at the very top.
1425 * </ul>
1426 * <p>
1427 * NOTE: This isn't a complete picture of what the user see. Further manipulation of the window
1428 * surface layering is done in {@link WindowLayersController}.
1429 */
1430 void rebuildAppWindowList() {
1431 int count = mWindows.size();
1432 int i;
1433 int lastBelow = -1;
1434 int numRemoved = 0;
1435
1436 if (mRebuildTmp.length < count) {
1437 mRebuildTmp = new WindowState[count + 10];
1438 }
1439
1440 // First remove all existing app windows.
1441 i = 0;
1442 while (i < count) {
1443 final WindowState w = mWindows.get(i);
1444 if (w.mAppToken != null) {
1445 final WindowState win = mWindows.remove(i);
1446 win.mRebuilding = true;
1447 mRebuildTmp[numRemoved] = win;
1448 mService.mWindowsChanged = true;
1449 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Rebuild removing window: " + win);
1450 count--;
1451 numRemoved++;
1452 continue;
1453 } else if (lastBelow == i-1) {
1454 if (w.mAttrs.type == TYPE_WALLPAPER) {
1455 lastBelow = i;
1456 }
1457 }
1458 i++;
1459 }
1460
1461 // Keep whatever windows were below the app windows still below, by skipping them.
1462 lastBelow++;
1463 i = lastBelow;
1464
1465 // First add all of the exiting app tokens... these are no longer in the main app list,
1466 // but still have windows shown. We put them in the back because now that the animation is
1467 // over we no longer will care about them.
1468 final int numStacks = mTaskStackContainers.size();
1469 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
1470 AppTokenList exitingAppTokens = mTaskStackContainers.get(stackNdx).mExitingAppTokens;
1471 int NT = exitingAppTokens.size();
1472 for (int j = 0; j < NT; j++) {
1473 i = exitingAppTokens.get(j).rebuildWindowListUnchecked(i);
1474 }
1475 }
1476
1477 // And add in the still active app tokens in Z order.
1478 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
1479 i = mTaskStackContainers.get(stackNdx).rebuildWindowList(i);
1480 }
1481
1482 i -= lastBelow;
1483 if (i != numRemoved) {
1484 setLayoutNeeded();
1485 Slog.w(TAG_WM, "On display=" + mDisplayId + " Rebuild removed " + numRemoved
1486 + " windows but added " + i + " rebuildAppWindowListLocked() "
1487 + " callers=" + Debug.getCallers(10));
1488 for (i = 0; i < numRemoved; i++) {
1489 WindowState ws = mRebuildTmp[i];
1490 if (ws.mRebuilding) {
1491 StringWriter sw = new StringWriter();
1492 PrintWriter pw = new FastPrintWriter(sw, false, 1024);
1493 ws.dump(pw, "", true);
1494 pw.flush();
1495 Slog.w(TAG_WM, "This window was lost: " + ws);
1496 Slog.w(TAG_WM, sw.toString());
1497 ws.mWinAnimator.destroySurfaceLocked();
1498 }
1499 }
1500 Slog.w(TAG_WM, "Current window hierarchy:");
1501 dumpChildrenNames();
1502 Slog.w(TAG_WM, "Final window list:");
1503 dumpWindows();
1504 }
1505 Arrays.fill(mRebuildTmp, null);
1506 }
1507
1508 /** Rebuilds the display's window list and does a relayout if something changed. */
1509 void rebuildAppWindowsAndLayoutIfNeeded() {
1510 mTmpWindows.clear();
1511 mTmpWindows.addAll(mWindows);
1512
1513 rebuildAppWindowList();
1514
1515 // Set displayContent.mLayoutNeeded if window order changed.
1516 final int tmpSize = mTmpWindows.size();
1517 final int winSize = mWindows.size();
1518 int tmpNdx = 0, winNdx = 0;
1519 while (tmpNdx < tmpSize && winNdx < winSize) {
1520 // Skip over all exiting windows, they've been moved out of order.
1521 WindowState tmp;
1522 do {
1523 tmp = mTmpWindows.get(tmpNdx++);
1524 } while (tmpNdx < tmpSize && tmp.mAppToken != null && tmp.mAppToken.mIsExiting);
1525
1526 WindowState win;
1527 do {
1528 win = mWindows.get(winNdx++);
1529 } while (winNdx < winSize && win.mAppToken != null && win.mAppToken.mIsExiting);
1530
1531 if (tmp != win) {
1532 // Window order changed.
1533 setLayoutNeeded();
1534 break;
1535 }
1536 }
1537 if (tmpNdx != winNdx) {
1538 // One list was different from the other.
1539 setLayoutNeeded();
1540 }
1541 mTmpWindows.clear();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001542
1543 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
1544 false /*updateInputWindows*/)) {
1545 assignWindowLayers(false /* setLayoutNeeded */);
1546 }
1547
1548 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
1549 mService.mWindowPlacerLocked.performSurfacePlacement();
1550 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1551 }
1552
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001553 void updateInputWindows(InputMonitor inputMonitor, WindowState inputFocus, boolean inDrag) {
1554 final InputConsumerImpl navInputConsumer =
1555 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_NAVIGATION, mDisplayId);
1556 final InputConsumerImpl pipInputConsumer =
1557 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_PIP, mDisplayId);
1558 final InputConsumerImpl wallpaperInputConsumer =
1559 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_WALLPAPER, mDisplayId);
1560 boolean addInputConsumerHandle = navInputConsumer != null;
1561 boolean addPipInputConsumerHandle = pipInputConsumer != null;
1562 boolean addWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
1563 final Rect pipTouchableBounds = addPipInputConsumerHandle ? new Rect() : null;
1564 boolean disableWallpaperTouchEvents = false;
1565
1566 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
1567 final WindowState child = mWindows.get(winNdx);
1568 final InputChannel inputChannel = child.mInputChannel;
1569 final InputWindowHandle inputWindowHandle = child.mInputWindowHandle;
1570 if (inputChannel == null || inputWindowHandle == null || child.mRemoved
1571 || child.isAdjustedForMinimizedDock()) {
1572 // Skip this window because it cannot possibly receive input.
1573 continue;
1574 }
1575
1576 if (addPipInputConsumerHandle
1577 && child.getStackId() == PINNED_STACK_ID
1578 && inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer) {
1579 // Update the bounds of the Pip input consumer to match the Pinned stack
1580 child.getStack().getBounds(pipTouchableBounds);
1581 pipInputConsumer.mWindowHandle.touchableRegion.set(pipTouchableBounds);
1582 inputMonitor.addInputWindowHandle(pipInputConsumer.mWindowHandle);
1583 addPipInputConsumerHandle = false;
1584 }
1585
1586 if (addInputConsumerHandle
1587 && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) {
1588 inputMonitor.addInputWindowHandle(navInputConsumer.mWindowHandle);
1589 addInputConsumerHandle = false;
1590 }
1591
1592 if (addWallpaperInputConsumerHandle) {
1593 if (child.mAttrs.type == TYPE_WALLPAPER && child.isVisibleLw()) {
1594 // Add the wallpaper input consumer above the first visible wallpaper.
1595 inputMonitor.addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
1596 addWallpaperInputConsumerHandle = false;
1597 }
1598 }
1599
1600 final int flags = child.mAttrs.flags;
1601 final int privateFlags = child.mAttrs.privateFlags;
1602 final int type = child.mAttrs.type;
1603
1604 final boolean hasFocus = child == inputFocus;
1605 final boolean isVisible = child.isVisibleLw();
1606 if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
1607 disableWallpaperTouchEvents = true;
1608 }
1609 final boolean hasWallpaper = mWallpaperController.isWallpaperTarget(child)
1610 && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
1611 && !disableWallpaperTouchEvents;
1612
1613 // If there's a drag in progress and 'child' is a potential drop target,
1614 // make sure it's been told about the drag
1615 if (inDrag && isVisible && isDefaultDisplay) {
1616 mService.mDragState.sendDragStartedIfNeededLw(child);
1617 }
1618
1619 inputMonitor.addInputWindowHandle(
1620 inputWindowHandle, child, flags, type, isVisible, hasFocus, hasWallpaper);
1621 }
1622
1623 if (addWallpaperInputConsumerHandle) {
1624 // No visible wallpaper found, add the wallpaper input consumer at the end.
1625 inputMonitor.addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
1626 }
1627 }
1628
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001629 /** Returns true if a leaked surface was destroyed */
1630 boolean destroyLeakedSurfaces() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001631 boolean leakedSurface = false;
1632 final int numWindows = mWindows.size();
1633 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
1634 final WindowState ws = mWindows.get(winNdx);
1635 final WindowStateAnimator wsa = ws.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001636 if (wsa.mSurfaceController == null) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001637 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001638 }
1639 if (!mService.mSessions.contains(wsa.mSession)) {
1640 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001641 + ws + " surface=" + wsa.mSurfaceController
1642 + " token=" + ws.mToken
1643 + " pid=" + ws.mSession.mPid
1644 + " uid=" + ws.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001645 wsa.destroySurface();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001646 mService.mForceRemoves.add(ws);
1647 leakedSurface = true;
1648 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001649 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001650 + ws + " surface=" + wsa.mSurfaceController
1651 + " token=" + ws.mAppToken
1652 + " saved=" + ws.hasSavedSurface());
1653 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001654 wsa.destroySurface();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001655 leakedSurface = true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001656 }
1657 }
1658
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001659 return leakedSurface;
1660 }
1661
1662 /** Return the list of Windows on this display associated with the input token. */
1663 WindowList getTokenWindowsOnDisplay(WindowToken token) {
1664 final WindowList windowList = new WindowList();
1665 final int count = mWindows.size();
1666 for (int i = 0; i < count; i++) {
1667 final WindowState win = mWindows.get(i);
1668 if (win.mToken == token) {
1669 windowList.add(win);
1670 }
1671 }
1672 return windowList;
1673 }
1674
1675 private void reAddToWindowList(WindowState win) {
1676 win.mToken.addWindow(win);
1677 // This is a hack to get all of the child windows added as well at the right position. Child
1678 // windows should be rare and this case should be rare, so it shouldn't be that big a deal.
1679 int wpos = mWindows.indexOf(win);
1680 if (wpos >= 0) {
1681 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "ReAdd removing from " + wpos + ": " + win);
1682 mWindows.remove(wpos);
1683 mService.mWindowsChanged = true;
1684 win.reAddWindow(wpos);
1685 }
1686 }
1687
1688 void moveInputMethodDialogs(int pos) {
1689 ArrayList<WindowState> dialogs = mService.mInputMethodDialogs;
1690
1691 final int N = dialogs.size();
1692 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Removing " + N + " dialogs w/pos=" + pos);
1693 for (int i = 0; i < N; i++) {
1694 pos = removeWindowAndChildrenFromWindowList(dialogs.get(i), pos);
1695 }
1696 if (DEBUG_INPUT_METHOD) {
1697 Slog.v(TAG_WM, "Window list w/pos=" + pos);
1698 logWindowList(mWindows, " ");
1699 }
1700
1701 WindowState ime = mService.mInputMethodWindow;
1702 if (pos >= 0) {
1703 // Skip windows owned by the input method.
1704 if (ime != null) {
1705 while (pos < mWindows.size()) {
1706 WindowState wp = mWindows.get(pos);
1707 if (wp == ime || wp.getParentWindow() == ime) {
1708 pos++;
1709 continue;
1710 }
1711 break;
1712 }
1713 }
1714 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Adding " + N + " dialogs at pos=" + pos);
1715 for (int i=0; i<N; i++) {
1716 WindowState win = dialogs.get(i);
1717 pos = win.reAddWindow(pos);
1718 }
1719 if (DEBUG_INPUT_METHOD) {
1720 Slog.v(TAG_WM, "Final window list:");
1721 logWindowList(mWindows, " ");
1722 }
1723 return;
1724 }
1725 for (int i=0; i<N; i++) {
1726 WindowState win = dialogs.get(i);
1727 reAddToWindowList(win);
1728 if (DEBUG_INPUT_METHOD) {
1729 Slog.v(TAG_WM, "No IM target, final list:");
1730 logWindowList(mWindows, " ");
1731 }
1732 }
1733 }
1734
1735 boolean moveInputMethodWindowsIfNeeded(boolean needAssignLayers) {
1736 final WindowState imWin = mService.mInputMethodWindow;
1737 final int DN = mService.mInputMethodDialogs.size();
1738 if (imWin == null && DN == 0) {
1739 return false;
1740 }
1741
1742 // TODO(multidisplay): IMEs are only supported on the default display.
1743 int imPos = findDesiredInputMethodWindowIndex(true);
1744 if (imPos >= 0) {
1745 // In this case, the input method windows are to be placed
1746 // immediately above the window they are targeting.
1747
1748 // First check to see if the input method windows are already
1749 // located here, and contiguous.
1750 final int N = mWindows.size();
1751 final WindowState firstImWin = imPos < N ? mWindows.get(imPos) : null;
1752
1753 // Figure out the actual input method window that should be
1754 // at the bottom of their stack.
1755 WindowState baseImWin = imWin != null ? imWin : mService.mInputMethodDialogs.get(0);
1756 final WindowState cw = baseImWin.getBottomChild();
1757 if (cw != null && cw.mSubLayer < 0) {
1758 baseImWin = cw;
1759 }
1760
1761 if (firstImWin == baseImWin) {
1762 // The windows haven't moved... but are they still contiguous?
1763 // First find the top IM window.
1764 int pos = imPos+1;
1765 while (pos < N) {
1766 if (!(mWindows.get(pos)).mIsImWindow) {
1767 break;
1768 }
1769 pos++;
1770 }
1771 pos++;
1772 // Now there should be no more input method windows above.
1773 while (pos < N) {
1774 if ((mWindows.get(pos)).mIsImWindow) {
1775 break;
1776 }
1777 pos++;
1778 }
1779 if (pos >= N) {
1780 return false;
1781 }
1782 }
1783
1784 if (imWin != null) {
1785 if (DEBUG_INPUT_METHOD) {
1786 Slog.v(TAG_WM, "Moving IM from " + imPos);
1787 logWindowList(mWindows, " ");
1788 }
1789 imPos = removeWindowAndChildrenFromWindowList(imWin, imPos);
1790 if (DEBUG_INPUT_METHOD) {
1791 Slog.v(TAG_WM, "List after removing with new pos " + imPos + ":");
1792 logWindowList(mWindows, " ");
1793 }
1794 imWin.reAddWindow(imPos);
1795 if (DEBUG_INPUT_METHOD) {
1796 Slog.v(TAG_WM, "List after moving IM to " + imPos + ":");
1797 logWindowList(mWindows, " ");
1798 }
1799 if (DN > 0) moveInputMethodDialogs(imPos+1);
1800 } else {
1801 moveInputMethodDialogs(imPos);
1802 }
1803
1804 } else {
1805 // In this case, the input method windows go in a fixed layer,
1806 // because they aren't currently associated with a focus window.
1807
1808 if (imWin != null) {
1809 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Moving IM from " + imPos);
1810 removeWindowAndChildrenFromWindowList(imWin, 0);
1811 reAddToWindowList(imWin);
1812 if (DEBUG_INPUT_METHOD) {
1813 Slog.v(TAG_WM, "List with no IM target:");
1814 logWindowList(mWindows, " ");
1815 }
1816 if (DN > 0) moveInputMethodDialogs(-1);
1817 } else {
1818 moveInputMethodDialogs(-1);
1819 }
1820
1821 }
1822
1823 if (needAssignLayers) {
1824 assignWindowLayers(false /* setLayoutNeeded */);
1825 }
1826
1827 return true;
1828 }
1829
1830 /**
1831 * Dig through the WindowStates and find the one that the Input Method will target.
1832 * @param willMove
1833 * @return The index+1 in mWindows of the discovered target.
1834 */
1835 int findDesiredInputMethodWindowIndex(boolean willMove) {
1836 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
1837 // same display. Or even when the current IME/target are not on the same screen as the next
1838 // IME/target. For now only look for input windows on the main screen.
1839 WindowState w = null;
1840 int i;
1841 for (i = mWindows.size() - 1; i >= 0; --i) {
1842 final WindowState win = mWindows.get(i);
1843
1844 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG_WM, "Checking window @" + i
1845 + " " + win + " fl=0x" + Integer.toHexString(win.mAttrs.flags));
1846 if (canBeImeTarget(win)) {
1847 w = win;
1848 //Slog.i(TAG_WM, "Putting input method here!");
1849
1850 // Yet more tricksyness! If this window is a "starting" window, we do actually want
1851 // to be on top of it, but it is not -really- where input will go. So if the caller
1852 // is not actually looking to move the IME, look down below for a real window to
1853 // target...
1854 if (!willMove && w.mAttrs.type == TYPE_APPLICATION_STARTING && i > 0) {
1855 final WindowState wb = mWindows.get(i-1);
1856 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1857 i--;
1858 w = wb;
1859 }
1860 }
1861 break;
1862 }
1863 }
1864
1865 // Now w is either mWindows[0] or an IME (or null if mWindows is empty).
1866
1867 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG_WM, "Proposed new IME target: " + w);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001868
1869 // Now, a special case -- if the last target's window is in the process of exiting, and is
1870 // above the new target, keep on the last target to avoid flicker. Consider for example a
1871 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
1872 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
1873 // scrim.
1874 final WindowState curTarget = mService.mInputMethodTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001875 if (curTarget != null
1876 && curTarget.isDisplayedLw()
1877 && curTarget.isClosing()
1878 && (w == null || curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001879 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001880 return mWindows.indexOf(curTarget) + 1;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001881 }
1882
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001883 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target="
1884 + w + " willMove=" + willMove);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001885
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001886 if (willMove && w != null) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001887 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
1888 if (token != null) {
1889
1890 // Now some fun for dealing with window animations that modify the Z order. We need
1891 // to look at all windows below the current target that are in this app, finding the
1892 // highest visible one in layering.
1893 WindowState highestTarget = null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001894 int highestPos = 0;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001895 if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001896 WindowList curWindows = token.getDisplayContent().mWindows;
1897 int pos = curWindows.indexOf(curTarget);
1898 while (pos >= 0) {
1899 WindowState win = curWindows.get(pos);
1900 if (win.mAppToken != token) {
1901 break;
1902 }
1903 if (!win.mRemoved) {
1904 if (highestTarget == null || win.mWinAnimator.mAnimLayer >
1905 highestTarget.mWinAnimator.mAnimLayer) {
1906 highestTarget = win;
1907 highestPos = pos;
1908 }
1909 }
1910 pos--;
1911 }
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001912 }
1913
1914 if (highestTarget != null) {
1915 final AppTransition appTransition = mService.mAppTransition;
1916 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
1917 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
1918 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001919 + " new layer=" + w.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001920
1921 if (appTransition.isTransitionSet()) {
1922 // If we are currently setting up for an animation, hold everything until we
1923 // can find out what will happen.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001924 mService.mInputMethodTargetWaitingAnim = true;
1925 mService.mInputMethodTarget = highestTarget;
1926 return highestPos + 1;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001927 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001928 highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001929 // If the window we are currently targeting is involved with an animation,
1930 // and it is on top of the next target we will be over, then hold off on
1931 // moving until that is done.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001932 mService.mInputMethodTargetWaitingAnim = true;
1933 mService.mInputMethodTarget = highestTarget;
1934 return highestPos + 1;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001935 }
1936 }
1937 }
1938 }
1939
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001940 //Slog.i(TAG_WM, "Placing input method @" + (i+1));
1941 if (w != null) {
1942 if (willMove) {
1943 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
1944 + w + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
1945 mService.mInputMethodTarget = w;
1946 mService.mInputMethodTargetWaitingAnim = false;
1947 if (w.mAppToken != null) {
1948 setInputMethodAnimLayerAdjustment(
1949 w.mAppToken.mAppAnimator.animLayerAdjustment);
1950 } else {
1951 setInputMethodAnimLayerAdjustment(0);
1952 }
Wale Ogunwale4551c8b2016-11-10 10:25:20 -08001953 }
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001954
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001955 // If the docked divider is visible, we still need to go through this whole excercise to
1956 // find the appropriate input method target (used for animations and dialog
1957 // adjustments), but for purposes of Z ordering we simply wish to place it above the
1958 // docked divider. Unless it is already above the divider.
1959 final WindowState dockedDivider = mDividerControllerLocked.getWindow();
1960 if (dockedDivider != null && dockedDivider.isVisibleLw()) {
1961 int dividerIndex = mWindows.indexOf(dockedDivider);
1962 if (dividerIndex > 0 && dividerIndex > i) {
1963 return dividerIndex + 1;
1964 }
1965 }
1966 return i+1;
1967 }
1968 if (willMove) {
1969 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
1970 + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
1971 mService.mInputMethodTarget = null;
1972 setInputMethodAnimLayerAdjustment(0);
1973 }
1974 return -1;
1975 }
1976
1977 private static boolean canBeImeTarget(WindowState w) {
1978 final int fl = w.mAttrs.flags & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1979 final int type = w.mAttrs.type;
1980
1981 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
1982 && type != TYPE_APPLICATION_STARTING) {
1983 return false;
1984 }
1985
1986 if (DEBUG_INPUT_METHOD) {
1987 Slog.i(TAG_WM, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1988 if (!w.isVisibleOrAdding()) {
1989 Slog.i(TAG_WM, " mSurfaceController=" + w.mWinAnimator.mSurfaceController
1990 + " relayoutCalled=" + w.mRelayoutCalled
1991 + " viewVis=" + w.mViewVisibility
1992 + " policyVis=" + w.mPolicyVisibility
1993 + " policyVisAfterAnim=" + w.mPolicyVisibilityAfterAnim
1994 + " parentHidden=" + w.isParentWindowHidden()
1995 + " exiting=" + w.mAnimatingExit + " destroying=" + w.mDestroying);
1996 if (w.mAppToken != null) {
1997 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1998 }
1999 }
2000 }
2001 return w.isVisibleOrAdding();
2002 }
2003
2004 private void logWindowList(final WindowList windows, String prefix) {
2005 int N = windows.size();
2006 while (N > 0) {
2007 N--;
2008 Slog.v(TAG_WM, prefix + "#" + N + ": " + windows.get(N));
2009 }
2010 }
2011
2012 boolean getNeedsMenu(WindowState win, WindowManagerPolicy.WindowState bottom) {
2013 int index = -1;
2014 while (true) {
2015 if (win.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2016 return win.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002017 }
2018 // If we reached the bottom of the range of windows we are considering,
2019 // assume no menu is needed.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002020 if (win == bottom) {
2021 return false;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002022 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002023 // The current window hasn't specified whether menu key is needed; look behind it.
2024 // First, we may need to determine the starting position.
2025 if (index < 0) {
2026 index = mWindows.indexOf(win);
2027 }
2028 index--;
2029 if (index < 0) {
2030 return false;
2031 }
2032 win = mWindows.get(index);
2033 }
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002034 }
2035
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002036 void setLayoutNeeded() {
2037 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2038 mLayoutNeeded = true;
2039 }
2040
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002041 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002042 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2043 mLayoutNeeded = false;
2044 }
2045
2046 boolean isLayoutNeeded() {
2047 return mLayoutNeeded;
2048 }
2049
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002050 private void addAppWindowExisting(WindowState win, WindowList tokenWindowList) {
2051
2052 // If this application has existing windows, we simply place the new window on top of
2053 // them... but keep the starting window on top.
2054 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
2055 // Base windows go behind everything else.
2056 final WindowState lowestWindow = tokenWindowList.get(0);
2057 addWindowToListBefore(win, lowestWindow);
2058 } else {
2059 final AppWindowToken atoken = win.mAppToken;
2060 final int windowListPos = tokenWindowList.size();
2061 final WindowState lastWindow = tokenWindowList.get(windowListPos - 1);
2062 if (atoken != null && lastWindow == atoken.startingWindow) {
2063 addWindowToListBefore(win, lastWindow);
2064 } else {
2065 int newIdx = findIdxBasedOnAppTokens(win);
2066 // There is a window above this one associated with the same apptoken note that the
2067 // window could be a floating window that was created later or a window at the top
2068 // of the list of windows associated with this token.
2069 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2070 "not Base app: Adding window " + win + " at " + (newIdx + 1) + " of "
2071 + mWindows.size());
2072 mWindows.add(newIdx + 1, win);
2073 mService.mWindowsChanged = true;
2074 }
2075 }
2076 }
2077
2078 /** Places the first input window after the second input window in the window list. */
2079 private void addWindowToListAfter(WindowState first, WindowState second) {
2080 final int i = mWindows.indexOf(second);
2081 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2082 "Adding window " + this + " at " + (i + 1) + " of " + mWindows.size()
2083 + " (after " + second + ")");
2084 mWindows.add(i + 1, first);
2085 mService.mWindowsChanged = true;
2086 }
2087
2088 /** Places the first input window before the second input window in the window list. */
2089 private void addWindowToListBefore(WindowState first, WindowState second) {
2090 int i = mWindows.indexOf(second);
2091 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2092 "Adding window " + this + " at " + i + " of " + mWindows.size()
2093 + " (before " + second + ")");
2094 if (i < 0) {
2095 Slog.w(TAG_WM, "addWindowToListBefore: Unable to find " + second + " in " + mWindows);
2096 i = 0;
2097 }
2098 mWindows.add(i, first);
2099 mService.mWindowsChanged = true;
2100 }
2101
2102 /**
2103 * This method finds out the index of a window that has the same app token as win. used for z
2104 * ordering the windows in mWindows
2105 */
2106 private int findIdxBasedOnAppTokens(WindowState win) {
2107 for(int j = mWindows.size() - 1; j >= 0; j--) {
2108 final WindowState wentry = mWindows.get(j);
2109 if(wentry.mAppToken == win.mAppToken) {
2110 return j;
2111 }
2112 }
2113 return -1;
2114 }
2115
2116 private void dumpChildrenNames() {
2117 StringBuilder output = new StringBuilder();
2118 dumpChildrenNames(output, " ");
2119 Slog.v(TAG_WM, output.toString());
2120 }
2121
2122 private void dumpWindows() {
2123 Slog.v(TAG_WM, " Display #" + mDisplayId);
2124 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
2125 Slog.v(TAG_WM, " #" + winNdx + ": " + mWindows.get(winNdx));
2126 }
2127 }
2128
Wale Ogunwale02319a62016-09-26 15:21:22 -07002129 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2130 if (mTokenMap.isEmpty()) {
2131 return;
2132 }
2133 pw.println(" Display #" + mDisplayId);
2134 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2135 while (it.hasNext()) {
2136 final WindowToken token = it.next();
2137 pw.print(" ");
2138 pw.print(token);
2139 if (dumpAll) {
2140 pw.println(':');
2141 token.dump(pw, " ");
2142 } else {
2143 pw.println();
2144 }
2145 }
2146 }
2147
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002148 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002149 final int count = mWindows.size();
2150 for (int j = 0; j < count; j++) {
2151 final WindowStateAnimator wAnim = mWindows.get(j).mWinAnimator;
2152 pw.println(subPrefix + "Window #" + j + ": " + wAnim);
2153 }
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002154 }
2155
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002156 void enableSurfaceTrace(FileDescriptor fd) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002157 for (int i = mWindows.size() - 1; i >= 0; i--) {
2158 final WindowState win = mWindows.get(i);
2159 win.mWinAnimator.enableSurfaceTrace(fd);
2160 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002161 }
2162
2163 void disableSurfaceTrace() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002164 for (int i = mWindows.size() - 1; i >= 0; i--) {
2165 final WindowState win = mWindows.get(i);
2166 win.mWinAnimator.disableSurfaceTrace();
2167 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002168 }
2169
Jorim Jaggife762342016-10-13 14:33:27 +02002170 /**
2171 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2172 */
2173 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2174 final WindowManagerPolicy policy = mService.mPolicy;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002175 for (int i = mWindows.size() - 1; i >= 0; i--) {
2176 final WindowState window = mWindows.get(i);
2177 if (window.mAppToken == null && policy.canBeHiddenByKeyguardLw(window)) {
2178 window.mWinAnimator.setAnimation(
Jorim Jaggife762342016-10-13 14:33:27 +02002179 policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
2180 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002181 }
Jorim Jaggife762342016-10-13 14:33:27 +02002182 }
2183
Wale Ogunwale494009b82016-10-21 09:01:38 -07002184 boolean checkWaitingForWindows() {
2185
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002186 boolean haveBootMsg = false;
2187 boolean haveApp = false;
2188 // if the wallpaper service is disabled on the device, we're never going to have
2189 // wallpaper, don't bother waiting for it
2190 boolean haveWallpaper = false;
2191 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2192 com.android.internal.R.bool.config_enableWallpaperService)
2193 && !mService.mOnlyCore;
2194 boolean haveKeyguard = true;
2195 final int count = mWindows.size();
2196 for (int i = 0; i < count; i++) {
2197 final WindowState w = mWindows.get(i);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002198 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2199 return true;
2200 }
2201 if (w.isDrawnLw()) {
2202 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002203 haveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002204 } else if (w.mAttrs.type == TYPE_APPLICATION
2205 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002206 haveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002207 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002208 haveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002209 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002210 haveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002211 }
2212 }
2213 }
2214
2215 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2216 "******** booted=" + mService.mSystemBooted
2217 + " msg=" + mService.mShowingBootMessages
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002218 + " haveBoot=" + haveBootMsg + " haveApp=" + haveApp
2219 + " haveWall=" + haveWallpaper + " wallEnabled=" + wallpaperEnabled
2220 + " haveKeyguard=" + haveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002221
2222 // If we are turning on the screen to show the boot message, don't do it until the boot
2223 // message is actually displayed.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002224 if (!mService.mSystemBooted && !haveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002225 return true;
2226 }
2227
2228 // If we are turning on the screen after the boot is completed normally, don't do so until
2229 // we have the application and wallpaper.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002230 if (mService.mSystemBooted && ((!haveApp && !haveKeyguard) ||
2231 (wallpaperEnabled && !haveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002232 return true;
2233 }
2234
2235 return false;
2236 }
2237
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002238 void updateWindowsForAnimator(WindowAnimator animator) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002239 final WallpaperController wallpaperController = mWallpaperController;
2240 for (int i = mWindows.size() - 1; i >= 0; i--) {
2241 WindowState win = mWindows.get(i);
2242 WindowStateAnimator winAnimator = win.mWinAnimator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002243 if (winAnimator.hasSurface()) {
2244 final boolean wasAnimating = winAnimator.mWasAnimating;
2245 final boolean nowAnimating = winAnimator.stepAnimationLocked(animator.mCurrentTime);
2246 winAnimator.mWasAnimating = nowAnimating;
2247 animator.orAnimating(nowAnimating);
2248
2249 if (DEBUG_WALLPAPER) Slog.v(TAG,
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002250 win + ": wasAnimating=" + wasAnimating + ", nowAnimating=" + nowAnimating);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002251
2252 if (wasAnimating && !winAnimator.mAnimating
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002253 && wallpaperController.isWallpaperTarget(win)) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002254 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2255 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
2256 if (DEBUG_LAYOUT_REPEATS) {
2257 mService.mWindowPlacerLocked.debugLayoutRepeats(
2258 "updateWindowsAndWallpaperLocked 2", pendingLayoutChanges);
2259 }
2260 }
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002261 }
2262
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002263 final AppWindowToken atoken = win.mAppToken;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002264 if (winAnimator.mDrawState == READY_TO_SHOW) {
2265 if (atoken == null || atoken.allDrawn) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002266 if (win.performShowLocked()) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002267 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
2268 if (DEBUG_LAYOUT_REPEATS) {
2269 mService.mWindowPlacerLocked.debugLayoutRepeats(
2270 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
2271 }
2272 }
2273 }
2274 }
2275 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
2276 if (appAnimator != null && appAnimator.thumbnail != null) {
2277 if (appAnimator.thumbnailTransactionSeq != animator.mAnimTransactionSequence) {
2278 appAnimator.thumbnailTransactionSeq = animator.mAnimTransactionSequence;
2279 appAnimator.thumbnailLayer = 0;
2280 }
2281 if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
2282 appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
2283 }
2284 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002285 } // end forall windows
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002286 }
2287
2288 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002289 resetAnimationBackgroundAnimator();
2290
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002291 final WindowList windows = mWindows;
2292 WindowState detachedWallpaper = null;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002293
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002294 for (int i = windows.size() - 1; i >= 0; i--) {
2295 final WindowState win = windows.get(i);
2296 final WindowStateAnimator winAnimator = win.mWinAnimator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002297 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002298 continue;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002299 }
2300
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002301 final int flags = win.mAttrs.flags;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002302
2303 // If this window is animating, make a note that we have an animating window and take
2304 // care of a request to run a detached wallpaper animation.
2305 if (winAnimator.mAnimating) {
2306 if (winAnimator.mAnimation != null) {
2307 if ((flags & FLAG_SHOW_WALLPAPER) != 0
2308 && winAnimator.mAnimation.getDetachWallpaper()) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002309 detachedWallpaper = win;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002310 }
2311 final int color = winAnimator.mAnimation.getBackgroundColor();
2312 if (color != 0) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002313 final TaskStack stack = win.getStack();
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002314 if (stack != null) {
2315 stack.setAnimationBackground(winAnimator, color);
2316 }
2317 }
2318 }
2319 animator.setAnimating(true);
2320 }
2321
2322 // If this window's app token is running a detached wallpaper animation, make a note so
2323 // we can ensure the wallpaper is displayed behind it.
2324 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
2325 if (appAnimator != null && appAnimator.animation != null
2326 && appAnimator.animating) {
2327 if ((flags & FLAG_SHOW_WALLPAPER) != 0
2328 && appAnimator.animation.getDetachWallpaper()) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002329 detachedWallpaper = win;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002330 }
2331
2332 final int color = appAnimator.animation.getBackgroundColor();
2333 if (color != 0) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002334 final TaskStack stack = win.getStack();
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002335 if (stack != null) {
2336 stack.setAnimationBackground(winAnimator, color);
2337 }
2338 }
2339 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002340 } // end forall windows
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002341
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002342 if (animator.mWindowDetachedWallpaper != detachedWallpaper) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002343 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002344 + animator.mWindowDetachedWallpaper + " to " + detachedWallpaper);
2345 animator.mWindowDetachedWallpaper = detachedWallpaper;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002346 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2347 }
2348 }
2349
2350 void prepareWindowSurfaces() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002351 final int count = mWindows.size();
2352 for (int j = 0; j < count; j++) {
2353 mWindows.get(j).mWinAnimator.prepareSurfaceLocked(true);
2354 }
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002355 }
2356
Wale Ogunwale494009b82016-10-21 09:01:38 -07002357 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002358 // The focus for the client is the window immediately below where we would place the input
2359 // method window.
2360 int idx = findDesiredInputMethodWindowIndex(false);
2361 if (idx <= 0) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002362 return false;
2363 }
2364
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002365 WindowState imFocus = mWindows.get(idx - 1);
Wale Ogunwale4551c8b2016-11-10 10:25:20 -08002366 if (DEBUG_INPUT_METHOD) {
2367 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2368 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2369 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002370 }
2371
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002372 if (imFocus == null) {
2373 return false;
2374 }
2375
2376 // This may be a starting window, in which case we still want to count it as okay.
2377 if (imFocus.mAttrs.type == TYPE_APPLICATION_STARTING && imFocus.mAppToken != null) {
2378 // The client has definitely started, so it really should have a window in this app
2379 // token. Let's look for it.
2380 final WindowState w = imFocus.mAppToken.getFirstNonStartingWindow();
2381 if (w != null) {
2382 if (DEBUG_INPUT_METHOD) Slog.i(TAG_WM, "Switching to real app window: " + w);
2383 imFocus = w;
2384 }
2385 }
2386
Wale Ogunwale494009b82016-10-21 09:01:38 -07002387 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2388
2389 if (DEBUG_INPUT_METHOD) {
2390 Slog.i(TAG_WM, "IM target client: " + imeClient);
2391 if (imeClient != null) {
2392 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2393 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2394 }
2395 }
2396
2397 return imeClient != null && imeClient.asBinder() == client.asBinder();
2398 }
2399
2400 boolean hasSecureWindowOnScreen() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002401 for (int i = mWindows.size() - 1; i >= 0; --i) {
2402 final WindowState ws = mWindows.get(i);
2403 if (ws.isOnScreen() && (ws.mAttrs.flags & FLAG_SECURE) != 0) {
2404 return true;
2405 }
2406 }
2407 return false;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002408 }
2409
2410 void updateSystemUiVisibility(int visibility, int globalDiff) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002411 for (int i = mWindows.size() - 1; i >= 0; --i) {
2412 final WindowState ws = mWindows.get(i);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002413 try {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002414 int curValue = ws.mSystemUiVisibility;
2415 int diff = (curValue ^ visibility) & globalDiff;
2416 int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002417 if (newValue != curValue) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002418 ws.mSeq++;
2419 ws.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002420 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002421 if (newValue != curValue || ws.mAttrs.hasSystemUiListeners) {
2422 ws.mClient.dispatchSystemUiVisibilityChanged(ws.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002423 visibility, newValue, diff);
2424 }
2425 } catch (RemoteException e) {
2426 // so sorry
2427 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002428 }
Wale Ogunwale494009b82016-10-21 09:01:38 -07002429 }
2430
2431 void onWindowFreezeTimeout() {
2432 Slog.w(TAG_WM, "Window freeze timeout expired.");
2433 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002434 for (int i = mWindows.size() - 1; i >= 0; --i) {
2435 final WindowState w = mWindows.get(i);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002436 if (!w.mOrientationChanging) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002437 continue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002438 }
2439 w.mOrientationChanging = false;
2440 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2441 - mService.mDisplayFreezeTime);
2442 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002443 }
Wale Ogunwale494009b82016-10-21 09:01:38 -07002444 mService.mWindowPlacerLocked.performSurfacePlacement();
2445 }
2446
2447 void waitForAllWindowsDrawn() {
2448 final WindowManagerPolicy policy = mService.mPolicy;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002449 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
2450 final WindowState win = mWindows.get(winNdx);
2451 final boolean keyguard = policy.isKeyguardHostWindow(win.mAttrs);
2452 if (win.isVisibleLw() && (win.mAppToken != null || keyguard)) {
2453 win.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002454 // Force add to mResizingWindows.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002455 win.mLastContentInsets.set(-1, -1, -1, -1);
2456 mService.mWaitingForDrawn.add(win);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002457 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002458 }
Wale Ogunwale494009b82016-10-21 09:01:38 -07002459 }
2460
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002461 // TODO: Super crazy long method that should be broken down...
2462 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2463
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002464 boolean focusDisplayed = false;
2465 boolean displayHasContent = false;
2466 float preferredRefreshRate = 0;
2467 int preferredModeId = 0;
2468
2469
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002470 final int dw = mDisplayInfo.logicalWidth;
2471 final int dh = mDisplayInfo.logicalHeight;
2472 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2473
2474 mTmpUpdateAllDrawn.clear();
2475
2476 int repeats = 0;
2477 do {
2478 repeats++;
2479 if (repeats > 6) {
2480 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2481 clearLayoutNeeded();
2482 break;
2483 }
2484
2485 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2486 pendingLayoutChanges);
2487
Andrii Kulian839def92016-11-02 10:58:58 -07002488 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2489 // the wallpaper window jumping across displays.
2490 // Remove check for default display when there will be support for multiple wallpaper
2491 // targets (on different displays).
2492 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002493 adjustWallpaperWindows();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002494 }
2495
2496 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2497 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2498 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2499 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002500 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002501 }
2502 }
2503
2504 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2505 setLayoutNeeded();
2506 }
2507
2508 // FIRST LOOP: Perform a layout, if needed.
2509 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2510 performLayout(repeats == 1, false /* updateInputWindows */);
2511 } else {
2512 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2513 }
2514
2515 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2516 pendingLayoutChanges = 0;
2517
2518 if (isDefaultDisplay) {
2519 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002520 for (int i = mWindows.size() - 1; i >= 0; i--) {
2521 final WindowState w = mWindows.get(i);
Jorim Jaggife762342016-10-13 14:33:27 +02002522 mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
2523 mService.mInputMethodTarget);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002524 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002525 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2526 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2527 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2528 }
2529 } while (pendingLayoutChanges != 0);
2530
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002531 RootWindowContainer root = mService.mRoot;
2532 boolean obscured = false;
2533 boolean syswin = false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002534 resetDimming();
2535
2536 // Only used if default window
2537 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
2538
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002539 for (int i = mWindows.size() - 1; i >= 0; i--) {
2540 final WindowState w = mWindows.get(i);
2541 final Task task = w.getTask();
2542 final boolean obscuredChanged = w.mObscured != obscured;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002543
2544 // Update effect.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002545 w.mObscured = obscured;
2546 if (!obscured) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002547 final boolean isDisplayed = w.isDisplayedLw();
2548
2549 if (isDisplayed && w.isObscuringFullscreen(mDisplayInfo)) {
2550 // This window completely covers everything behind it, so we want to leave all
2551 // of them as undimmed (for performance reasons).
2552 root.mObscuringWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002553 obscured = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002554 }
2555
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002556 displayHasContent |= root.handleNotObscuredLocked(w, obscured, syswin);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002557
2558 if (w.mHasSurface && isDisplayed) {
2559 final int type = w.mAttrs.type;
2560 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
2561 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002562 syswin = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002563 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002564 if (preferredRefreshRate == 0 && w.mAttrs.preferredRefreshRate != 0) {
2565 preferredRefreshRate = w.mAttrs.preferredRefreshRate;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002566 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002567 if (preferredModeId == 0 && w.mAttrs.preferredDisplayModeId != 0) {
2568 preferredModeId = w.mAttrs.preferredDisplayModeId;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002569 }
2570 }
2571 }
2572
2573 w.applyDimLayerIfNeeded();
2574
2575 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
2576 && mWallpaperController.isWallpaperTarget(w)) {
2577 // This is the wallpaper target and its obscured state changed... make sure the
2578 // current wallpaper's visibility has been updated accordingly.
2579 mWallpaperController.updateWallpaperVisibility();
2580 }
2581
2582 w.handleWindowMovedIfNeeded();
2583
2584 final WindowStateAnimator winAnimator = w.mWinAnimator;
2585
2586 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
2587 w.mContentChanged = false;
2588
2589 // Moved from updateWindowsAndWallpaperLocked().
2590 if (w.mHasSurface) {
2591 // Take care of the window being ready to display.
2592 final boolean committed = winAnimator.commitFinishDrawingLocked();
2593 if (isDefaultDisplay && committed) {
2594 if (w.mAttrs.type == TYPE_DREAM) {
2595 // HACK: When a dream is shown, it may at that point hide the lock screen.
2596 // So we need to redo the layout to let the phone window manager make this
2597 // happen.
2598 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
2599 if (DEBUG_LAYOUT_REPEATS) {
2600 surfacePlacer.debugLayoutRepeats(
2601 "dream and commitFinishDrawingLocked true",
2602 pendingLayoutChanges);
2603 }
2604 }
2605 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
2606 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
2607 "First draw done in potential wallpaper target " + w);
2608 root.mWallpaperMayChange = true;
2609 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
2610 if (DEBUG_LAYOUT_REPEATS) {
2611 surfacePlacer.debugLayoutRepeats(
2612 "wallpaper and commitFinishDrawingLocked true",
2613 pendingLayoutChanges);
2614 }
2615 }
2616 }
2617 if (!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening()) {
2618 // Updates the shown frame before we set up the surface. This is needed
2619 // because the resizing could change the top-left position (in addition to
2620 // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to
2621 // position the surface.
2622 //
2623 // If an animation is being started, we can't call this method because the
2624 // animation hasn't processed its initial transformation yet, but in general
2625 // we do want to update the position if the window is animating.
2626 winAnimator.computeShownFrameLocked();
2627 }
2628 winAnimator.setSurfaceBoundariesLocked(recoveringMemory);
2629 }
2630
2631 final AppWindowToken atoken = w.mAppToken;
2632 if (atoken != null) {
2633 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
2634 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
2635 mTmpUpdateAllDrawn.add(atoken);
2636 }
2637 }
2638
2639 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
2640 && w.isDisplayedLw()) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002641 focusDisplayed = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002642 }
2643
2644 w.updateResizingWindowIfNeeded();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002645 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002646
2647 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002648 displayHasContent,
2649 preferredRefreshRate,
2650 preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002651 true /* inTraversal, must call performTraversalInTrans... below */);
2652
2653 stopDimmingIfNeeded();
2654
2655 while (!mTmpUpdateAllDrawn.isEmpty()) {
2656 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2657 // See if any windows have been drawn, so they (and others associated with them)
2658 // can now be shown.
2659 atoken.updateAllDrawn(this);
2660 }
2661
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002662 return focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002663 }
2664
2665 void performLayout(boolean initial, boolean updateInputWindows) {
2666 if (!isLayoutNeeded()) {
2667 return;
2668 }
2669 clearLayoutNeeded();
2670
2671 final int dw = mDisplayInfo.logicalWidth;
2672 final int dh = mDisplayInfo.logicalHeight;
2673
2674 int i;
2675
2676 if (DEBUG_LAYOUT) {
2677 Slog.v(TAG, "-------------------------------------");
2678 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2679 }
2680
2681 mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mService.mRotation,
2682 getConfiguration().uiMode);
2683 if (isDefaultDisplay) {
2684 // Not needed on non-default displays.
2685 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2686 mService.mScreenRect.set(0, 0, dw, dh);
2687 }
2688
2689 mService.mPolicy.getContentRectLw(mContentRect);
2690
2691 int seq = mService.mLayoutSeq + 1;
2692 if (seq < 0) seq = 0;
2693 mService.mLayoutSeq = seq;
2694
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002695 boolean behindDream = false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002696
2697 // First perform layout of any root windows (not attached to another window).
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002698 int topAttached = -1;
2699 for (i = mWindows.size() - 1; i >= 0; i--) {
2700 final WindowState win = mWindows.get(i);
2701
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002702 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
2703 // wasting time and funky changes while a window is animating away.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002704 final boolean gone = (behindDream && mService.mPolicy.canBeHiddenByKeyguardLw(win))
2705 || win.isGoneForLayoutLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002706
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002707 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
2708 Slog.v(TAG, "1ST PASS " + win + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
2709 + " mLayoutAttached=" + win.mLayoutAttached
2710 + " screen changed=" + win.isConfigChanged());
2711 final AppWindowToken atoken = win.mAppToken;
2712 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + win.mViewVisibility
2713 + " mRelayoutCalled=" + win.mRelayoutCalled + " hidden=" + win.mToken.hidden
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002714 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002715 + " parentHidden=" + win.isParentWindowHidden());
2716 else Slog.v(TAG, " VIS: mViewVisibility=" + win.mViewVisibility
2717 + " mRelayoutCalled=" + win.mRelayoutCalled + " hidden=" + win.mToken.hidden
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002718 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002719 + " parentHidden=" + win.isParentWindowHidden());
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002720 }
2721
2722 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
2723 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
2724 // since that means "perform layout as normal, just don't display").
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002725 if (!gone || !win.mHaveFrame || win.mLayoutNeeded
2726 || ((win.isConfigChanged() || win.setReportResizeHints())
2727 && !win.isGoneForLayoutLw() &&
2728 ((win.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
2729 (win.mHasSurface && win.mAppToken != null &&
2730 win.mAppToken.layoutConfigChanges)))) {
2731 if (!win.mLayoutAttached) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002732 if (initial) {
2733 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002734 win.mContentChanged = false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002735 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002736 if (win.mAttrs.type == TYPE_DREAM) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002737 // Don't layout windows behind a dream, so that if it does stuff like hide
2738 // the status bar we won't get a bad transition when it goes away.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002739 behindDream = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002740 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002741 win.mLayoutNeeded = false;
2742 win.prelayout();
2743 mService.mPolicy.layoutWindowLw(win, null);
2744 win.mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002745
2746 // Window frames may have changed. Update dim layer with the new bounds.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002747 final Task task = win.getTask();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002748 if (task != null) {
2749 mDimLayerController.updateDimLayer(task);
2750 }
2751
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002752 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + win.mFrame
2753 + " mContainingFrame=" + win.mContainingFrame
2754 + " mDisplayFrame=" + win.mDisplayFrame);
2755 } else {
2756 if (topAttached < 0) topAttached = i;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002757 }
2758 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002759 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002760
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002761 boolean attachedBehindDream = false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002762
2763 // Now perform layout of attached windows, which usually depend on the position of the
2764 // window they are attached to. XXX does not deal with windows that are attached to windows
2765 // that are themselves attached.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002766 for (i = topAttached; i >= 0; i--) {
2767 final WindowState win = mWindows.get(i);
2768
2769 if (win.mLayoutAttached) {
2770 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + win + " mHaveFrame=" + win.mHaveFrame
2771 + " mViewVisibility=" + win.mViewVisibility
2772 + " mRelayoutCalled=" + win.mRelayoutCalled);
2773 // If this view is GONE, then skip it -- keep the current frame, and let the caller
2774 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
2775 // windows, since that means "perform layout as normal, just don't display").
2776 if (attachedBehindDream && mService.mPolicy.canBeHiddenByKeyguardLw(win)) {
2777 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002778 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002779 if ((win.mViewVisibility != GONE && win.mRelayoutCalled) || !win.mHaveFrame
2780 || win.mLayoutNeeded) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002781 if (initial) {
2782 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002783 win.mContentChanged = false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002784 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002785 win.mLayoutNeeded = false;
2786 win.prelayout();
2787 mService.mPolicy.layoutWindowLw(win, win.getParentWindow());
2788 win.mLayoutSeq = seq;
2789 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + win.mFrame
2790 + " mContainingFrame=" + win.mContainingFrame
2791 + " mDisplayFrame=" + win.mDisplayFrame);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002792 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002793 } else if (win.mAttrs.type == TYPE_DREAM) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002794 // Don't layout windows behind a dream, so that if it does stuff like hide the
2795 // status bar we won't get a bad transition when it goes away.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002796 attachedBehindDream = behindDream;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002797 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002798 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002799
2800 // Window frames may have changed. Tell the input dispatcher about it.
2801 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2802 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2803 if (updateInputWindows) {
2804 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2805 }
2806
2807 mService.mPolicy.finishLayoutLw();
2808 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2809 }
2810
2811 /**
2812 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2813 * In portrait mode, it grabs the full screenshot.
2814 *
2815 * @param width the width of the target bitmap
2816 * @param height the height of the target bitmap
2817 * @param includeFullDisplay true if the screen should not be cropped before capture
2818 * @param frameScale the scale to apply to the frame, only used when width = -1 and height = -1
2819 * @param config of the output bitmap
2820 * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
2821 */
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002822 Bitmap screenshotApplications(IBinder appToken, int displayId, int width, int height,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002823 boolean includeFullDisplay, float frameScale, Bitmap.Config config,
2824 boolean wallpaperOnly) {
2825 int dw = mDisplayInfo.logicalWidth;
2826 int dh = mDisplayInfo.logicalHeight;
2827 if (dw == 0 || dh == 0) {
2828 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
2829 + ": returning null. logical widthxheight=" + dw + "x" + dh);
2830 return null;
2831 }
2832
2833 Bitmap bm = null;
2834
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002835 int maxLayer = 0;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002836 final Rect frame = new Rect();
2837 final Rect stackBounds = new Rect();
2838
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002839 boolean screenshotReady;
2840 int minLayer;
2841 if (appToken == null && !wallpaperOnly) {
2842 screenshotReady = true;
2843 minLayer = 0;
2844 } else {
2845 screenshotReady = false;
2846 minLayer = Integer.MAX_VALUE;
2847 }
2848
2849 WindowState appWin = null;
2850
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002851 boolean includeImeInScreenshot;
2852 synchronized(mService.mWindowMap) {
2853 final AppWindowToken imeTargetAppToken = mService.mInputMethodTarget != null
2854 ? mService.mInputMethodTarget.mAppToken : null;
2855 // We only include the Ime in the screenshot if the app we are screenshoting is the IME
2856 // target and isn't in multi-window mode. We don't screenshot the IME in multi-window
2857 // mode because the frame of the IME might not overlap with that of the app.
2858 // E.g. IME target app at the top in split-screen mode and the IME at the bottom
2859 // overlapping with the bottom app.
2860 includeImeInScreenshot = imeTargetAppToken != null
2861 && imeTargetAppToken.appToken != null
2862 && imeTargetAppToken.appToken.asBinder() == appToken
2863 && !mService.mInputMethodTarget.isInMultiWindowMode();
2864 }
2865
2866 final int aboveAppLayer = (mService.mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) + 1)
2867 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
2868
2869 synchronized(mService.mWindowMap) {
2870 // Figure out the part of the screen that is actually the app.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002871 appWin = null;
2872 for (int i = mWindows.size() - 1; i >= 0; i--) {
2873 final WindowState ws = mWindows.get(i);
2874 if (!ws.mHasSurface) {
2875 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002876 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002877 if (ws.mLayer >= aboveAppLayer) {
2878 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002879 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002880 if (wallpaperOnly && !ws.mIsWallpaper) {
2881 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002882 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002883 if (ws.mIsImWindow) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002884 if (!includeImeInScreenshot) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002885 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002886 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002887 } else if (ws.mIsWallpaper) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002888 // If this is the wallpaper layer and we're only looking for the wallpaper layer
2889 // then the target window state is this one.
2890 if (wallpaperOnly) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002891 appWin = ws;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002892 }
2893
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002894 if (appWin == null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002895 // We have not ran across the target window yet, so it is probably behind
2896 // the wallpaper. This can happen when the keyguard is up and all windows
2897 // are moved behind the wallpaper. We don't want to include the wallpaper
2898 // layer in the screenshot as it will cover-up the layer of the target
2899 // window.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002900 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002901 }
2902 // Fall through. The target window is in front of the wallpaper. For this
2903 // case we want to include the wallpaper layer in the screenshot because
2904 // the target window might have some transparent areas.
2905 } else if (appToken != null) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002906 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002907 // This app window is of no interest if it is not associated with the
2908 // screenshot app.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002909 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002910 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002911 appWin = ws;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002912 }
2913
2914 // Include this window.
2915
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002916 final WindowStateAnimator winAnim = ws.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002917 int layer = winAnim.mSurfaceController.getLayer();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002918 if (maxLayer < layer) {
2919 maxLayer = layer;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002920 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002921 if (minLayer > layer) {
2922 minLayer = layer;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002923 }
2924
2925 // Don't include wallpaper in bounds calculation
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002926 if (!includeFullDisplay && !ws.mIsWallpaper) {
2927 final Rect wf = ws.mFrame;
2928 final Rect cr = ws.mContentInsets;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002929 int left = wf.left + cr.left;
2930 int top = wf.top + cr.top;
2931 int right = wf.right - cr.right;
2932 int bottom = wf.bottom - cr.bottom;
2933 frame.union(left, top, right, bottom);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002934 ws.getVisibleBounds(stackBounds);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002935 if (!Rect.intersects(frame, stackBounds)) {
2936 // Set frame empty if there's no intersection.
2937 frame.setEmpty();
2938 }
2939 }
2940
2941 final boolean foundTargetWs =
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002942 (ws.mAppToken != null && ws.mAppToken.token == appToken)
2943 || (appWin != null && wallpaperOnly);
2944 if (foundTargetWs && ws.isDisplayedLw() && winAnim.getShown()) {
2945 screenshotReady = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002946 }
2947
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002948 if (ws.isObscuringFullscreen(mDisplayInfo)){
2949 break;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002950 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002951 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002952
2953 if (appToken != null && appWin == null) {
2954 // Can't find a window to snapshot.
2955 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM,
2956 "Screenshot: Couldn't find a surface matching " + appToken);
2957 return null;
2958 }
2959
2960 if (!screenshotReady) {
2961 Slog.i(TAG_WM, "Failed to capture screenshot of " + appToken +
2962 " appWin=" + (appWin == null ? "null" : (appWin + " drawState=" +
2963 appWin.mWinAnimator.mDrawState)));
2964 return null;
2965 }
2966
2967 // Screenshot is ready to be taken. Everything from here below will continue
2968 // through the bottom of the loop and return a value. We only stay in the loop
2969 // because we don't want to release the mWindowMap lock until the screenshot is
2970 // taken.
2971
2972 if (maxLayer == 0) {
2973 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
2974 + ": returning null maxLayer=" + maxLayer);
2975 return null;
2976 }
2977
2978 if (!includeFullDisplay) {
2979 // Constrain frame to the screen size.
2980 if (!frame.intersect(0, 0, dw, dh)) {
2981 frame.setEmpty();
2982 }
2983 } else {
2984 // Caller just wants entire display.
2985 frame.set(0, 0, dw, dh);
2986 }
2987 if (frame.isEmpty()) {
2988 return null;
2989 }
2990
2991 if (width < 0) {
2992 width = (int) (frame.width() * frameScale);
2993 }
2994 if (height < 0) {
2995 height = (int) (frame.height() * frameScale);
2996 }
2997
2998 // Tell surface flinger what part of the image to crop. Take the top
2999 // right part of the application, and crop the larger dimension to fit.
3000 Rect crop = new Rect(frame);
3001 if (width / (float) frame.width() < height / (float) frame.height()) {
3002 int cropWidth = (int)((float)width / (float)height * frame.height());
3003 crop.right = crop.left + cropWidth;
3004 } else {
3005 int cropHeight = (int)((float)height / (float)width * frame.width());
3006 crop.bottom = crop.top + cropHeight;
3007 }
3008
3009 // The screenshot API does not apply the current screen rotation.
3010 int rot = mDisplay.getRotation();
3011
3012 if (rot == ROTATION_90 || rot == ROTATION_270) {
3013 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3014 }
3015
3016 // Surfaceflinger is not aware of orientation, so convert our logical
3017 // crop to surfaceflinger's portrait orientation.
3018 convertCropForSurfaceFlinger(crop, rot, dw, dh);
3019
3020 if (DEBUG_SCREENSHOT) {
3021 Slog.i(TAG_WM, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to "
3022 + maxLayer + " appToken=" + appToken);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003023 for (int i = 0; i < mWindows.size(); i++) {
3024 final WindowState win = mWindows.get(i);
3025 final WindowSurfaceController controller = win.mWinAnimator.mSurfaceController;
3026 Slog.i(TAG_WM, win + ": " + win.mLayer
3027 + " animLayer=" + win.mWinAnimator.mAnimLayer
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003028 + " surfaceLayer=" + ((controller == null)
3029 ? "null" : controller.getLayer()));
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003030 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003031 }
3032
3033 final ScreenRotationAnimation screenRotationAnimation =
3034 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3035 final boolean inRotation = screenRotationAnimation != null &&
3036 screenRotationAnimation.isAnimating();
3037 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM,
3038 "Taking screenshot while rotating");
3039
3040 // We force pending transactions to flush before taking
3041 // the screenshot by pushing an empty synchronous transaction.
3042 SurfaceControl.openTransaction();
3043 SurfaceControl.closeTransactionSync();
3044
3045 bm = SurfaceControl.screenshot(crop, width, height, minLayer, maxLayer,
3046 inRotation, rot);
3047 if (bm == null) {
3048 Slog.w(TAG_WM, "Screenshot failure taking screenshot for (" + dw + "x" + dh
3049 + ") to layer " + maxLayer);
3050 return null;
3051 }
3052 }
3053
3054 if (DEBUG_SCREENSHOT) {
3055 // TEST IF IT's ALL BLACK
3056 int[] buffer = new int[bm.getWidth() * bm.getHeight()];
3057 bm.getPixels(buffer, 0, bm.getWidth(), 0, 0, bm.getWidth(), bm.getHeight());
3058 boolean allBlack = true;
3059 final int firstColor = buffer[0];
3060 for (int i = 0; i < buffer.length; i++) {
3061 if (buffer[i] != firstColor) {
3062 allBlack = false;
3063 break;
3064 }
3065 }
3066 if (allBlack) {
3067 Slog.i(TAG_WM, "Screenshot " + appWin + " was monochrome(" +
3068 Integer.toHexString(firstColor) + ")! mSurfaceLayer=" +
3069 (appWin != null ?
3070 appWin.mWinAnimator.mSurfaceController.getLayer() : "null") +
3071 " minLayer=" + minLayer + " maxLayer=" + maxLayer);
3072 }
3073 }
3074
3075 // Create a copy of the screenshot that is immutable and backed in ashmem.
3076 // This greatly reduces the overhead of passing the bitmap between processes.
3077 Bitmap ret = bm.createAshmemBitmap(config);
3078 bm.recycle();
3079 return ret;
3080 }
3081
3082 // TODO: Can this use createRotationMatrix()?
3083 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3084 if (rot == Surface.ROTATION_90) {
3085 final int tmp = crop.top;
3086 crop.top = dw - crop.right;
3087 crop.right = crop.bottom;
3088 crop.bottom = dw - crop.left;
3089 crop.left = tmp;
3090 } else if (rot == Surface.ROTATION_180) {
3091 int tmp = crop.top;
3092 crop.top = dh - crop.bottom;
3093 crop.bottom = dh - tmp;
3094 tmp = crop.right;
3095 crop.right = dw - crop.left;
3096 crop.left = dw - tmp;
3097 } else if (rot == Surface.ROTATION_270) {
3098 final int tmp = crop.top;
3099 crop.top = crop.left;
3100 crop.left = dh - crop.bottom;
3101 crop.bottom = crop.right;
3102 crop.right = dh - tmp;
3103 }
3104 }
3105
3106 void onSeamlessRotationTimeout() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003107 boolean layoutNeeded = false;
3108 for (int i = mWindows.size() - 1; i >= 0; i--) {
3109 final WindowState w = mWindows.get(i);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003110 if (!w.mSeamlesslyRotated) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003111 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003112 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003113 layoutNeeded = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003114 w.setDisplayLayoutNeeded();
3115 mService.markForSeamlessRotation(w, false);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003116 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003117
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003118 if (layoutNeeded) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003119 mService.mWindowPlacerLocked.performSurfacePlacement();
3120 }
3121 }
3122
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003123 static final class GetWindowOnDisplaySearchResult {
3124 boolean reachedToken;
3125 WindowState foundWindow;
3126
3127 void reset() {
3128 reachedToken = false;
3129 foundWindow = null;
3130 }
3131 }
3132
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003133 static final class TaskForResizePointSearchResult {
3134 boolean searchDone;
3135 Task taskForResize;
3136
3137 void reset() {
3138 searchDone = false;
3139 taskForResize = null;
3140 }
3141 }
Robert Carr3b716242016-08-16 16:02:21 -07003142
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003143 /**
3144 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3145 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3146 * homogeneous children type which is currently required by sub-classes of
3147 * {@link WindowContainer} class.
3148 */
3149 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3150
3151 int size() {
3152 return mChildren.size();
3153 }
3154
3155 E get(int index) {
3156 return mChildren.get(index);
3157 }
3158
3159 @Override
3160 boolean fillsParent() {
3161 return true;
3162 }
3163
3164 @Override
3165 boolean isVisible() {
3166 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003167 }
3168 }
3169
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003170 /**
3171 * Window container class that contains all containers on this display relating to Apps.
3172 * I.e Activities.
3173 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003174 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003175
Andrii Kulian839def92016-11-02 10:58:58 -07003176 /**
3177 * Adds the stack to this container.
3178 * @see WindowManagerService#addStackToDisplay(int, int, boolean)
3179 */
3180 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003181 if (stack.mStackId == HOME_STACK_ID) {
3182 if (mHomeStack != null) {
3183 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
3184 }
3185 mHomeStack = stack;
3186 }
3187 addChild(stack, onTop);
3188 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003189 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003190
Andrii Kulian839def92016-11-02 10:58:58 -07003191 /** Removes the stack from its container and prepare for changing the parent. */
3192 void removeStackFromDisplay(TaskStack stack) {
3193 removeChild(stack);
3194 stack.onRemovedFromDisplay();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003195 // TODO: remove when window list will be gone.
3196 // Manually remove records from window list and tap excluded windows list.
3197 for (int i = mWindows.size() - 1; i >= 0; --i) {
3198 final WindowState windowState = mWindows.get(i);
3199 if (stack == windowState.getStack()) {
3200 mWindows.remove(i);
3201 mTapExcludedWindows.remove(windowState);
3202 }
3203 }
Andrii Kulian839def92016-11-02 10:58:58 -07003204 }
3205
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003206 void moveStack(TaskStack stack, boolean toTop) {
3207 if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
3208 // This stack is always-on-top silly...
3209 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
3210 return;
3211 }
3212
3213 if (!mChildren.contains(stack)) {
3214 Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
3215 }
3216 removeChild(stack);
3217 addChild(stack, toTop);
3218 }
3219
3220 private void addChild(TaskStack stack, boolean toTop) {
3221 int addIndex = toTop ? mChildren.size() : 0;
3222
3223 if (toTop
3224 && mService.isStackVisibleLocked(PINNED_STACK_ID)
3225 && stack.mStackId != PINNED_STACK_ID) {
3226 // The pinned stack is always the top most stack (always-on-top) when it is visible.
3227 // So, stack is moved just below the pinned stack.
3228 addIndex--;
3229 TaskStack topStack = mChildren.get(addIndex);
3230 if (topStack.mStackId != PINNED_STACK_ID) {
3231 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3232 }
3233 }
3234 addChild(stack, addIndex);
3235 setLayoutNeeded();
3236 }
3237
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003238 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003239 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3240 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003241 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003242 if (super.forAllWindows(callback, traverseTopToBottom)) {
3243 return true;
3244 }
3245 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3246 return true;
3247 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003248 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003249 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3250 return true;
3251 }
3252 if (super.forAllWindows(callback, traverseTopToBottom)) {
3253 return true;
3254 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003255 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003256 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003257 }
3258
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003259 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003260 boolean traverseTopToBottom) {
3261 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3262 // app tokens.
3263 // TODO: Investigate if we need to continue to do this or if we can just process them
3264 // in-order.
3265 if (traverseTopToBottom) {
3266 for (int i = mChildren.size() - 1; i >= 0; --i) {
3267 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3268 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003269 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3270 traverseTopToBottom)) {
3271 return true;
3272 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003273 }
3274 }
3275 } else {
3276 final int count = mChildren.size();
3277 for (int i = 0; i < count; ++i) {
3278 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3279 final int appTokensCount = appTokens.size();
3280 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003281 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3282 traverseTopToBottom)) {
3283 return true;
3284 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003285 }
3286 }
3287 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003288 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003289 }
3290
3291 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003292 int getOrientation() {
3293 if (mService.isStackVisibleLocked(DOCKED_STACK_ID)
3294 || mService.isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID)) {
3295 // Apps and their containers are not allowed to specify an orientation while the
3296 // docked or freeform stack is visible...except for the home stack/task if the
3297 // docked stack is minimized and it actually set something.
3298 if (mHomeStack != null && mHomeStack.isVisible()
3299 && mDividerControllerLocked.isMinimizedDock()) {
3300 final int orientation = mHomeStack.getOrientation();
3301 if (orientation != SCREEN_ORIENTATION_UNSET) {
3302 return orientation;
3303 }
3304 }
3305 return SCREEN_ORIENTATION_UNSPECIFIED;
3306 }
3307
3308 final int orientation = super.getOrientation();
3309 if (orientation != SCREEN_ORIENTATION_UNSET
3310 && orientation != SCREEN_ORIENTATION_BEHIND) {
3311 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3312 "App is requesting an orientation, return " + orientation);
3313 return orientation;
3314 }
3315
3316 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3317 "No app is requesting an orientation, return " + mService.mLastOrientation);
3318 // The next app has not been requested to be visible, so we keep the current orientation
3319 // to prevent freezing/unfreezing the display too early.
3320 return mService.mLastOrientation;
3321 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003322 }
3323
3324 /**
3325 * Window container class that contains all containers on this display that are not related to
3326 * Apps. E.g. status bar.
3327 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003328 private final class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
3329 /**
3330 * Compares two child window tokens returns -1 if the first is lesser than the second in
3331 * terms of z-order and 1 otherwise.
3332 */
3333 final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
3334 // Tokens with higher base layer are z-ordered on-top.
3335 mService.mPolicy.windowTypeToLayerLw(token1.windowType)
3336 < mService.mPolicy.windowTypeToLayerLw(token2.windowType) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003337
Wale Ogunwale3a931692016-11-02 16:49:48 -07003338 private final String mName;
3339 NonAppWindowContainers(String name) {
3340 mName = name;
3341 }
3342
3343 void addChild(WindowToken token) {
3344 addChild(token, mWindowComparator);
3345 }
3346
3347 @Override
3348 String getName() {
3349 return mName;
3350 }
Robert Carr3b716242016-08-16 16:02:21 -07003351 }
Craig Mautner59c00972012-07-30 12:10:24 -07003352}