blob: 18568ba4f13723551429879ff18cbedd15716207 [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;
Craig Mautner59c00972012-07-30 12:10:24 -0700144
Craig Mautner59c00972012-07-30 12:10:24 -0700145/**
146 * Utility class for keeping track of the WindowStates and other pertinent contents of a
147 * particular Display.
148 *
149 * IMPORTANT: No method from this class should ever be used without holding
150 * WindowManagerService.mWindowMap.
151 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700152class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700153 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700154
155 /** Unique identifier of this stack. */
156 private final int mDisplayId;
157
Wale Ogunwale3a931692016-11-02 16:49:48 -0700158 /** The containers below are the only child containers the display can have. */
159 // Contains all window containers that are related to apps (Activities)
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700160 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers();
Wale Ogunwale3a931692016-11-02 16:49:48 -0700161 // Contains all non-app window containers that should be displayed above the app containers
162 // (e.g. Status bar)
163 private final NonAppWindowContainers mAboveAppWindowsContainers =
164 new NonAppWindowContainers("mAboveAppWindowsContainers");
165 // Contains all non-app window containers that should be displayed below the app containers
166 // (e.g. Wallpaper).
167 private final NonAppWindowContainers mBelowAppWindowsContainers =
168 new NonAppWindowContainers("mBelowAppWindowsContainers");
169 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
170 // on the IME target. We mainly have this container grouping so we can keep track of all the IME
171 // window containers together and move them in-sync if/when needed.
172 private final NonAppWindowContainers mImeWindowsContainers =
173 new NonAppWindowContainers("mImeWindowsContainers");
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700174
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000175 // Z-ordered (bottom-most first) list of all Window objects.
176 private final WindowList mWindows = new WindowList();
Craig Mautner59c00972012-07-30 12:10:24 -0700177
Wale Ogunwale02319a62016-09-26 15:21:22 -0700178 // Mapping from a token IBinder to a WindowToken object on this display.
179 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
180
Craig Mautner59c00972012-07-30 12:10:24 -0700181 int mInitialDisplayWidth = 0;
182 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700183 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -0700184 int mBaseDisplayWidth = 0;
185 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700186 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700187 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700188 private final DisplayInfo mDisplayInfo = new DisplayInfo();
189 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700190 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -0700191
Craig Mautner6601b7b2013-04-29 10:29:11 -0700192 Rect mBaseDisplayRect = new Rect();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700193 private Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700194
Craig Mautner39834192012-09-02 07:47:24 -0700195 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700196 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700197 int pendingLayoutChanges;
Andrii Kulian839def92016-11-02 10:58:58 -0700198 // TODO(multi-display): remove some of the usages.
Craig Mautner69b08182012-09-05 13:07:13 -0700199 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700200
Craig Mautnerdc548482014-02-05 13:35:24 -0800201 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700202 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800203
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800204 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
205 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -0700206 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700207
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700208 /** Detect user tapping outside of current focused task bounds .*/
209 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700210
Craig Mautner6601b7b2013-04-29 10:29:11 -0700211 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700212 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700213
Craig Mautner6601b7b2013-04-29 10:29:11 -0700214 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800215 private final Rect mTmpRect = new Rect();
216 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700217 private final RectF mTmpRectF = new RectF();
218 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800219 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700220
Craig Mautner9d808b12013-08-06 18:00:25 -0700221 final WindowManagerService mService;
222
Craig Mautner95da1082014-02-24 17:54:35 -0800223 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700224 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800225
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700226 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700227 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700228
Chong Zhang112eb8c2015-11-02 11:17:00 -0800229 final DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700230
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800231 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
232
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000233 /** Used when rebuilding window list to keep track of windows that have been removed. */
234 private WindowState[] mRebuildTmp = new WindowState[20];
235
236 /**
237 * Temporary list for comparison. Always clear this after use so we don't end up with
238 * orphaned windows references
239 */
240 private final ArrayList<WindowState> mTmpWindows = new ArrayList<>();
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700241
242 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
243
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700244 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
245 new TaskForResizePointSearchResult();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000246 private final GetWindowOnDisplaySearchResult mTmpGetWindowOnDisplaySearchResult =
247 new GetWindowOnDisplaySearchResult();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700248
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700249 // True if this display is in the process of being removed. Used to determine if the removal of
250 // the display's direct children should be allowed.
251 private boolean mRemovingDisplay = false;
252
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700253 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700254 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700255 int mInputMethodAnimLayerAdjustment;
256
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800257 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700258 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800259 * @param service You know.
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700260 * @param layersController window layer controller used to assign layer to the windows on this
261 * display.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700262 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
263 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700264 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700265 DisplayContent(Display display, WindowManagerService service,
Wale Ogunwale0303c572016-10-20 10:16:29 -0700266 WindowLayersController layersController, WallpaperController wallpaperController) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700267 mDisplay = display;
268 mDisplayId = display.getDisplayId();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700269 mLayersController = layersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700270 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700271 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700272 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700273 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700274 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700275 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800276 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700277 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800278 mDimLayerController = new DimLayerController(this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700279
280 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700281 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700282 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700283 super.addChild(mAboveAppWindowsContainers, null);
284 super.addChild(mImeWindowsContainers, null);
Craig Mautner59c00972012-07-30 12:10:24 -0700285 }
286
287 int getDisplayId() {
288 return mDisplayId;
289 }
290
Wale Ogunwale02319a62016-09-26 15:21:22 -0700291 WindowToken getWindowToken(IBinder binder) {
292 return mTokenMap.get(binder);
293 }
294
295 AppWindowToken getAppWindowToken(IBinder binder) {
296 final WindowToken token = getWindowToken(binder);
297 if (token == null) {
298 return null;
299 }
300 return token.asAppWindowToken();
301 }
302
303 void setWindowToken(IBinder binder, WindowToken token) {
304 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
305 if (dc != null) {
306 // We currently don't support adding a window token to the display if the display
307 // already has the binder mapped to another token. If there is a use case for supporting
308 // this moving forward we will either need to merge the WindowTokens some how or have
309 // the binder map to a list of window tokens.
310 throw new IllegalArgumentException("Can't map token=" + token + " to display=" + this
311 + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
312 }
313 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700314
315 if (token.asAppWindowToken() == null) {
316 // Add non-app token to container hierarchy on the display. App tokens are added through
317 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700318 switch (token.windowType) {
319 case TYPE_WALLPAPER:
320 mBelowAppWindowsContainers.addChild(token);
321 break;
322 case TYPE_INPUT_METHOD:
323 case TYPE_INPUT_METHOD_DIALOG:
324 mImeWindowsContainers.addChild(token);
325 break;
326 default:
327 mAboveAppWindowsContainers.addChild(token);
328 break;
329 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700330 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700331 }
332
333 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700334 final WindowToken token = mTokenMap.remove(binder);
335 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3a931692016-11-02 16:49:48 -0700336 switch (token.windowType) {
337 case TYPE_WALLPAPER:
338 mBelowAppWindowsContainers.removeChild(token);
339 break;
340 case TYPE_INPUT_METHOD:
341 case TYPE_INPUT_METHOD_DIALOG:
342 mImeWindowsContainers.removeChild(token);
343 break;
344 default:
345 mAboveAppWindowsContainers.removeChild(token);
346 break;
347 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700348 }
349 return token;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700350 }
351
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700352 void removeAppToken(IBinder binder) {
353 final WindowToken token = removeWindowToken(binder);
354 if (token == null) {
355 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
356 return;
357 }
358
359 final AppWindowToken appToken = token.asAppWindowToken();
360
361 if (appToken == null) {
362 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
363 return;
364 }
365
366 appToken.onRemovedFromDisplay();
367 }
368
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700369 Display getDisplay() {
370 return mDisplay;
371 }
372
Craig Mautner59c00972012-07-30 12:10:24 -0700373 DisplayInfo getDisplayInfo() {
374 return mDisplayInfo;
375 }
376
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700377 DisplayMetrics getDisplayMetrics() {
378 return mDisplayMetrics;
379 }
380
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100381 DockedStackDividerController getDockedDividerController() {
382 return mDividerControllerLocked;
383 }
384
Winson Chung655332c2016-10-31 13:14:28 -0700385 PinnedStackController getPinnedStackController() {
386 return mPinnedStackControllerLocked;
387 }
388
Jeff Browna506a6e2013-06-04 00:02:38 -0700389 /**
390 * Returns true if the specified UID has access to this display.
391 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700392 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700393 return mDisplay.hasAccess(uid);
394 }
395
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700396 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700397 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -0700398 }
399
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700400 TaskStack getHomeStack() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700401 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800402 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
Craig Mautnere0a38842013-12-16 16:14:02 -0800403 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700404 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700405 }
406
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700407 TaskStack getStackById(int stackId) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700408 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
409 final TaskStack stack = mTaskStackContainers.get(i);
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700410 if (stack.mStackId == stackId) {
411 return stack;
412 }
413 }
414 return null;
415 }
416
Andrii Kulian441e4492016-09-29 15:25:00 -0700417 @Override
418 void onConfigurationChanged(Configuration newParentConfig) {
419 super.onConfigurationChanged(newParentConfig);
420
Andrii Kulian3a507b52016-09-19 18:14:12 -0700421 // The display size information is heavily dependent on the resources in the current
422 // configuration, so we need to reconfigure it every time the configuration changes.
423 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
424 mService.reconfigureDisplayLocked(this);
425
426 getDockedDividerController().onConfigurationChanged();
Winson Chung655332c2016-10-31 13:14:28 -0700427 getPinnedStackController().onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700428 }
Andrii Kulian3a507b52016-09-19 18:14:12 -0700429
Andrii Kulian441e4492016-09-29 15:25:00 -0700430 /**
431 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
432 * bounds were updated.
433 */
434 void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700435 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
436 final TaskStack stack = mTaskStackContainers.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700437 if (stack.updateBoundsAfterConfigChange()) {
Andrii Kulian3a507b52016-09-19 18:14:12 -0700438 changedStackList.add(stack.mStackId);
439 }
440 }
441 }
442
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700443 @Override
444 boolean fillsParent() {
445 return true;
446 }
447
448 @Override
449 boolean isVisible() {
450 return true;
451 }
452
453 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700454 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700455 super.onAppTransitionDone();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000456 rebuildAppWindowList();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700457 }
458
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700459 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -0700460 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700461 final WindowManagerPolicy policy = mService.mPolicy;
462
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000463 // TODO: All the logic before the last return statement in this method should really go in
464 // #NonAppWindowContainer.getOrientation() since it is trying to decide orientation based
465 // on non-app windows. But, we can not do that until the window list is always correct in
466 // terms of z-ordering based on layers.
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700467 if (mService.mDisplayFrozen) {
468 if (mService.mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
469 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
470 "Display is frozen, return " + mService.mLastWindowForcedOrientation);
471 // If the display is frozen, some activities may be in the middle of restarting, and
472 // thus have removed their old window. If the window has the flag to hide the lock
473 // screen, then the lock screen can re-appear and inflict its own orientation on us.
474 // Keep the orientation stable until this all settles down.
475 return mService.mLastWindowForcedOrientation;
476 } else if (policy.isKeyguardLocked()) {
477 // Use the last orientation the while the display is frozen with the keyguard
478 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
479 // window. We don't want to check the show when locked window directly though as
480 // things aren't stable while the display is frozen, for example the window could be
481 // momentarily unavailable due to activity relaunch.
482 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
483 + "return " + mService.mLastOrientation);
484 return mService.mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -0700485 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700486 } else {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000487 for (int pos = mWindows.size() - 1; pos >= 0; --pos) {
488 final WindowState win = mWindows.get(pos);
489 if (win.mAppToken != null) {
490 // We hit an application window. so the orientation will be determined by the
491 // app window. No point in continuing further.
492 break;
493 }
494 if (!win.isVisibleLw() || !win.mPolicyVisibilityAfterAnim) {
495 continue;
496 }
497 int req = win.mAttrs.screenOrientation;
498 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND) {
499 continue;
500 }
501
502 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
503 if (policy.isKeyguardHostWindow(win.mAttrs)) {
504 mService.mLastKeyguardForcedOrientation = req;
505 }
506 return (mService.mLastWindowForcedOrientation = req);
507 }
508 mService.mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
509
510 if (policy.isKeyguardShowingAndNotOccluded()) {
511 return mService.mLastKeyguardForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700512 }
Wale Ogunwale51362492016-09-08 17:49:17 -0700513 }
514
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700515 // Top system windows are not requesting an orientation. Start searching from apps.
516 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -0700517 }
518
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700519 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700520 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700521 mDisplay.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700522 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
523 mTaskStackContainers.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800524 }
Craig Mautner722285e2012-09-07 13:55:58 -0700525 }
526
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700527 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700528 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
529 if (displayManagerInternal != null) {
530 // Bootstrap the default logical display from the display manager.
531 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
532 if (newDisplayInfo != null) {
533 mDisplayInfo.copyFrom(newDisplayInfo);
534 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700535 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700536
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800537 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
538 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
539 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
540 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700541 }
542
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700543 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700544 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800545 final int orientation = mDisplayInfo.rotation;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700546 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
Craig Mautner4a1cb222013-12-04 16:14:06 -0800547 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
548 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700549 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800550 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700551 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800552 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700553 out.set(left, top, left + width, top + height);
554 }
555
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700556 private void getLogicalDisplayRect(Rect out, int orientation) {
557 getLogicalDisplayRect(out);
558
559 // Rotate the Rect if needed.
560 final int currentRotation = mDisplayInfo.rotation;
561 final int rotationDelta = deltaRotation(currentRotation, orientation);
562 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
563 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
564 mTmpRectF.set(out);
565 mTmpMatrix.mapRect(mTmpRectF);
566 mTmpRectF.round(out);
567 }
568 }
569
Chong Zhangf66db432016-01-13 10:39:51 -0800570 void getContentRect(Rect out) {
571 out.set(mContentRect);
572 }
573
Andrii Kulian839def92016-11-02 10:58:58 -0700574 /**
575 * Adds the stack to this display.
576 * @see WindowManagerService#addStackToDisplay(int, int, boolean)
577 */
578 Rect addStackToDisplay(int stackId, boolean onTop) {
579 boolean attachedToDisplay = false;
580 TaskStack stack = mService.mStackIdToStack.get(stackId);
581 if (stack == null) {
582 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
583 + mDisplayId);
584
585 stack = getStackById(stackId);
586 if (stack != null) {
587 // It's already attached to the display...clear mDeferRemoval and move stack to
588 // appropriate z-order on display as needed.
589 stack.mDeferRemoval = false;
590 moveStack(stack, onTop);
591 attachedToDisplay = true;
592 } else {
593 stack = new TaskStack(mService, stackId);
594 }
595
596 mService.mStackIdToStack.put(stackId, stack);
597 if (stackId == DOCKED_STACK_ID) {
598 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
599 }
600 } else {
601 final DisplayContent currentDC = stack.getDisplayContent();
602 if (currentDC != null) {
603 throw new IllegalStateException("Trying to add stackId=" + stackId
604 + "to displayId=" + mDisplayId + ", but it's already attached to displayId="
605 + currentDC.getDisplayId());
606 }
607 }
608
609 if (!attachedToDisplay) {
610 mTaskStackContainers.addStackToDisplay(stack, onTop);
611 }
612
613 if (stack.getRawFullscreen()) {
614 return null;
615 }
616 final Rect bounds = new Rect();
617 stack.getRawBounds(bounds);
618 return bounds;
619 }
620
621 /** Removes the stack from the display and prepares for changing the parent. */
622 private void removeStackFromDisplay(TaskStack stack) {
623 mTaskStackContainers.removeStackFromDisplay(stack);
624 }
625
626 /** Moves the stack to this display and returns the updated bounds. */
627 Rect moveStackToDisplay(TaskStack stack) {
628 final DisplayContent currentDisplayContent = stack.getDisplayContent();
629 if (currentDisplayContent == null) {
630 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
631 + " which is not currently attached to any display");
632 }
633 if (stack.getDisplayContent().getDisplayId() == mDisplayId) {
634 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
635 + " to its current displayId=" + mDisplayId);
636 }
637
638 currentDisplayContent.removeStackFromDisplay(stack);
639 return addStackToDisplay(stack.mStackId, true /* onTop */);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800640 }
641
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800642 void moveStack(TaskStack stack, boolean toTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700643 mTaskStackContainers.moveStack(stack, toTop);
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700644 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700645
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700646 @Override
647 protected void addChild(DisplayChildWindowContainer child,
648 Comparator<DisplayChildWindowContainer> comparator) {
649 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
650 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700651
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700652 @Override
653 protected void addChild(DisplayChildWindowContainer child, int index) {
654 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
655 }
656
657 @Override
658 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700659 // Only allow removal of direct children from this display if the display is in the process
660 // of been removed.
661 if (mRemovingDisplay) {
662 super.removeChild(child);
663 return;
664 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700665 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800666 }
667
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700668 int taskIdFromPoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700669 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
670 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700671 final int taskId = stack.taskIdFromPoint(x, y);
672 if (taskId != -1) {
673 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -0700674 }
675 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800676 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700677 }
678
Chong Zhang8e89b312015-09-09 15:09:30 -0700679 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -0800680 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -0700681 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700682 */
Wale Ogunwale15ead902016-09-02 14:30:11 -0700683 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700684 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700685 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700686 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
687 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -0700688 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700689 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700690 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700691
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700692 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
693 if (mTmpTaskForResizePointSearchResult.searchDone) {
694 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -0700695 }
696 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700697 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700698 }
699
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700700 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700701 mTouchExcludeRegion.set(mBaseDisplayRect);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700702 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700703 mTmpRect2.setEmpty();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700704 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
705 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700706 stack.setTouchExcludeRegion(
707 focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2);
Craig Mautner6601b7b2013-04-29 10:29:11 -0700708 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800709 // If we removed the focused task above, add it back and only leave its
710 // outside touch area in the exclusion. TapDectector is not interested in
711 // any touch inside the focused task itself.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700712 if (!mTmpRect2.isEmpty()) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800713 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
714 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800715 final WindowState inputMethod = mService.mInputMethodWindow;
716 if (inputMethod != null && inputMethod.isVisibleLw()) {
717 // If the input method is visible and the user is typing, we don't want these touch
718 // events to be intercepted and used to change focus. This would likely cause a
719 // disappearance of the input method.
720 inputMethod.getTouchableRegion(mTmpRegion);
721 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
722 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800723 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
724 WindowState win = mTapExcludedWindows.get(i);
725 win.getTouchableRegion(mTmpRegion);
726 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
727 }
Andrii Kulian03c403d2016-11-11 11:14:12 -0800728 // TODO(multi-display): Support docked stacks on secondary displays.
729 if (mDisplayId == DEFAULT_DISPLAY && getDockedStackLocked() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100730 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -0700731 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100732 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
733 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800734 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700735 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -0800736 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700737 }
738
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700739 void switchUser() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000740 final int count = mWindows.size();
741 for (int i = 0; i < count; i++) {
742 final WindowState win = mWindows.get(i);
743 if (win.isHiddenFromUserLocked()) {
744 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win
745 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
746 win.hideLw(false);
747 }
748 }
749
750 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
751 mTaskStackContainers.get(stackNdx).switchUser();
752 }
753
754 rebuildAppWindowList();
Craig Mautner858d8a62013-04-23 17:08:34 -0700755 }
756
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700757 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700758 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
759 mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700760 }
761 }
762
763 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800764 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700765 }
766
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700767 private void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800768 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700769 }
770
771 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800772 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700773 }
774
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700775 private void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800776 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700777 }
778
Wale Ogunwale10124582016-09-15 20:25:50 -0700779 @Override
780 void removeIfPossible() {
781 if (isAnimating()) {
782 mDeferredRemoval = true;
783 return;
Craig Mautner2eb15342013-08-07 13:13:35 -0700784 }
Wale Ogunwale10124582016-09-15 20:25:50 -0700785 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -0700786 }
787
Wale Ogunwale10124582016-09-15 20:25:50 -0700788 @Override
789 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700790 mRemovingDisplay = true;
791 try {
792 super.removeImmediately();
793 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
794 mDimLayerController.close();
795 if (mDisplayId == DEFAULT_DISPLAY) {
796 mService.unregisterPointerEventListener(mTapDetector);
797 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
798 }
799 } finally {
800 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -0800801 }
Craig Mautner95da1082014-02-24 17:54:35 -0800802 }
803
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700804 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -0700805 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700806 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700807 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
808
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700809 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -0700810 removeImmediately();
Craig Mautner95da1082014-02-24 17:54:35 -0800811 mService.onDisplayRemoved(mDisplayId);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700812 return false;
Craig Mautner95da1082014-02-24 17:54:35 -0800813 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700814 return true;
Craig Mautner95da1082014-02-24 17:54:35 -0800815 }
816
Wale Ogunwale10124582016-09-15 20:25:50 -0700817 boolean animateForIme(float interpolatedValue, float animationTarget,
818 float dividerAnimationTarget) {
819 boolean updated = false;
820
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700821 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
822 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700823 if (stack == null || !stack.isAdjustedForIme()) {
824 continue;
825 }
826
827 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
828 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
829 updated = true;
830 } else {
831 mDividerControllerLocked.mLastAnimationProgress =
832 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
833 mDividerControllerLocked.mLastDividerProgress =
834 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
835 updated |= stack.updateAdjustForIme(
836 mDividerControllerLocked.mLastAnimationProgress,
837 mDividerControllerLocked.mLastDividerProgress,
838 false /* force */);
839 }
840 if (interpolatedValue >= 1f) {
841 stack.endImeAdjustAnimation();
842 }
843 }
844
845 return updated;
846 }
847
848 boolean clearImeAdjustAnimation() {
849 boolean changed = false;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700850 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
851 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700852 if (stack != null && stack.isAdjustedForIme()) {
853 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
854 changed = true;
855 }
856 }
857 return changed;
858 }
859
860 void beginImeAdjustAnimation() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700861 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
862 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700863 if (stack.isVisible() && stack.isAdjustedForIme()) {
864 stack.beginImeAdjustAnimation();
865 }
866 }
867 }
868
869 void adjustForImeIfNeeded() {
870 final WindowState imeWin = mService.mInputMethodWindow;
871 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
872 && !mDividerControllerLocked.isImeHideRequested();
873 final boolean dockVisible = mService.isStackVisibleLocked(DOCKED_STACK_ID);
874 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
875 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
876 imeTargetStack.getDockSide() : DOCKED_INVALID;
877 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
878 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
879 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
880 final int imeHeight = mService.mPolicy.getInputMethodWindowVisibleHeightLw();
881 final boolean imeHeightChanged = imeVisible &&
882 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
883
884 // The divider could be adjusted for IME position, or be thinner than usual,
885 // or both. There are three possible cases:
886 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
887 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
888 // - If IME is not visible, divider is not moved and is normal width.
889
890 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700891 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
892 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700893 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
894 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)) {
895 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
896 } else {
897 stack.resetAdjustedForIme(false);
898 }
899 }
900 mDividerControllerLocked.setAdjustedForIme(
901 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
902 } else {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700903 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
904 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700905 stack.resetAdjustedForIme(!dockVisible);
906 }
907 mDividerControllerLocked.setAdjustedForIme(
908 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
909 }
Winson Chung655332c2016-10-31 13:14:28 -0700910 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -0700911 }
912
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700913 void setInputMethodAnimLayerAdjustment(int adj) {
914 if (DEBUG_LAYERS) Slog.v(TAG_WM, "Setting im layer adj to " + adj);
915 mInputMethodAnimLayerAdjustment = adj;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000916 final WindowState imw = mService.mInputMethodWindow;
917 if (imw != null) {
918 imw.adjustAnimLayer(adj);
919 }
920 for (int i = mService.mInputMethodDialogs.size() - 1; i >= 0; i--) {
921 final WindowState dialog = mService.mInputMethodDialogs.get(i);
922 // TODO: This and other places setting mAnimLayer can probably use WS.adjustAnimLayer,
923 // but need to make sure we are not setting things twice for child windows that are
924 // already in the list.
925 dialog.mWinAnimator.mAnimLayer = dialog.mLayer + adj;
926 if (DEBUG_LAYERS) Slog.v(TAG_WM, "IM win " + imw
927 + " anim layer: " + dialog.mWinAnimator.mAnimLayer);
928 }
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700929 }
930
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700931 /**
932 * If a window that has an animation specifying a colored background and the current wallpaper
933 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
934 * suddenly disappear.
935 */
936 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +0000937 for (int i = mWindows.size() - 1; i >= 0; --i) {
938 final WindowState win = mWindows.get(i);
939 if (win.mIsWallpaper && win.isVisibleNow()) {
940 return win.mWinAnimator.mAnimLayer;
941 }
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700942 }
943 return winAnimator.mAnimLayer;
944 }
945
Wale Ogunwale10124582016-09-15 20:25:50 -0700946 void prepareFreezingTaskBounds() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700947 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
948 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -0700949 stack.prepareFreezingTaskBounds();
950 }
951 }
952
Wale Ogunwale94744212015-09-21 19:01:47 -0700953 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700954 getLogicalDisplayRect(mTmpRect, newRotation);
955
956 // Compute a transform matrix to undo the coordinate space transformation,
957 // and present the window at the same physical position it previously occupied.
958 final int deltaRotation = deltaRotation(newRotation, oldRotation);
959 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
960
961 mTmpRectF.set(bounds);
962 mTmpMatrix.mapRect(mTmpRectF);
963 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -0700964 }
965
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800966 static int deltaRotation(int oldRotation, int newRotation) {
967 int delta = newRotation - oldRotation;
968 if (delta < 0) delta += 4;
969 return delta;
970 }
971
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700972 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700973 Matrix outMatrix) {
974 // For rotations without Z-ordering we don't need the target rectangle's position.
975 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
976 displayHeight, outMatrix);
977 }
978
979 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
980 float displayWidth, float displayHeight, Matrix outMatrix) {
981 switch (rotation) {
982 case ROTATION_0:
983 outMatrix.reset();
984 break;
985 case ROTATION_270:
986 outMatrix.setRotate(270, 0, 0);
987 outMatrix.postTranslate(0, displayHeight);
988 outMatrix.postTranslate(rectTop, 0);
989 break;
990 case ROTATION_180:
991 outMatrix.reset();
992 break;
993 case ROTATION_90:
994 outMatrix.setRotate(90, 0, 0);
995 outMatrix.postTranslate(displayWidth, 0);
996 outMatrix.postTranslate(-rectTop, rectLeft);
997 break;
998 }
999 }
1000
Craig Mautnera91f9e22012-09-14 16:22:08 -07001001 public void dump(String prefix, PrintWriter pw) {
1002 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
1003 final String subPrefix = " " + prefix;
1004 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
1005 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
1006 pw.print("dpi");
1007 if (mInitialDisplayWidth != mBaseDisplayWidth
1008 || mInitialDisplayHeight != mBaseDisplayHeight
1009 || mInitialDisplayDensity != mBaseDisplayDensity) {
1010 pw.print(" base=");
1011 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
1012 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
1013 }
Jeff Brownd46747a2015-04-15 19:02:36 -07001014 if (mDisplayScalingDisabled) {
1015 pw.println(" noscale");
1016 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07001017 pw.print(" cur=");
1018 pw.print(mDisplayInfo.logicalWidth);
1019 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
1020 pw.print(" app=");
1021 pw.print(mDisplayInfo.appWidth);
1022 pw.print("x"); pw.print(mDisplayInfo.appHeight);
1023 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
1024 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
1025 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
1026 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001027 pw.println(subPrefix + "deferred=" + mDeferredRemoval
1028 + " mLayoutNeeded=" + mLayoutNeeded);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001029
Craig Mautnerdc548482014-02-05 13:35:24 -08001030 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001031 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001032 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
1033 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001034 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001035 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001036
Craig Mautnerdc548482014-02-05 13:35:24 -08001037 pw.println();
1038 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07001039 pw.println();
1040 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08001041 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001042 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001043 pw.print(" Exiting #"); pw.print(i);
1044 pw.print(' '); pw.print(token);
1045 pw.println(':');
1046 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08001047 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07001048 }
Craig Mautner59c00972012-07-30 12:10:24 -07001049 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001050 mDimLayerController.dump(prefix, pw);
Jorim Jaggi31f71702016-05-04 16:43:04 -07001051 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001052 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07001053 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07001054 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001055
1056 if (mInputMethodAnimLayerAdjustment != 0) {
1057 pw.println(subPrefix
1058 + "mInputMethodAnimLayerAdjustment=" + mInputMethodAnimLayerAdjustment);
1059 }
Craig Mautner59c00972012-07-30 12:10:24 -07001060 }
Craig Mautnere0a38842013-12-16 16:14:02 -08001061
1062 @Override
1063 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001064 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001065 }
1066
1067 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001068 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08001069 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001070
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001071 /**
1072 * @return The docked stack, but only if it is visible, and {@code null} otherwise.
1073 */
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001074 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -07001075 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001076 return (stack != null && stack.isVisible()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001077 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001078
1079 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001080 * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not
Jorim Jaggife762342016-10-13 14:33:27 +02001081 * visible.
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001082 */
Jorim Jaggife762342016-10-13 14:33:27 +02001083 TaskStack getDockedStackIgnoringVisibility() {
1084 return mService.mStackIdToStack.get(DOCKED_STACK_ID);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001085 }
1086
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001087 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001088 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001089 WindowState touchedWin = null;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001090 final int x = (int) xf;
1091 final int y = (int) yf;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001092
1093 for (int i = mWindows.size() - 1; i >= 0; i--) {
1094 WindowState window = mWindows.get(i);
1095 final int flags = window.mAttrs.flags;
1096 if (!window.isVisibleLw()) {
1097 continue;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001098 }
1099 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001100 continue;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001101 }
1102
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001103 window.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001104 if (!mTmpRect.contains(x, y)) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001105 continue;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001106 }
1107
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001108 window.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001109
1110 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001111 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
1112 touchedWin = window;
1113 break;
1114 }
1115 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08001116
1117 return touchedWin;
1118 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07001119
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001120 boolean canAddToastWindowForUid(int uid) {
1121 // We allow one toast window per UID being shown at a time.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001122 final int windowCount = mWindows.size();
1123 for (int i = 0; i < windowCount; i++) {
1124 final WindowState window = mWindows.get(i);
1125 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == uid
1126 && !window.mPermanentlyHidden && !window.mWindowRemovalAllowed) {
1127 return false;
1128 }
1129 }
1130 return true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001131 }
1132
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001133 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001134 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
1135 return;
1136 }
1137 final int lostFocusUid = oldFocus.mOwnerUid;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001138 final int windowCount = mWindows.size();
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001139 final Handler handler = mService.mH;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001140 for (int i = 0; i < windowCount; i++) {
1141 final WindowState window = mWindows.get(i);
1142 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == lostFocusUid) {
1143 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, window)) {
1144 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, window),
1145 window.mAttrs.hideTimeoutMilliseconds);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001146 }
1147 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001148 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001149 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001150
1151 WindowState findFocusedWindow() {
1152 final AppWindowToken focusedApp = mService.mFocusedApp;
1153
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001154 for (int i = mWindows.size() - 1; i >= 0; i--) {
1155 final WindowState win = mWindows.get(i);
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001156
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001157 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + i + " = " + win
1158 + ", flags=" + win.mAttrs.flags + ", canReceive=" + win.canReceiveKeys());
1159
1160 if (!win.canReceiveKeys()) {
1161 continue;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001162 }
1163
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001164 final AppWindowToken wtoken = win.mAppToken;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001165
1166 // If this window's application has been removed, just skip it.
1167 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
1168 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
1169 + (wtoken.removed ? "removed" : "sendingToBottom"));
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001170 continue;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001171 }
1172
1173 if (focusedApp == null) {
1174 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001175 + " using new focus @ " + i + " = " + win);
1176 return win;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001177 }
1178
1179 if (!focusedApp.windowsAreFocusable()) {
1180 // Current focused app windows aren't focusable...
1181 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001182 + " focusable using new focus @ " + i + " = " + win);
1183 return win;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001184 }
1185
1186 // Descend through all of the app tokens and find the first that either matches
1187 // win.mAppToken (return win) or mFocusedApp (return null).
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001188 if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001189 if (focusedApp.compareTo(wtoken) > 0) {
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001190 // App stack below focused app stack. No focus for you!!!
1191 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
1192 "findFocusedWindow: Reached focused app=" + focusedApp);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001193 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001194 }
1195 }
1196
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001197 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ "
1198 + i + " = " + win);
1199 return win;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001200 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001201
1202 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
1203 return null;
1204 }
1205
1206 void addAppWindowToWindowList(final WindowState win) {
1207 final IWindow client = win.mClient;
1208
1209 WindowList tokenWindowList = getTokenWindowsOnDisplay(win.mToken);
1210 if (!tokenWindowList.isEmpty()) {
1211 addAppWindowExisting(win, tokenWindowList);
1212 return;
1213 }
1214
1215 // No windows from this token on this display
1216 if (localLOGV) Slog.v(TAG_WM, "Figuring out where to add app window "
1217 + client.asBinder() + " (token=" + this + ")");
1218
1219 final WindowToken wToken = win.mToken;
1220
1221 // Figure out where the window should go, based on the order of applications.
1222 mTmpGetWindowOnDisplaySearchResult.reset();
1223 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1224 final TaskStack stack = mTaskStackContainers.get(i);
1225 stack.getWindowOnDisplayBeforeToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
1226 if (mTmpGetWindowOnDisplaySearchResult.reachedToken) {
1227 // We have reach the token we are interested in. End search.
1228 break;
1229 }
1230 }
1231
1232 WindowState pos = mTmpGetWindowOnDisplaySearchResult.foundWindow;
1233
1234 // We now know the index into the apps. If we found an app window above, that gives us the
1235 // position; else we need to look some more.
1236 if (pos != null) {
1237 // Move behind any windows attached to this one.
1238 final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
1239 if (atoken != null) {
1240 tokenWindowList = getTokenWindowsOnDisplay(atoken);
1241 final int NC = tokenWindowList.size();
1242 if (NC > 0) {
1243 WindowState bottom = tokenWindowList.get(0);
1244 if (bottom.mSubLayer < 0) {
1245 pos = bottom;
1246 }
1247 }
1248 }
1249 addWindowToListBefore(win, pos);
1250 return;
1251 }
1252
1253 // Continue looking down until we find the first token that has windows on this display.
1254 mTmpGetWindowOnDisplaySearchResult.reset();
1255 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1256 final TaskStack stack = mTaskStackContainers.get(i);
1257 stack.getWindowOnDisplayAfterToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
1258 if (mTmpGetWindowOnDisplaySearchResult.foundWindow != null) {
1259 // We have found a window after the token. End search.
1260 break;
1261 }
1262 }
1263
1264 pos = mTmpGetWindowOnDisplaySearchResult.foundWindow;
1265
1266 if (pos != null) {
1267 // Move in front of any windows attached to this one.
1268 final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
1269 if (atoken != null) {
1270 final WindowState top = atoken.getTopWindow();
1271 if (top != null && top.mSubLayer >= 0) {
1272 pos = top;
1273 }
1274 }
1275 addWindowToListAfter(win, pos);
1276 return;
1277 }
1278
1279 // Just search for the start of this layer.
1280 final int myLayer = win.mBaseLayer;
1281 int i;
1282 for (i = mWindows.size() - 1; i >= 0; --i) {
1283 final WindowState w = mWindows.get(i);
1284 // Dock divider shares the base layer with application windows, but we want to always
1285 // keep it above the application windows. The sharing of the base layer is intended
1286 // for window animations, which need to be above the dock divider for the duration
1287 // of the animation.
1288 if (w.mBaseLayer <= myLayer && w.mAttrs.type != TYPE_DOCK_DIVIDER) {
1289 break;
1290 }
1291 }
1292 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1293 "Based on layer: Adding window " + win + " at " + (i + 1) + " of "
1294 + mWindows.size());
1295 mWindows.add(i + 1, win);
1296 mService.mWindowsChanged = true;
1297 }
1298
1299 /** Adds this non-app window to the window list. */
1300 void addNonAppWindowToWindowList(WindowState win) {
1301 // Figure out where window should go, based on layer.
1302 int i;
1303 for (i = mWindows.size() - 1; i >= 0; i--) {
1304 final WindowState otherWin = mWindows.get(i);
1305 if (otherWin.getBaseType() != TYPE_WALLPAPER && otherWin.mBaseLayer <= win.mBaseLayer) {
1306 // Wallpaper wanders through the window list, for example to position itself
1307 // directly behind keyguard. Because of this it will break the ordering based on
1308 // WindowState.mBaseLayer. There might windows with higher mBaseLayer behind it and
1309 // we don't want the new window to appear above them. An example of this is adding
1310 // of the docked stack divider. Consider a scenario with the following ordering (top
1311 // to bottom): keyguard, wallpaper, assist preview, apps. We want the dock divider
1312 // to land below the assist preview, so the dock divider must ignore the wallpaper,
1313 // with which it shares the base layer.
1314 break;
1315 }
1316 }
1317
1318 i++;
1319 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1320 "Free window: Adding window " + this + " at " + i + " of " + mWindows.size());
1321 mWindows.add(i, win);
1322 mService.mWindowsChanged = true;
1323 }
1324
1325 void addToWindowList(WindowState win, int index) {
1326 mService.mWindowsChanged = true;
1327 mWindows.add(index, win);
1328 }
1329
1330 boolean removeFromWindowList(WindowState win) {
1331 mService.mWindowsChanged = true;
1332 return mWindows.remove(win);
1333 }
1334
1335 private int removeWindowAndChildrenFromWindowList(WindowState win, int interestingPos) {
1336 int wpos = mWindows.indexOf(win);
1337 if (wpos < 0) {
1338 return interestingPos;
1339 }
1340
1341 if (wpos < interestingPos) interestingPos--;
1342 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + this);
1343 mWindows.remove(wpos);
1344 mService.mWindowsChanged = true;
1345 int childWinCount = win.mChildren.size();
1346 while (childWinCount > 0) {
1347 childWinCount--;
1348 final WindowState cw = win.mChildren.get(childWinCount);
1349 int cpos = mWindows.indexOf(cw);
1350 if (cpos >= 0) {
1351 if (cpos < interestingPos) interestingPos--;
1352 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
1353 "Temp removing child at " + cpos + ": " + cw);
1354 mWindows.remove(cpos);
1355 }
1356 }
1357 return interestingPos;
1358 }
1359
1360 void addChildWindowToWindowList(WindowState win) {
1361 final WindowState parentWindow = win.getParentWindow();
1362
1363 WindowList windowsOnSameDisplay = getTokenWindowsOnDisplay(win.mToken);
1364
1365 // Figure out this window's ordering relative to the parent window.
1366 final int wCount = windowsOnSameDisplay.size();
1367 final int sublayer = win.mSubLayer;
1368 int largestSublayer = Integer.MIN_VALUE;
1369 WindowState windowWithLargestSublayer = null;
1370 int i;
1371 for (i = 0; i < wCount; i++) {
1372 WindowState w = windowsOnSameDisplay.get(i);
1373 final int wSublayer = w.mSubLayer;
1374 if (wSublayer >= largestSublayer) {
1375 largestSublayer = wSublayer;
1376 windowWithLargestSublayer = w;
1377 }
1378 if (sublayer < 0) {
1379 // For negative sublayers, we go below all windows in the same sublayer.
1380 if (wSublayer >= sublayer) {
1381 addWindowToListBefore(win, wSublayer >= 0 ? parentWindow : w);
1382 break;
1383 }
1384 } else {
1385 // For positive sublayers, we go above all windows in the same sublayer.
1386 if (wSublayer > sublayer) {
1387 addWindowToListBefore(win, w);
1388 break;
1389 }
1390 }
1391 }
1392 if (i >= wCount) {
1393 if (sublayer < 0) {
1394 addWindowToListBefore(win, parentWindow);
1395 } else {
1396 addWindowToListAfter(win,
1397 largestSublayer >= 0 ? windowWithLargestSublayer : parentWindow);
1398 }
1399 }
Wale Ogunwaleec731152016-09-08 20:18:57 -07001400 }
1401
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001402 /** Updates the layer assignment of windows on this display. */
1403 void assignWindowLayers(boolean setLayoutNeeded) {
Wale Ogunwaled1880962016-11-08 10:31:59 -08001404 mLayersController.assignWindowLayers(this);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001405 if (setLayoutNeeded) {
1406 setLayoutNeeded();
1407 }
1408 }
1409
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001410 void adjustWallpaperWindows() {
1411 mWallpaperController.adjustWallpaperWindows(this);
1412 }
1413
1414 /**
1415 * Z-orders the display window list so that:
1416 * <ul>
1417 * <li>Any windows that are currently below the wallpaper window stay below the wallpaper
1418 * window.
1419 * <li>Exiting application windows are at the bottom, but above the wallpaper window.
1420 * <li>All other application windows are above the exiting application windows and ordered based
1421 * on the ordering of their stacks and tasks on the display.
1422 * <li>Non-application windows are at the very top.
1423 * </ul>
1424 * <p>
1425 * NOTE: This isn't a complete picture of what the user see. Further manipulation of the window
1426 * surface layering is done in {@link WindowLayersController}.
1427 */
1428 void rebuildAppWindowList() {
1429 int count = mWindows.size();
1430 int i;
1431 int lastBelow = -1;
1432 int numRemoved = 0;
1433
1434 if (mRebuildTmp.length < count) {
1435 mRebuildTmp = new WindowState[count + 10];
1436 }
1437
1438 // First remove all existing app windows.
1439 i = 0;
1440 while (i < count) {
1441 final WindowState w = mWindows.get(i);
1442 if (w.mAppToken != null) {
1443 final WindowState win = mWindows.remove(i);
1444 win.mRebuilding = true;
1445 mRebuildTmp[numRemoved] = win;
1446 mService.mWindowsChanged = true;
1447 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Rebuild removing window: " + win);
1448 count--;
1449 numRemoved++;
1450 continue;
1451 } else if (lastBelow == i-1) {
1452 if (w.mAttrs.type == TYPE_WALLPAPER) {
1453 lastBelow = i;
1454 }
1455 }
1456 i++;
1457 }
1458
1459 // Keep whatever windows were below the app windows still below, by skipping them.
1460 lastBelow++;
1461 i = lastBelow;
1462
1463 // First add all of the exiting app tokens... these are no longer in the main app list,
1464 // but still have windows shown. We put them in the back because now that the animation is
1465 // over we no longer will care about them.
1466 final int numStacks = mTaskStackContainers.size();
1467 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
1468 AppTokenList exitingAppTokens = mTaskStackContainers.get(stackNdx).mExitingAppTokens;
1469 int NT = exitingAppTokens.size();
1470 for (int j = 0; j < NT; j++) {
1471 i = exitingAppTokens.get(j).rebuildWindowListUnchecked(i);
1472 }
1473 }
1474
1475 // And add in the still active app tokens in Z order.
1476 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
1477 i = mTaskStackContainers.get(stackNdx).rebuildWindowList(i);
1478 }
1479
1480 i -= lastBelow;
1481 if (i != numRemoved) {
1482 setLayoutNeeded();
1483 Slog.w(TAG_WM, "On display=" + mDisplayId + " Rebuild removed " + numRemoved
1484 + " windows but added " + i + " rebuildAppWindowListLocked() "
1485 + " callers=" + Debug.getCallers(10));
1486 for (i = 0; i < numRemoved; i++) {
1487 WindowState ws = mRebuildTmp[i];
1488 if (ws.mRebuilding) {
1489 StringWriter sw = new StringWriter();
1490 PrintWriter pw = new FastPrintWriter(sw, false, 1024);
1491 ws.dump(pw, "", true);
1492 pw.flush();
1493 Slog.w(TAG_WM, "This window was lost: " + ws);
1494 Slog.w(TAG_WM, sw.toString());
1495 ws.mWinAnimator.destroySurfaceLocked();
1496 }
1497 }
1498 Slog.w(TAG_WM, "Current window hierarchy:");
1499 dumpChildrenNames();
1500 Slog.w(TAG_WM, "Final window list:");
1501 dumpWindows();
1502 }
1503 Arrays.fill(mRebuildTmp, null);
1504 }
1505
1506 /** Rebuilds the display's window list and does a relayout if something changed. */
1507 void rebuildAppWindowsAndLayoutIfNeeded() {
1508 mTmpWindows.clear();
1509 mTmpWindows.addAll(mWindows);
1510
1511 rebuildAppWindowList();
1512
1513 // Set displayContent.mLayoutNeeded if window order changed.
1514 final int tmpSize = mTmpWindows.size();
1515 final int winSize = mWindows.size();
1516 int tmpNdx = 0, winNdx = 0;
1517 while (tmpNdx < tmpSize && winNdx < winSize) {
1518 // Skip over all exiting windows, they've been moved out of order.
1519 WindowState tmp;
1520 do {
1521 tmp = mTmpWindows.get(tmpNdx++);
1522 } while (tmpNdx < tmpSize && tmp.mAppToken != null && tmp.mAppToken.mIsExiting);
1523
1524 WindowState win;
1525 do {
1526 win = mWindows.get(winNdx++);
1527 } while (winNdx < winSize && win.mAppToken != null && win.mAppToken.mIsExiting);
1528
1529 if (tmp != win) {
1530 // Window order changed.
1531 setLayoutNeeded();
1532 break;
1533 }
1534 }
1535 if (tmpNdx != winNdx) {
1536 // One list was different from the other.
1537 setLayoutNeeded();
1538 }
1539 mTmpWindows.clear();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001540
1541 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
1542 false /*updateInputWindows*/)) {
1543 assignWindowLayers(false /* setLayoutNeeded */);
1544 }
1545
1546 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
1547 mService.mWindowPlacerLocked.performSurfacePlacement();
1548 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1549 }
1550
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001551 void updateInputWindows(InputMonitor inputMonitor, WindowState inputFocus, boolean inDrag) {
1552 final InputConsumerImpl navInputConsumer =
1553 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_NAVIGATION, mDisplayId);
1554 final InputConsumerImpl pipInputConsumer =
1555 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_PIP, mDisplayId);
1556 final InputConsumerImpl wallpaperInputConsumer =
1557 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_WALLPAPER, mDisplayId);
1558 boolean addInputConsumerHandle = navInputConsumer != null;
1559 boolean addPipInputConsumerHandle = pipInputConsumer != null;
1560 boolean addWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
1561 final Rect pipTouchableBounds = addPipInputConsumerHandle ? new Rect() : null;
1562 boolean disableWallpaperTouchEvents = false;
1563
1564 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
1565 final WindowState child = mWindows.get(winNdx);
1566 final InputChannel inputChannel = child.mInputChannel;
1567 final InputWindowHandle inputWindowHandle = child.mInputWindowHandle;
1568 if (inputChannel == null || inputWindowHandle == null || child.mRemoved
1569 || child.isAdjustedForMinimizedDock()) {
1570 // Skip this window because it cannot possibly receive input.
1571 continue;
1572 }
1573
1574 if (addPipInputConsumerHandle
1575 && child.getStackId() == PINNED_STACK_ID
1576 && inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer) {
1577 // Update the bounds of the Pip input consumer to match the Pinned stack
1578 child.getStack().getBounds(pipTouchableBounds);
1579 pipInputConsumer.mWindowHandle.touchableRegion.set(pipTouchableBounds);
1580 inputMonitor.addInputWindowHandle(pipInputConsumer.mWindowHandle);
1581 addPipInputConsumerHandle = false;
1582 }
1583
1584 if (addInputConsumerHandle
1585 && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) {
1586 inputMonitor.addInputWindowHandle(navInputConsumer.mWindowHandle);
1587 addInputConsumerHandle = false;
1588 }
1589
1590 if (addWallpaperInputConsumerHandle) {
1591 if (child.mAttrs.type == TYPE_WALLPAPER && child.isVisibleLw()) {
1592 // Add the wallpaper input consumer above the first visible wallpaper.
1593 inputMonitor.addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
1594 addWallpaperInputConsumerHandle = false;
1595 }
1596 }
1597
1598 final int flags = child.mAttrs.flags;
1599 final int privateFlags = child.mAttrs.privateFlags;
1600 final int type = child.mAttrs.type;
1601
1602 final boolean hasFocus = child == inputFocus;
1603 final boolean isVisible = child.isVisibleLw();
1604 if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
1605 disableWallpaperTouchEvents = true;
1606 }
1607 final boolean hasWallpaper = mWallpaperController.isWallpaperTarget(child)
1608 && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
1609 && !disableWallpaperTouchEvents;
1610
1611 // If there's a drag in progress and 'child' is a potential drop target,
1612 // make sure it's been told about the drag
1613 if (inDrag && isVisible && isDefaultDisplay) {
1614 mService.mDragState.sendDragStartedIfNeededLw(child);
1615 }
1616
1617 inputMonitor.addInputWindowHandle(
1618 inputWindowHandle, child, flags, type, isVisible, hasFocus, hasWallpaper);
1619 }
1620
1621 if (addWallpaperInputConsumerHandle) {
1622 // No visible wallpaper found, add the wallpaper input consumer at the end.
1623 inputMonitor.addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
1624 }
1625 }
1626
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001627 /** Returns true if a leaked surface was destroyed */
1628 boolean destroyLeakedSurfaces() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001629 boolean leakedSurface = false;
1630 final int numWindows = mWindows.size();
1631 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
1632 final WindowState ws = mWindows.get(winNdx);
1633 final WindowStateAnimator wsa = ws.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001634 if (wsa.mSurfaceController == null) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001635 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001636 }
1637 if (!mService.mSessions.contains(wsa.mSession)) {
1638 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001639 + ws + " surface=" + wsa.mSurfaceController
1640 + " token=" + ws.mToken
1641 + " pid=" + ws.mSession.mPid
1642 + " uid=" + ws.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001643 wsa.destroySurface();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001644 mService.mForceRemoves.add(ws);
1645 leakedSurface = true;
1646 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001647 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001648 + ws + " surface=" + wsa.mSurfaceController
1649 + " token=" + ws.mAppToken
1650 + " saved=" + ws.hasSavedSurface());
1651 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001652 wsa.destroySurface();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001653 leakedSurface = true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001654 }
1655 }
1656
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001657 return leakedSurface;
1658 }
1659
1660 /** Return the list of Windows on this display associated with the input token. */
1661 WindowList getTokenWindowsOnDisplay(WindowToken token) {
1662 final WindowList windowList = new WindowList();
1663 final int count = mWindows.size();
1664 for (int i = 0; i < count; i++) {
1665 final WindowState win = mWindows.get(i);
1666 if (win.mToken == token) {
1667 windowList.add(win);
1668 }
1669 }
1670 return windowList;
1671 }
1672
1673 private void reAddToWindowList(WindowState win) {
1674 win.mToken.addWindow(win);
1675 // This is a hack to get all of the child windows added as well at the right position. Child
1676 // windows should be rare and this case should be rare, so it shouldn't be that big a deal.
1677 int wpos = mWindows.indexOf(win);
1678 if (wpos >= 0) {
1679 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "ReAdd removing from " + wpos + ": " + win);
1680 mWindows.remove(wpos);
1681 mService.mWindowsChanged = true;
1682 win.reAddWindow(wpos);
1683 }
1684 }
1685
1686 void moveInputMethodDialogs(int pos) {
1687 ArrayList<WindowState> dialogs = mService.mInputMethodDialogs;
1688
1689 final int N = dialogs.size();
1690 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Removing " + N + " dialogs w/pos=" + pos);
1691 for (int i = 0; i < N; i++) {
1692 pos = removeWindowAndChildrenFromWindowList(dialogs.get(i), pos);
1693 }
1694 if (DEBUG_INPUT_METHOD) {
1695 Slog.v(TAG_WM, "Window list w/pos=" + pos);
1696 logWindowList(mWindows, " ");
1697 }
1698
1699 WindowState ime = mService.mInputMethodWindow;
1700 if (pos >= 0) {
1701 // Skip windows owned by the input method.
1702 if (ime != null) {
1703 while (pos < mWindows.size()) {
1704 WindowState wp = mWindows.get(pos);
1705 if (wp == ime || wp.getParentWindow() == ime) {
1706 pos++;
1707 continue;
1708 }
1709 break;
1710 }
1711 }
1712 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Adding " + N + " dialogs at pos=" + pos);
1713 for (int i=0; i<N; i++) {
1714 WindowState win = dialogs.get(i);
1715 pos = win.reAddWindow(pos);
1716 }
1717 if (DEBUG_INPUT_METHOD) {
1718 Slog.v(TAG_WM, "Final window list:");
1719 logWindowList(mWindows, " ");
1720 }
1721 return;
1722 }
1723 for (int i=0; i<N; i++) {
1724 WindowState win = dialogs.get(i);
1725 reAddToWindowList(win);
1726 if (DEBUG_INPUT_METHOD) {
1727 Slog.v(TAG_WM, "No IM target, final list:");
1728 logWindowList(mWindows, " ");
1729 }
1730 }
1731 }
1732
1733 boolean moveInputMethodWindowsIfNeeded(boolean needAssignLayers) {
1734 final WindowState imWin = mService.mInputMethodWindow;
1735 final int DN = mService.mInputMethodDialogs.size();
1736 if (imWin == null && DN == 0) {
1737 return false;
1738 }
1739
1740 // TODO(multidisplay): IMEs are only supported on the default display.
1741 int imPos = findDesiredInputMethodWindowIndex(true);
1742 if (imPos >= 0) {
1743 // In this case, the input method windows are to be placed
1744 // immediately above the window they are targeting.
1745
1746 // First check to see if the input method windows are already
1747 // located here, and contiguous.
1748 final int N = mWindows.size();
1749 final WindowState firstImWin = imPos < N ? mWindows.get(imPos) : null;
1750
1751 // Figure out the actual input method window that should be
1752 // at the bottom of their stack.
1753 WindowState baseImWin = imWin != null ? imWin : mService.mInputMethodDialogs.get(0);
1754 final WindowState cw = baseImWin.getBottomChild();
1755 if (cw != null && cw.mSubLayer < 0) {
1756 baseImWin = cw;
1757 }
1758
1759 if (firstImWin == baseImWin) {
1760 // The windows haven't moved... but are they still contiguous?
1761 // First find the top IM window.
1762 int pos = imPos+1;
1763 while (pos < N) {
1764 if (!(mWindows.get(pos)).mIsImWindow) {
1765 break;
1766 }
1767 pos++;
1768 }
1769 pos++;
1770 // Now there should be no more input method windows above.
1771 while (pos < N) {
1772 if ((mWindows.get(pos)).mIsImWindow) {
1773 break;
1774 }
1775 pos++;
1776 }
1777 if (pos >= N) {
1778 return false;
1779 }
1780 }
1781
1782 if (imWin != null) {
1783 if (DEBUG_INPUT_METHOD) {
1784 Slog.v(TAG_WM, "Moving IM from " + imPos);
1785 logWindowList(mWindows, " ");
1786 }
1787 imPos = removeWindowAndChildrenFromWindowList(imWin, imPos);
1788 if (DEBUG_INPUT_METHOD) {
1789 Slog.v(TAG_WM, "List after removing with new pos " + imPos + ":");
1790 logWindowList(mWindows, " ");
1791 }
1792 imWin.reAddWindow(imPos);
1793 if (DEBUG_INPUT_METHOD) {
1794 Slog.v(TAG_WM, "List after moving IM to " + imPos + ":");
1795 logWindowList(mWindows, " ");
1796 }
1797 if (DN > 0) moveInputMethodDialogs(imPos+1);
1798 } else {
1799 moveInputMethodDialogs(imPos);
1800 }
1801
1802 } else {
1803 // In this case, the input method windows go in a fixed layer,
1804 // because they aren't currently associated with a focus window.
1805
1806 if (imWin != null) {
1807 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Moving IM from " + imPos);
1808 removeWindowAndChildrenFromWindowList(imWin, 0);
1809 reAddToWindowList(imWin);
1810 if (DEBUG_INPUT_METHOD) {
1811 Slog.v(TAG_WM, "List with no IM target:");
1812 logWindowList(mWindows, " ");
1813 }
1814 if (DN > 0) moveInputMethodDialogs(-1);
1815 } else {
1816 moveInputMethodDialogs(-1);
1817 }
1818
1819 }
1820
1821 if (needAssignLayers) {
1822 assignWindowLayers(false /* setLayoutNeeded */);
1823 }
1824
1825 return true;
1826 }
1827
1828 /**
1829 * Dig through the WindowStates and find the one that the Input Method will target.
1830 * @param willMove
1831 * @return The index+1 in mWindows of the discovered target.
1832 */
1833 int findDesiredInputMethodWindowIndex(boolean willMove) {
1834 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
1835 // same display. Or even when the current IME/target are not on the same screen as the next
1836 // IME/target. For now only look for input windows on the main screen.
1837 WindowState w = null;
1838 int i;
1839 for (i = mWindows.size() - 1; i >= 0; --i) {
1840 final WindowState win = mWindows.get(i);
1841
1842 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG_WM, "Checking window @" + i
1843 + " " + win + " fl=0x" + Integer.toHexString(win.mAttrs.flags));
1844 if (canBeImeTarget(win)) {
1845 w = win;
1846 //Slog.i(TAG_WM, "Putting input method here!");
1847
1848 // Yet more tricksyness! If this window is a "starting" window, we do actually want
1849 // to be on top of it, but it is not -really- where input will go. So if the caller
1850 // is not actually looking to move the IME, look down below for a real window to
1851 // target...
1852 if (!willMove && w.mAttrs.type == TYPE_APPLICATION_STARTING && i > 0) {
1853 final WindowState wb = mWindows.get(i-1);
1854 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1855 i--;
1856 w = wb;
1857 }
1858 }
1859 break;
1860 }
1861 }
1862
1863 // Now w is either mWindows[0] or an IME (or null if mWindows is empty).
1864
1865 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG_WM, "Proposed new IME target: " + w);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001866
1867 // Now, a special case -- if the last target's window is in the process of exiting, and is
1868 // above the new target, keep on the last target to avoid flicker. Consider for example a
1869 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
1870 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
1871 // scrim.
1872 final WindowState curTarget = mService.mInputMethodTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001873 if (curTarget != null
1874 && curTarget.isDisplayedLw()
1875 && curTarget.isClosing()
1876 && (w == null || curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001877 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001878 return mWindows.indexOf(curTarget) + 1;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001879 }
1880
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001881 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target="
1882 + w + " willMove=" + willMove);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001883
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001884 if (willMove && w != null) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001885 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
1886 if (token != null) {
1887
1888 // Now some fun for dealing with window animations that modify the Z order. We need
1889 // to look at all windows below the current target that are in this app, finding the
1890 // highest visible one in layering.
1891 WindowState highestTarget = null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001892 int highestPos = 0;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001893 if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001894 WindowList curWindows = token.getDisplayContent().mWindows;
1895 int pos = curWindows.indexOf(curTarget);
1896 while (pos >= 0) {
1897 WindowState win = curWindows.get(pos);
1898 if (win.mAppToken != token) {
1899 break;
1900 }
1901 if (!win.mRemoved) {
1902 if (highestTarget == null || win.mWinAnimator.mAnimLayer >
1903 highestTarget.mWinAnimator.mAnimLayer) {
1904 highestTarget = win;
1905 highestPos = pos;
1906 }
1907 }
1908 pos--;
1909 }
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001910 }
1911
1912 if (highestTarget != null) {
1913 final AppTransition appTransition = mService.mAppTransition;
1914 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
1915 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
1916 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001917 + " new layer=" + w.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001918
1919 if (appTransition.isTransitionSet()) {
1920 // If we are currently setting up for an animation, hold everything until we
1921 // can find out what will happen.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001922 mService.mInputMethodTargetWaitingAnim = true;
1923 mService.mInputMethodTarget = highestTarget;
1924 return highestPos + 1;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001925 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001926 highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001927 // If the window we are currently targeting is involved with an animation,
1928 // and it is on top of the next target we will be over, then hold off on
1929 // moving until that is done.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001930 mService.mInputMethodTargetWaitingAnim = true;
1931 mService.mInputMethodTarget = highestTarget;
1932 return highestPos + 1;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001933 }
1934 }
1935 }
1936 }
1937
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001938 //Slog.i(TAG_WM, "Placing input method @" + (i+1));
1939 if (w != null) {
1940 if (willMove) {
1941 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
1942 + w + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
1943 mService.mInputMethodTarget = w;
1944 mService.mInputMethodTargetWaitingAnim = false;
1945 if (w.mAppToken != null) {
1946 setInputMethodAnimLayerAdjustment(
1947 w.mAppToken.mAppAnimator.animLayerAdjustment);
1948 } else {
1949 setInputMethodAnimLayerAdjustment(0);
1950 }
Wale Ogunwale4551c8b2016-11-10 10:25:20 -08001951 }
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001952
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00001953 // If the docked divider is visible, we still need to go through this whole excercise to
1954 // find the appropriate input method target (used for animations and dialog
1955 // adjustments), but for purposes of Z ordering we simply wish to place it above the
1956 // docked divider. Unless it is already above the divider.
1957 final WindowState dockedDivider = mDividerControllerLocked.getWindow();
1958 if (dockedDivider != null && dockedDivider.isVisibleLw()) {
1959 int dividerIndex = mWindows.indexOf(dockedDivider);
1960 if (dividerIndex > 0 && dividerIndex > i) {
1961 return dividerIndex + 1;
1962 }
1963 }
1964 return i+1;
1965 }
1966 if (willMove) {
1967 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
1968 + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
1969 mService.mInputMethodTarget = null;
1970 setInputMethodAnimLayerAdjustment(0);
1971 }
1972 return -1;
1973 }
1974
1975 private static boolean canBeImeTarget(WindowState w) {
1976 final int fl = w.mAttrs.flags & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1977 final int type = w.mAttrs.type;
1978
1979 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
1980 && type != TYPE_APPLICATION_STARTING) {
1981 return false;
1982 }
1983
1984 if (DEBUG_INPUT_METHOD) {
1985 Slog.i(TAG_WM, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1986 if (!w.isVisibleOrAdding()) {
1987 Slog.i(TAG_WM, " mSurfaceController=" + w.mWinAnimator.mSurfaceController
1988 + " relayoutCalled=" + w.mRelayoutCalled
1989 + " viewVis=" + w.mViewVisibility
1990 + " policyVis=" + w.mPolicyVisibility
1991 + " policyVisAfterAnim=" + w.mPolicyVisibilityAfterAnim
1992 + " parentHidden=" + w.isParentWindowHidden()
1993 + " exiting=" + w.mAnimatingExit + " destroying=" + w.mDestroying);
1994 if (w.mAppToken != null) {
1995 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1996 }
1997 }
1998 }
1999 return w.isVisibleOrAdding();
2000 }
2001
2002 private void logWindowList(final WindowList windows, String prefix) {
2003 int N = windows.size();
2004 while (N > 0) {
2005 N--;
2006 Slog.v(TAG_WM, prefix + "#" + N + ": " + windows.get(N));
2007 }
2008 }
2009
2010 boolean getNeedsMenu(WindowState win, WindowManagerPolicy.WindowState bottom) {
2011 int index = -1;
2012 while (true) {
2013 if (win.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2014 return win.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002015 }
2016 // If we reached the bottom of the range of windows we are considering,
2017 // assume no menu is needed.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002018 if (win == bottom) {
2019 return false;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002020 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002021 // The current window hasn't specified whether menu key is needed; look behind it.
2022 // First, we may need to determine the starting position.
2023 if (index < 0) {
2024 index = mWindows.indexOf(win);
2025 }
2026 index--;
2027 if (index < 0) {
2028 return false;
2029 }
2030 win = mWindows.get(index);
2031 }
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002032 }
2033
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002034 void setLayoutNeeded() {
2035 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2036 mLayoutNeeded = true;
2037 }
2038
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002039 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002040 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2041 mLayoutNeeded = false;
2042 }
2043
2044 boolean isLayoutNeeded() {
2045 return mLayoutNeeded;
2046 }
2047
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002048 private void addAppWindowExisting(WindowState win, WindowList tokenWindowList) {
2049
2050 // If this application has existing windows, we simply place the new window on top of
2051 // them... but keep the starting window on top.
2052 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
2053 // Base windows go behind everything else.
2054 final WindowState lowestWindow = tokenWindowList.get(0);
2055 addWindowToListBefore(win, lowestWindow);
2056 } else {
2057 final AppWindowToken atoken = win.mAppToken;
2058 final int windowListPos = tokenWindowList.size();
2059 final WindowState lastWindow = tokenWindowList.get(windowListPos - 1);
2060 if (atoken != null && lastWindow == atoken.startingWindow) {
2061 addWindowToListBefore(win, lastWindow);
2062 } else {
2063 int newIdx = findIdxBasedOnAppTokens(win);
2064 // There is a window above this one associated with the same apptoken note that the
2065 // window could be a floating window that was created later or a window at the top
2066 // of the list of windows associated with this token.
2067 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2068 "not Base app: Adding window " + win + " at " + (newIdx + 1) + " of "
2069 + mWindows.size());
2070 mWindows.add(newIdx + 1, win);
2071 mService.mWindowsChanged = true;
2072 }
2073 }
2074 }
2075
2076 /** Places the first input window after the second input window in the window list. */
2077 private void addWindowToListAfter(WindowState first, WindowState second) {
2078 final int i = mWindows.indexOf(second);
2079 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2080 "Adding window " + this + " at " + (i + 1) + " of " + mWindows.size()
2081 + " (after " + second + ")");
2082 mWindows.add(i + 1, first);
2083 mService.mWindowsChanged = true;
2084 }
2085
2086 /** Places the first input window before the second input window in the window list. */
2087 private void addWindowToListBefore(WindowState first, WindowState second) {
2088 int i = mWindows.indexOf(second);
2089 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2090 "Adding window " + this + " at " + i + " of " + mWindows.size()
2091 + " (before " + second + ")");
2092 if (i < 0) {
2093 Slog.w(TAG_WM, "addWindowToListBefore: Unable to find " + second + " in " + mWindows);
2094 i = 0;
2095 }
2096 mWindows.add(i, first);
2097 mService.mWindowsChanged = true;
2098 }
2099
2100 /**
2101 * This method finds out the index of a window that has the same app token as win. used for z
2102 * ordering the windows in mWindows
2103 */
2104 private int findIdxBasedOnAppTokens(WindowState win) {
2105 for(int j = mWindows.size() - 1; j >= 0; j--) {
2106 final WindowState wentry = mWindows.get(j);
2107 if(wentry.mAppToken == win.mAppToken) {
2108 return j;
2109 }
2110 }
2111 return -1;
2112 }
2113
2114 private void dumpChildrenNames() {
2115 StringBuilder output = new StringBuilder();
2116 dumpChildrenNames(output, " ");
2117 Slog.v(TAG_WM, output.toString());
2118 }
2119
2120 private void dumpWindows() {
2121 Slog.v(TAG_WM, " Display #" + mDisplayId);
2122 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
2123 Slog.v(TAG_WM, " #" + winNdx + ": " + mWindows.get(winNdx));
2124 }
2125 }
2126
Wale Ogunwale02319a62016-09-26 15:21:22 -07002127 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2128 if (mTokenMap.isEmpty()) {
2129 return;
2130 }
2131 pw.println(" Display #" + mDisplayId);
2132 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2133 while (it.hasNext()) {
2134 final WindowToken token = it.next();
2135 pw.print(" ");
2136 pw.print(token);
2137 if (dumpAll) {
2138 pw.println(':');
2139 token.dump(pw, " ");
2140 } else {
2141 pw.println();
2142 }
2143 }
2144 }
2145
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002146 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002147 final int count = mWindows.size();
2148 for (int j = 0; j < count; j++) {
2149 final WindowStateAnimator wAnim = mWindows.get(j).mWinAnimator;
2150 pw.println(subPrefix + "Window #" + j + ": " + wAnim);
2151 }
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002152 }
2153
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002154 void enableSurfaceTrace(FileDescriptor fd) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002155 for (int i = mWindows.size() - 1; i >= 0; i--) {
2156 final WindowState win = mWindows.get(i);
2157 win.mWinAnimator.enableSurfaceTrace(fd);
2158 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002159 }
2160
2161 void disableSurfaceTrace() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002162 for (int i = mWindows.size() - 1; i >= 0; i--) {
2163 final WindowState win = mWindows.get(i);
2164 win.mWinAnimator.disableSurfaceTrace();
2165 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002166 }
2167
Jorim Jaggife762342016-10-13 14:33:27 +02002168 /**
2169 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2170 */
2171 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2172 final WindowManagerPolicy policy = mService.mPolicy;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002173 for (int i = mWindows.size() - 1; i >= 0; i--) {
2174 final WindowState window = mWindows.get(i);
2175 if (window.mAppToken == null && policy.canBeHiddenByKeyguardLw(window)) {
2176 window.mWinAnimator.setAnimation(
Jorim Jaggife762342016-10-13 14:33:27 +02002177 policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
2178 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002179 }
Jorim Jaggife762342016-10-13 14:33:27 +02002180 }
2181
Wale Ogunwale494009b82016-10-21 09:01:38 -07002182 boolean checkWaitingForWindows() {
2183
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002184 boolean haveBootMsg = false;
2185 boolean haveApp = false;
2186 // if the wallpaper service is disabled on the device, we're never going to have
2187 // wallpaper, don't bother waiting for it
2188 boolean haveWallpaper = false;
2189 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2190 com.android.internal.R.bool.config_enableWallpaperService)
2191 && !mService.mOnlyCore;
2192 boolean haveKeyguard = true;
2193 final int count = mWindows.size();
2194 for (int i = 0; i < count; i++) {
2195 final WindowState w = mWindows.get(i);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002196 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2197 return true;
2198 }
2199 if (w.isDrawnLw()) {
2200 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002201 haveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002202 } else if (w.mAttrs.type == TYPE_APPLICATION
2203 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002204 haveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002205 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002206 haveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002207 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002208 haveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002209 }
2210 }
2211 }
2212
2213 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2214 "******** booted=" + mService.mSystemBooted
2215 + " msg=" + mService.mShowingBootMessages
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002216 + " haveBoot=" + haveBootMsg + " haveApp=" + haveApp
2217 + " haveWall=" + haveWallpaper + " wallEnabled=" + wallpaperEnabled
2218 + " haveKeyguard=" + haveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002219
2220 // If we are turning on the screen to show the boot message, don't do it until the boot
2221 // message is actually displayed.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002222 if (!mService.mSystemBooted && !haveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002223 return true;
2224 }
2225
2226 // If we are turning on the screen after the boot is completed normally, don't do so until
2227 // we have the application and wallpaper.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002228 if (mService.mSystemBooted && ((!haveApp && !haveKeyguard) ||
2229 (wallpaperEnabled && !haveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002230 return true;
2231 }
2232
2233 return false;
2234 }
2235
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002236 void updateWindowsForAnimator(WindowAnimator animator) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002237 final WallpaperController wallpaperController = mWallpaperController;
2238 for (int i = mWindows.size() - 1; i >= 0; i--) {
2239 WindowState win = mWindows.get(i);
2240 WindowStateAnimator winAnimator = win.mWinAnimator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002241 if (winAnimator.hasSurface()) {
2242 final boolean wasAnimating = winAnimator.mWasAnimating;
2243 final boolean nowAnimating = winAnimator.stepAnimationLocked(animator.mCurrentTime);
2244 winAnimator.mWasAnimating = nowAnimating;
2245 animator.orAnimating(nowAnimating);
2246
2247 if (DEBUG_WALLPAPER) Slog.v(TAG,
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002248 win + ": wasAnimating=" + wasAnimating + ", nowAnimating=" + nowAnimating);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002249
2250 if (wasAnimating && !winAnimator.mAnimating
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002251 && wallpaperController.isWallpaperTarget(win)) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002252 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2253 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
2254 if (DEBUG_LAYOUT_REPEATS) {
2255 mService.mWindowPlacerLocked.debugLayoutRepeats(
2256 "updateWindowsAndWallpaperLocked 2", pendingLayoutChanges);
2257 }
2258 }
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002259 }
2260
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002261 final AppWindowToken atoken = win.mAppToken;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002262 if (winAnimator.mDrawState == READY_TO_SHOW) {
2263 if (atoken == null || atoken.allDrawn) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002264 if (win.performShowLocked()) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002265 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
2266 if (DEBUG_LAYOUT_REPEATS) {
2267 mService.mWindowPlacerLocked.debugLayoutRepeats(
2268 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
2269 }
2270 }
2271 }
2272 }
2273 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
2274 if (appAnimator != null && appAnimator.thumbnail != null) {
2275 if (appAnimator.thumbnailTransactionSeq != animator.mAnimTransactionSequence) {
2276 appAnimator.thumbnailTransactionSeq = animator.mAnimTransactionSequence;
2277 appAnimator.thumbnailLayer = 0;
2278 }
2279 if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
2280 appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
2281 }
2282 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002283 } // end forall windows
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002284 }
2285
2286 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002287 resetAnimationBackgroundAnimator();
2288
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002289 final WindowList windows = mWindows;
2290 WindowState detachedWallpaper = null;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002291
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002292 for (int i = windows.size() - 1; i >= 0; i--) {
2293 final WindowState win = windows.get(i);
2294 final WindowStateAnimator winAnimator = win.mWinAnimator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002295 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002296 continue;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002297 }
2298
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002299 final int flags = win.mAttrs.flags;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002300
2301 // If this window is animating, make a note that we have an animating window and take
2302 // care of a request to run a detached wallpaper animation.
2303 if (winAnimator.mAnimating) {
2304 if (winAnimator.mAnimation != null) {
2305 if ((flags & FLAG_SHOW_WALLPAPER) != 0
2306 && winAnimator.mAnimation.getDetachWallpaper()) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002307 detachedWallpaper = win;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002308 }
2309 final int color = winAnimator.mAnimation.getBackgroundColor();
2310 if (color != 0) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002311 final TaskStack stack = win.getStack();
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002312 if (stack != null) {
2313 stack.setAnimationBackground(winAnimator, color);
2314 }
2315 }
2316 }
2317 animator.setAnimating(true);
2318 }
2319
2320 // If this window's app token is running a detached wallpaper animation, make a note so
2321 // we can ensure the wallpaper is displayed behind it.
2322 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
2323 if (appAnimator != null && appAnimator.animation != null
2324 && appAnimator.animating) {
2325 if ((flags & FLAG_SHOW_WALLPAPER) != 0
2326 && appAnimator.animation.getDetachWallpaper()) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002327 detachedWallpaper = win;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002328 }
2329
2330 final int color = appAnimator.animation.getBackgroundColor();
2331 if (color != 0) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002332 final TaskStack stack = win.getStack();
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002333 if (stack != null) {
2334 stack.setAnimationBackground(winAnimator, color);
2335 }
2336 }
2337 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002338 } // end forall windows
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002339
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002340 if (animator.mWindowDetachedWallpaper != detachedWallpaper) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002341 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002342 + animator.mWindowDetachedWallpaper + " to " + detachedWallpaper);
2343 animator.mWindowDetachedWallpaper = detachedWallpaper;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002344 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2345 }
2346 }
2347
2348 void prepareWindowSurfaces() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002349 final int count = mWindows.size();
2350 for (int j = 0; j < count; j++) {
2351 mWindows.get(j).mWinAnimator.prepareSurfaceLocked(true);
2352 }
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002353 }
2354
Wale Ogunwale494009b82016-10-21 09:01:38 -07002355 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002356 // The focus for the client is the window immediately below where we would place the input
2357 // method window.
2358 int idx = findDesiredInputMethodWindowIndex(false);
2359 if (idx <= 0) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002360 return false;
2361 }
2362
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002363 WindowState imFocus = mWindows.get(idx - 1);
Wale Ogunwale4551c8b2016-11-10 10:25:20 -08002364 if (DEBUG_INPUT_METHOD) {
2365 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2366 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2367 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002368 }
2369
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002370 if (imFocus == null) {
2371 return false;
2372 }
2373
2374 // This may be a starting window, in which case we still want to count it as okay.
2375 if (imFocus.mAttrs.type == TYPE_APPLICATION_STARTING && imFocus.mAppToken != null) {
2376 // The client has definitely started, so it really should have a window in this app
2377 // token. Let's look for it.
2378 final WindowState w = imFocus.mAppToken.getFirstNonStartingWindow();
2379 if (w != null) {
2380 if (DEBUG_INPUT_METHOD) Slog.i(TAG_WM, "Switching to real app window: " + w);
2381 imFocus = w;
2382 }
2383 }
2384
Wale Ogunwale494009b82016-10-21 09:01:38 -07002385 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2386
2387 if (DEBUG_INPUT_METHOD) {
2388 Slog.i(TAG_WM, "IM target client: " + imeClient);
2389 if (imeClient != null) {
2390 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2391 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2392 }
2393 }
2394
2395 return imeClient != null && imeClient.asBinder() == client.asBinder();
2396 }
2397
2398 boolean hasSecureWindowOnScreen() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002399 for (int i = mWindows.size() - 1; i >= 0; --i) {
2400 final WindowState ws = mWindows.get(i);
2401 if (ws.isOnScreen() && (ws.mAttrs.flags & FLAG_SECURE) != 0) {
2402 return true;
2403 }
2404 }
2405 return false;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002406 }
2407
2408 void updateSystemUiVisibility(int visibility, int globalDiff) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002409 for (int i = mWindows.size() - 1; i >= 0; --i) {
2410 final WindowState ws = mWindows.get(i);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002411 try {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002412 int curValue = ws.mSystemUiVisibility;
2413 int diff = (curValue ^ visibility) & globalDiff;
2414 int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002415 if (newValue != curValue) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002416 ws.mSeq++;
2417 ws.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002418 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002419 if (newValue != curValue || ws.mAttrs.hasSystemUiListeners) {
2420 ws.mClient.dispatchSystemUiVisibilityChanged(ws.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002421 visibility, newValue, diff);
2422 }
2423 } catch (RemoteException e) {
2424 // so sorry
2425 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002426 }
Wale Ogunwale494009b82016-10-21 09:01:38 -07002427 }
2428
2429 void onWindowFreezeTimeout() {
2430 Slog.w(TAG_WM, "Window freeze timeout expired.");
2431 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002432 for (int i = mWindows.size() - 1; i >= 0; --i) {
2433 final WindowState w = mWindows.get(i);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002434 if (!w.mOrientationChanging) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002435 continue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002436 }
2437 w.mOrientationChanging = false;
2438 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2439 - mService.mDisplayFreezeTime);
2440 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002441 }
Wale Ogunwale494009b82016-10-21 09:01:38 -07002442 mService.mWindowPlacerLocked.performSurfacePlacement();
2443 }
2444
2445 void waitForAllWindowsDrawn() {
2446 final WindowManagerPolicy policy = mService.mPolicy;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002447 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
2448 final WindowState win = mWindows.get(winNdx);
2449 final boolean keyguard = policy.isKeyguardHostWindow(win.mAttrs);
2450 if (win.isVisibleLw() && (win.mAppToken != null || keyguard)) {
2451 win.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002452 // Force add to mResizingWindows.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002453 win.mLastContentInsets.set(-1, -1, -1, -1);
2454 mService.mWaitingForDrawn.add(win);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002455 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002456 }
Wale Ogunwale494009b82016-10-21 09:01:38 -07002457 }
2458
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002459 // TODO: Super crazy long method that should be broken down...
2460 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2461
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002462 boolean focusDisplayed = false;
2463 boolean displayHasContent = false;
2464 float preferredRefreshRate = 0;
2465 int preferredModeId = 0;
2466
2467
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002468 final int dw = mDisplayInfo.logicalWidth;
2469 final int dh = mDisplayInfo.logicalHeight;
2470 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2471
2472 mTmpUpdateAllDrawn.clear();
2473
2474 int repeats = 0;
2475 do {
2476 repeats++;
2477 if (repeats > 6) {
2478 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2479 clearLayoutNeeded();
2480 break;
2481 }
2482
2483 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2484 pendingLayoutChanges);
2485
Andrii Kulian839def92016-11-02 10:58:58 -07002486 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2487 // the wallpaper window jumping across displays.
2488 // Remove check for default display when there will be support for multiple wallpaper
2489 // targets (on different displays).
2490 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002491 adjustWallpaperWindows();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002492 }
2493
2494 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2495 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2496 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2497 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002498 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002499 }
2500 }
2501
2502 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2503 setLayoutNeeded();
2504 }
2505
2506 // FIRST LOOP: Perform a layout, if needed.
2507 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2508 performLayout(repeats == 1, false /* updateInputWindows */);
2509 } else {
2510 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2511 }
2512
2513 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2514 pendingLayoutChanges = 0;
2515
2516 if (isDefaultDisplay) {
2517 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002518 for (int i = mWindows.size() - 1; i >= 0; i--) {
2519 final WindowState w = mWindows.get(i);
Jorim Jaggife762342016-10-13 14:33:27 +02002520 mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
2521 mService.mInputMethodTarget);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002522 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002523 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2524 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2525 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2526 }
2527 } while (pendingLayoutChanges != 0);
2528
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002529 RootWindowContainer root = mService.mRoot;
2530 boolean obscured = false;
2531 boolean syswin = false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002532 resetDimming();
2533
2534 // Only used if default window
2535 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
2536
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002537 for (int i = mWindows.size() - 1; i >= 0; i--) {
2538 final WindowState w = mWindows.get(i);
2539 final Task task = w.getTask();
2540 final boolean obscuredChanged = w.mObscured != obscured;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002541
2542 // Update effect.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002543 w.mObscured = obscured;
2544 if (!obscured) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002545 final boolean isDisplayed = w.isDisplayedLw();
2546
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08002547 if (isDisplayed && w.isObscuringDisplay()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002548 // This window completely covers everything behind it, so we want to leave all
2549 // of them as undimmed (for performance reasons).
2550 root.mObscuringWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002551 obscured = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002552 }
2553
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002554 displayHasContent |= root.handleNotObscuredLocked(w, obscured, syswin);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002555
2556 if (w.mHasSurface && isDisplayed) {
2557 final int type = w.mAttrs.type;
2558 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
2559 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002560 syswin = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002561 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002562 if (preferredRefreshRate == 0 && w.mAttrs.preferredRefreshRate != 0) {
2563 preferredRefreshRate = w.mAttrs.preferredRefreshRate;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002564 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002565 if (preferredModeId == 0 && w.mAttrs.preferredDisplayModeId != 0) {
2566 preferredModeId = w.mAttrs.preferredDisplayModeId;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002567 }
2568 }
2569 }
2570
2571 w.applyDimLayerIfNeeded();
2572
2573 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
2574 && mWallpaperController.isWallpaperTarget(w)) {
2575 // This is the wallpaper target and its obscured state changed... make sure the
2576 // current wallpaper's visibility has been updated accordingly.
2577 mWallpaperController.updateWallpaperVisibility();
2578 }
2579
2580 w.handleWindowMovedIfNeeded();
2581
2582 final WindowStateAnimator winAnimator = w.mWinAnimator;
2583
2584 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
2585 w.mContentChanged = false;
2586
2587 // Moved from updateWindowsAndWallpaperLocked().
2588 if (w.mHasSurface) {
2589 // Take care of the window being ready to display.
2590 final boolean committed = winAnimator.commitFinishDrawingLocked();
2591 if (isDefaultDisplay && committed) {
2592 if (w.mAttrs.type == TYPE_DREAM) {
2593 // HACK: When a dream is shown, it may at that point hide the lock screen.
2594 // So we need to redo the layout to let the phone window manager make this
2595 // happen.
2596 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
2597 if (DEBUG_LAYOUT_REPEATS) {
2598 surfacePlacer.debugLayoutRepeats(
2599 "dream and commitFinishDrawingLocked true",
2600 pendingLayoutChanges);
2601 }
2602 }
2603 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
2604 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
2605 "First draw done in potential wallpaper target " + w);
2606 root.mWallpaperMayChange = true;
2607 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
2608 if (DEBUG_LAYOUT_REPEATS) {
2609 surfacePlacer.debugLayoutRepeats(
2610 "wallpaper and commitFinishDrawingLocked true",
2611 pendingLayoutChanges);
2612 }
2613 }
2614 }
2615 if (!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening()) {
2616 // Updates the shown frame before we set up the surface. This is needed
2617 // because the resizing could change the top-left position (in addition to
2618 // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to
2619 // position the surface.
2620 //
2621 // If an animation is being started, we can't call this method because the
2622 // animation hasn't processed its initial transformation yet, but in general
2623 // we do want to update the position if the window is animating.
2624 winAnimator.computeShownFrameLocked();
2625 }
2626 winAnimator.setSurfaceBoundariesLocked(recoveringMemory);
2627 }
2628
2629 final AppWindowToken atoken = w.mAppToken;
2630 if (atoken != null) {
2631 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
2632 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
2633 mTmpUpdateAllDrawn.add(atoken);
2634 }
2635 }
2636
2637 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
2638 && w.isDisplayedLw()) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002639 focusDisplayed = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002640 }
2641
2642 w.updateResizingWindowIfNeeded();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002643 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002644
2645 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002646 displayHasContent,
2647 preferredRefreshRate,
2648 preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002649 true /* inTraversal, must call performTraversalInTrans... below */);
2650
2651 stopDimmingIfNeeded();
2652
2653 while (!mTmpUpdateAllDrawn.isEmpty()) {
2654 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2655 // See if any windows have been drawn, so they (and others associated with them)
2656 // can now be shown.
2657 atoken.updateAllDrawn(this);
2658 }
2659
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002660 return focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002661 }
2662
2663 void performLayout(boolean initial, boolean updateInputWindows) {
2664 if (!isLayoutNeeded()) {
2665 return;
2666 }
2667 clearLayoutNeeded();
2668
2669 final int dw = mDisplayInfo.logicalWidth;
2670 final int dh = mDisplayInfo.logicalHeight;
2671
2672 int i;
2673
2674 if (DEBUG_LAYOUT) {
2675 Slog.v(TAG, "-------------------------------------");
2676 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2677 }
2678
2679 mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mService.mRotation,
2680 getConfiguration().uiMode);
2681 if (isDefaultDisplay) {
2682 // Not needed on non-default displays.
2683 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2684 mService.mScreenRect.set(0, 0, dw, dh);
2685 }
2686
2687 mService.mPolicy.getContentRectLw(mContentRect);
2688
2689 int seq = mService.mLayoutSeq + 1;
2690 if (seq < 0) seq = 0;
2691 mService.mLayoutSeq = seq;
2692
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002693 boolean behindDream = false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002694
2695 // First perform layout of any root windows (not attached to another window).
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002696 int topAttached = -1;
2697 for (i = mWindows.size() - 1; i >= 0; i--) {
2698 final WindowState win = mWindows.get(i);
2699
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002700 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
2701 // wasting time and funky changes while a window is animating away.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002702 final boolean gone = (behindDream && mService.mPolicy.canBeHiddenByKeyguardLw(win))
2703 || win.isGoneForLayoutLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002704
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002705 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
2706 Slog.v(TAG, "1ST PASS " + win + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
2707 + " mLayoutAttached=" + win.mLayoutAttached
2708 + " screen changed=" + win.isConfigChanged());
2709 final AppWindowToken atoken = win.mAppToken;
2710 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + win.mViewVisibility
2711 + " mRelayoutCalled=" + win.mRelayoutCalled + " hidden=" + win.mToken.hidden
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002712 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002713 + " parentHidden=" + win.isParentWindowHidden());
2714 else Slog.v(TAG, " VIS: mViewVisibility=" + win.mViewVisibility
2715 + " mRelayoutCalled=" + win.mRelayoutCalled + " hidden=" + win.mToken.hidden
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002716 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002717 + " parentHidden=" + win.isParentWindowHidden());
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002718 }
2719
2720 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
2721 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
2722 // since that means "perform layout as normal, just don't display").
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002723 if (!gone || !win.mHaveFrame || win.mLayoutNeeded
2724 || ((win.isConfigChanged() || win.setReportResizeHints())
2725 && !win.isGoneForLayoutLw() &&
2726 ((win.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
2727 (win.mHasSurface && win.mAppToken != null &&
2728 win.mAppToken.layoutConfigChanges)))) {
2729 if (!win.mLayoutAttached) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002730 if (initial) {
2731 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002732 win.mContentChanged = false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002733 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002734 if (win.mAttrs.type == TYPE_DREAM) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002735 // Don't layout windows behind a dream, so that if it does stuff like hide
2736 // the status bar we won't get a bad transition when it goes away.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002737 behindDream = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002738 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002739 win.mLayoutNeeded = false;
2740 win.prelayout();
2741 mService.mPolicy.layoutWindowLw(win, null);
2742 win.mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002743
2744 // Window frames may have changed. Update dim layer with the new bounds.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002745 final Task task = win.getTask();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002746 if (task != null) {
2747 mDimLayerController.updateDimLayer(task);
2748 }
2749
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002750 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + win.mFrame
2751 + " mContainingFrame=" + win.mContainingFrame
2752 + " mDisplayFrame=" + win.mDisplayFrame);
2753 } else {
2754 if (topAttached < 0) topAttached = i;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002755 }
2756 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002757 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002758
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002759 boolean attachedBehindDream = false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002760
2761 // Now perform layout of attached windows, which usually depend on the position of the
2762 // window they are attached to. XXX does not deal with windows that are attached to windows
2763 // that are themselves attached.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002764 for (i = topAttached; i >= 0; i--) {
2765 final WindowState win = mWindows.get(i);
2766
2767 if (win.mLayoutAttached) {
2768 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + win + " mHaveFrame=" + win.mHaveFrame
2769 + " mViewVisibility=" + win.mViewVisibility
2770 + " mRelayoutCalled=" + win.mRelayoutCalled);
2771 // If this view is GONE, then skip it -- keep the current frame, and let the caller
2772 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
2773 // windows, since that means "perform layout as normal, just don't display").
2774 if (attachedBehindDream && mService.mPolicy.canBeHiddenByKeyguardLw(win)) {
2775 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002776 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002777 if ((win.mViewVisibility != GONE && win.mRelayoutCalled) || !win.mHaveFrame
2778 || win.mLayoutNeeded) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002779 if (initial) {
2780 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002781 win.mContentChanged = false;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002782 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002783 win.mLayoutNeeded = false;
2784 win.prelayout();
2785 mService.mPolicy.layoutWindowLw(win, win.getParentWindow());
2786 win.mLayoutSeq = seq;
2787 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + win.mFrame
2788 + " mContainingFrame=" + win.mContainingFrame
2789 + " mDisplayFrame=" + win.mDisplayFrame);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002790 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002791 } else if (win.mAttrs.type == TYPE_DREAM) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002792 // Don't layout windows behind a dream, so that if it does stuff like hide the
2793 // status bar we won't get a bad transition when it goes away.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002794 attachedBehindDream = behindDream;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002795 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002796 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002797
2798 // Window frames may have changed. Tell the input dispatcher about it.
2799 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2800 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2801 if (updateInputWindows) {
2802 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2803 }
2804
2805 mService.mPolicy.finishLayoutLw();
2806 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2807 }
2808
2809 /**
2810 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2811 * In portrait mode, it grabs the full screenshot.
2812 *
2813 * @param width the width of the target bitmap
2814 * @param height the height of the target bitmap
2815 * @param includeFullDisplay true if the screen should not be cropped before capture
2816 * @param frameScale the scale to apply to the frame, only used when width = -1 and height = -1
2817 * @param config of the output bitmap
2818 * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
2819 */
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002820 Bitmap screenshotApplications(IBinder appToken, int displayId, int width, int height,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002821 boolean includeFullDisplay, float frameScale, Bitmap.Config config,
2822 boolean wallpaperOnly) {
2823 int dw = mDisplayInfo.logicalWidth;
2824 int dh = mDisplayInfo.logicalHeight;
2825 if (dw == 0 || dh == 0) {
2826 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
2827 + ": returning null. logical widthxheight=" + dw + "x" + dh);
2828 return null;
2829 }
2830
2831 Bitmap bm = null;
2832
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002833 int maxLayer = 0;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002834 final Rect frame = new Rect();
2835 final Rect stackBounds = new Rect();
2836
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002837 boolean screenshotReady;
2838 int minLayer;
2839 if (appToken == null && !wallpaperOnly) {
2840 screenshotReady = true;
2841 minLayer = 0;
2842 } else {
2843 screenshotReady = false;
2844 minLayer = Integer.MAX_VALUE;
2845 }
2846
2847 WindowState appWin = null;
2848
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002849 boolean includeImeInScreenshot;
2850 synchronized(mService.mWindowMap) {
2851 final AppWindowToken imeTargetAppToken = mService.mInputMethodTarget != null
2852 ? mService.mInputMethodTarget.mAppToken : null;
2853 // We only include the Ime in the screenshot if the app we are screenshoting is the IME
2854 // target and isn't in multi-window mode. We don't screenshot the IME in multi-window
2855 // mode because the frame of the IME might not overlap with that of the app.
2856 // E.g. IME target app at the top in split-screen mode and the IME at the bottom
2857 // overlapping with the bottom app.
2858 includeImeInScreenshot = imeTargetAppToken != null
2859 && imeTargetAppToken.appToken != null
2860 && imeTargetAppToken.appToken.asBinder() == appToken
2861 && !mService.mInputMethodTarget.isInMultiWindowMode();
2862 }
2863
2864 final int aboveAppLayer = (mService.mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) + 1)
2865 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
2866
2867 synchronized(mService.mWindowMap) {
2868 // Figure out the part of the screen that is actually the app.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002869 appWin = null;
2870 for (int i = mWindows.size() - 1; i >= 0; i--) {
2871 final WindowState ws = mWindows.get(i);
2872 if (!ws.mHasSurface) {
2873 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002874 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002875 if (ws.mLayer >= aboveAppLayer) {
2876 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002877 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002878 if (wallpaperOnly && !ws.mIsWallpaper) {
2879 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002880 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002881 if (ws.mIsImWindow) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002882 if (!includeImeInScreenshot) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002883 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002884 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002885 } else if (ws.mIsWallpaper) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002886 // If this is the wallpaper layer and we're only looking for the wallpaper layer
2887 // then the target window state is this one.
2888 if (wallpaperOnly) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002889 appWin = ws;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002890 }
2891
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002892 if (appWin == null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002893 // We have not ran across the target window yet, so it is probably behind
2894 // the wallpaper. This can happen when the keyguard is up and all windows
2895 // are moved behind the wallpaper. We don't want to include the wallpaper
2896 // layer in the screenshot as it will cover-up the layer of the target
2897 // window.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002898 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002899 }
2900 // Fall through. The target window is in front of the wallpaper. For this
2901 // case we want to include the wallpaper layer in the screenshot because
2902 // the target window might have some transparent areas.
2903 } else if (appToken != null) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002904 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002905 // This app window is of no interest if it is not associated with the
2906 // screenshot app.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002907 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002908 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002909 appWin = ws;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002910 }
2911
2912 // Include this window.
2913
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002914 final WindowStateAnimator winAnim = ws.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002915 int layer = winAnim.mSurfaceController.getLayer();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002916 if (maxLayer < layer) {
2917 maxLayer = layer;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002918 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002919 if (minLayer > layer) {
2920 minLayer = layer;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002921 }
2922
2923 // Don't include wallpaper in bounds calculation
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002924 if (!includeFullDisplay && !ws.mIsWallpaper) {
2925 final Rect wf = ws.mFrame;
2926 final Rect cr = ws.mContentInsets;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002927 int left = wf.left + cr.left;
2928 int top = wf.top + cr.top;
2929 int right = wf.right - cr.right;
2930 int bottom = wf.bottom - cr.bottom;
2931 frame.union(left, top, right, bottom);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002932 ws.getVisibleBounds(stackBounds);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002933 if (!Rect.intersects(frame, stackBounds)) {
2934 // Set frame empty if there's no intersection.
2935 frame.setEmpty();
2936 }
2937 }
2938
2939 final boolean foundTargetWs =
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002940 (ws.mAppToken != null && ws.mAppToken.token == appToken)
2941 || (appWin != null && wallpaperOnly);
2942 if (foundTargetWs && ws.isDisplayedLw() && winAnim.getShown()) {
2943 screenshotReady = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002944 }
2945
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08002946 if (ws.isObscuringDisplay()){
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002947 break;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002948 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002949 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002950
2951 if (appToken != null && appWin == null) {
2952 // Can't find a window to snapshot.
2953 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM,
2954 "Screenshot: Couldn't find a surface matching " + appToken);
2955 return null;
2956 }
2957
2958 if (!screenshotReady) {
2959 Slog.i(TAG_WM, "Failed to capture screenshot of " + appToken +
2960 " appWin=" + (appWin == null ? "null" : (appWin + " drawState=" +
2961 appWin.mWinAnimator.mDrawState)));
2962 return null;
2963 }
2964
2965 // Screenshot is ready to be taken. Everything from here below will continue
2966 // through the bottom of the loop and return a value. We only stay in the loop
2967 // because we don't want to release the mWindowMap lock until the screenshot is
2968 // taken.
2969
2970 if (maxLayer == 0) {
2971 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
2972 + ": returning null maxLayer=" + maxLayer);
2973 return null;
2974 }
2975
2976 if (!includeFullDisplay) {
2977 // Constrain frame to the screen size.
2978 if (!frame.intersect(0, 0, dw, dh)) {
2979 frame.setEmpty();
2980 }
2981 } else {
2982 // Caller just wants entire display.
2983 frame.set(0, 0, dw, dh);
2984 }
2985 if (frame.isEmpty()) {
2986 return null;
2987 }
2988
2989 if (width < 0) {
2990 width = (int) (frame.width() * frameScale);
2991 }
2992 if (height < 0) {
2993 height = (int) (frame.height() * frameScale);
2994 }
2995
2996 // Tell surface flinger what part of the image to crop. Take the top
2997 // right part of the application, and crop the larger dimension to fit.
2998 Rect crop = new Rect(frame);
2999 if (width / (float) frame.width() < height / (float) frame.height()) {
3000 int cropWidth = (int)((float)width / (float)height * frame.height());
3001 crop.right = crop.left + cropWidth;
3002 } else {
3003 int cropHeight = (int)((float)height / (float)width * frame.width());
3004 crop.bottom = crop.top + cropHeight;
3005 }
3006
3007 // The screenshot API does not apply the current screen rotation.
3008 int rot = mDisplay.getRotation();
3009
3010 if (rot == ROTATION_90 || rot == ROTATION_270) {
3011 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3012 }
3013
3014 // Surfaceflinger is not aware of orientation, so convert our logical
3015 // crop to surfaceflinger's portrait orientation.
3016 convertCropForSurfaceFlinger(crop, rot, dw, dh);
3017
3018 if (DEBUG_SCREENSHOT) {
3019 Slog.i(TAG_WM, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to "
3020 + maxLayer + " appToken=" + appToken);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003021 for (int i = 0; i < mWindows.size(); i++) {
3022 final WindowState win = mWindows.get(i);
3023 final WindowSurfaceController controller = win.mWinAnimator.mSurfaceController;
3024 Slog.i(TAG_WM, win + ": " + win.mLayer
3025 + " animLayer=" + win.mWinAnimator.mAnimLayer
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003026 + " surfaceLayer=" + ((controller == null)
3027 ? "null" : controller.getLayer()));
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003028 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003029 }
3030
3031 final ScreenRotationAnimation screenRotationAnimation =
3032 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3033 final boolean inRotation = screenRotationAnimation != null &&
3034 screenRotationAnimation.isAnimating();
3035 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM,
3036 "Taking screenshot while rotating");
3037
3038 // We force pending transactions to flush before taking
3039 // the screenshot by pushing an empty synchronous transaction.
3040 SurfaceControl.openTransaction();
3041 SurfaceControl.closeTransactionSync();
3042
3043 bm = SurfaceControl.screenshot(crop, width, height, minLayer, maxLayer,
3044 inRotation, rot);
3045 if (bm == null) {
3046 Slog.w(TAG_WM, "Screenshot failure taking screenshot for (" + dw + "x" + dh
3047 + ") to layer " + maxLayer);
3048 return null;
3049 }
3050 }
3051
3052 if (DEBUG_SCREENSHOT) {
3053 // TEST IF IT's ALL BLACK
3054 int[] buffer = new int[bm.getWidth() * bm.getHeight()];
3055 bm.getPixels(buffer, 0, bm.getWidth(), 0, 0, bm.getWidth(), bm.getHeight());
3056 boolean allBlack = true;
3057 final int firstColor = buffer[0];
3058 for (int i = 0; i < buffer.length; i++) {
3059 if (buffer[i] != firstColor) {
3060 allBlack = false;
3061 break;
3062 }
3063 }
3064 if (allBlack) {
3065 Slog.i(TAG_WM, "Screenshot " + appWin + " was monochrome(" +
3066 Integer.toHexString(firstColor) + ")! mSurfaceLayer=" +
3067 (appWin != null ?
3068 appWin.mWinAnimator.mSurfaceController.getLayer() : "null") +
3069 " minLayer=" + minLayer + " maxLayer=" + maxLayer);
3070 }
3071 }
3072
3073 // Create a copy of the screenshot that is immutable and backed in ashmem.
3074 // This greatly reduces the overhead of passing the bitmap between processes.
3075 Bitmap ret = bm.createAshmemBitmap(config);
3076 bm.recycle();
3077 return ret;
3078 }
3079
3080 // TODO: Can this use createRotationMatrix()?
3081 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3082 if (rot == Surface.ROTATION_90) {
3083 final int tmp = crop.top;
3084 crop.top = dw - crop.right;
3085 crop.right = crop.bottom;
3086 crop.bottom = dw - crop.left;
3087 crop.left = tmp;
3088 } else if (rot == Surface.ROTATION_180) {
3089 int tmp = crop.top;
3090 crop.top = dh - crop.bottom;
3091 crop.bottom = dh - tmp;
3092 tmp = crop.right;
3093 crop.right = dw - crop.left;
3094 crop.left = dw - tmp;
3095 } else if (rot == Surface.ROTATION_270) {
3096 final int tmp = crop.top;
3097 crop.top = crop.left;
3098 crop.left = dh - crop.bottom;
3099 crop.bottom = crop.right;
3100 crop.right = dh - tmp;
3101 }
3102 }
3103
3104 void onSeamlessRotationTimeout() {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003105 boolean layoutNeeded = false;
3106 for (int i = mWindows.size() - 1; i >= 0; i--) {
3107 final WindowState w = mWindows.get(i);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003108 if (!w.mSeamlesslyRotated) {
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003109 continue;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003110 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003111 layoutNeeded = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003112 w.setDisplayLayoutNeeded();
3113 mService.markForSeamlessRotation(w, false);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003114 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003115
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003116 if (layoutNeeded) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003117 mService.mWindowPlacerLocked.performSurfacePlacement();
3118 }
3119 }
3120
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003121 static final class GetWindowOnDisplaySearchResult {
3122 boolean reachedToken;
3123 WindowState foundWindow;
3124
3125 void reset() {
3126 reachedToken = false;
3127 foundWindow = null;
3128 }
3129 }
3130
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003131 static final class TaskForResizePointSearchResult {
3132 boolean searchDone;
3133 Task taskForResize;
3134
3135 void reset() {
3136 searchDone = false;
3137 taskForResize = null;
3138 }
3139 }
Robert Carr3b716242016-08-16 16:02:21 -07003140
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003141 /**
3142 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3143 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3144 * homogeneous children type which is currently required by sub-classes of
3145 * {@link WindowContainer} class.
3146 */
3147 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3148
3149 int size() {
3150 return mChildren.size();
3151 }
3152
3153 E get(int index) {
3154 return mChildren.get(index);
3155 }
3156
3157 @Override
3158 boolean fillsParent() {
3159 return true;
3160 }
3161
3162 @Override
3163 boolean isVisible() {
3164 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003165 }
3166 }
3167
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003168 /**
3169 * Window container class that contains all containers on this display relating to Apps.
3170 * I.e Activities.
3171 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003172 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003173
Andrii Kulian839def92016-11-02 10:58:58 -07003174 /**
3175 * Adds the stack to this container.
3176 * @see WindowManagerService#addStackToDisplay(int, int, boolean)
3177 */
3178 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003179 if (stack.mStackId == HOME_STACK_ID) {
3180 if (mHomeStack != null) {
3181 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
3182 }
3183 mHomeStack = stack;
3184 }
3185 addChild(stack, onTop);
3186 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003187 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003188
Andrii Kulian839def92016-11-02 10:58:58 -07003189 /** Removes the stack from its container and prepare for changing the parent. */
3190 void removeStackFromDisplay(TaskStack stack) {
3191 removeChild(stack);
3192 stack.onRemovedFromDisplay();
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003193 // TODO: remove when window list will be gone.
3194 // Manually remove records from window list and tap excluded windows list.
3195 for (int i = mWindows.size() - 1; i >= 0; --i) {
3196 final WindowState windowState = mWindows.get(i);
3197 if (stack == windowState.getStack()) {
3198 mWindows.remove(i);
3199 mTapExcludedWindows.remove(windowState);
3200 }
3201 }
Andrii Kulian839def92016-11-02 10:58:58 -07003202 }
3203
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003204 void moveStack(TaskStack stack, boolean toTop) {
3205 if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
3206 // This stack is always-on-top silly...
3207 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
3208 return;
3209 }
3210
3211 if (!mChildren.contains(stack)) {
3212 Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
3213 }
3214 removeChild(stack);
3215 addChild(stack, toTop);
3216 }
3217
3218 private void addChild(TaskStack stack, boolean toTop) {
3219 int addIndex = toTop ? mChildren.size() : 0;
3220
3221 if (toTop
3222 && mService.isStackVisibleLocked(PINNED_STACK_ID)
3223 && stack.mStackId != PINNED_STACK_ID) {
3224 // The pinned stack is always the top most stack (always-on-top) when it is visible.
3225 // So, stack is moved just below the pinned stack.
3226 addIndex--;
3227 TaskStack topStack = mChildren.get(addIndex);
3228 if (topStack.mStackId != PINNED_STACK_ID) {
3229 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3230 }
3231 }
3232 addChild(stack, addIndex);
3233 setLayoutNeeded();
3234 }
3235
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003236 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003237 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3238 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003239 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003240 if (super.forAllWindows(callback, traverseTopToBottom)) {
3241 return true;
3242 }
3243 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3244 return true;
3245 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003246 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003247 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3248 return true;
3249 }
3250 if (super.forAllWindows(callback, traverseTopToBottom)) {
3251 return true;
3252 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003253 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003254 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003255 }
3256
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003257 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003258 boolean traverseTopToBottom) {
3259 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3260 // app tokens.
3261 // TODO: Investigate if we need to continue to do this or if we can just process them
3262 // in-order.
3263 if (traverseTopToBottom) {
3264 for (int i = mChildren.size() - 1; i >= 0; --i) {
3265 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3266 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003267 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3268 traverseTopToBottom)) {
3269 return true;
3270 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003271 }
3272 }
3273 } else {
3274 final int count = mChildren.size();
3275 for (int i = 0; i < count; ++i) {
3276 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3277 final int appTokensCount = appTokens.size();
3278 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003279 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3280 traverseTopToBottom)) {
3281 return true;
3282 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003283 }
3284 }
3285 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003286 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003287 }
3288
3289 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003290 int getOrientation() {
3291 if (mService.isStackVisibleLocked(DOCKED_STACK_ID)
3292 || mService.isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID)) {
3293 // Apps and their containers are not allowed to specify an orientation while the
3294 // docked or freeform stack is visible...except for the home stack/task if the
3295 // docked stack is minimized and it actually set something.
3296 if (mHomeStack != null && mHomeStack.isVisible()
3297 && mDividerControllerLocked.isMinimizedDock()) {
3298 final int orientation = mHomeStack.getOrientation();
3299 if (orientation != SCREEN_ORIENTATION_UNSET) {
3300 return orientation;
3301 }
3302 }
3303 return SCREEN_ORIENTATION_UNSPECIFIED;
3304 }
3305
3306 final int orientation = super.getOrientation();
3307 if (orientation != SCREEN_ORIENTATION_UNSET
3308 && orientation != SCREEN_ORIENTATION_BEHIND) {
3309 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3310 "App is requesting an orientation, return " + orientation);
3311 return orientation;
3312 }
3313
3314 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3315 "No app is requesting an orientation, return " + mService.mLastOrientation);
3316 // The next app has not been requested to be visible, so we keep the current orientation
3317 // to prevent freezing/unfreezing the display too early.
3318 return mService.mLastOrientation;
3319 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003320 }
3321
3322 /**
3323 * Window container class that contains all containers on this display that are not related to
3324 * Apps. E.g. status bar.
3325 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003326 private final class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
3327 /**
3328 * Compares two child window tokens returns -1 if the first is lesser than the second in
3329 * terms of z-order and 1 otherwise.
3330 */
3331 final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
3332 // Tokens with higher base layer are z-ordered on-top.
3333 mService.mPolicy.windowTypeToLayerLw(token1.windowType)
3334 < mService.mPolicy.windowTypeToLayerLw(token2.windowType) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003335
Wale Ogunwale3a931692016-11-02 16:49:48 -07003336 private final String mName;
3337 NonAppWindowContainers(String name) {
3338 mName = name;
3339 }
3340
3341 void addChild(WindowToken token) {
3342 addChild(token, mWindowComparator);
3343 }
3344
3345 @Override
3346 String getName() {
3347 return mName;
3348 }
Robert Carr3b716242016-08-16 16:02:21 -07003349 }
Craig Mautner59c00972012-07-30 12:10:24 -07003350}