blob: 243c4a579962809f3b463f0d5ce0ef655137c9cb [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;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070036import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION;
37import static android.view.WindowManager.INPUT_CONSUMER_PIP;
38import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070039import 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;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070047import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS;
48import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwale494009b82016-10-21 09:01:38 -070049import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070050import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwaleec731152016-09-08 20:18:57 -070051import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale494009b82016-10-21 09:01:38 -070052import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Wale Ogunwaleec731152016-09-08 20:18:57 -070053import 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 Ogunwale494009b82016-10-21 09:01:38 -070056import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070057import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
58import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070059import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070060import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070061import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070062import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
63import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070064import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleec731152016-09-08 20:18:57 -070065import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070066import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070067import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
69import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070070import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwalec69694a2016-10-18 13:51:15 -070071import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070072import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070073import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020074import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070075import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070076import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Jorim Jaggife762342016-10-13 14:33:27 +020077import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070078import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070079import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleec731152016-09-08 20:18:57 -070080import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070081import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070082import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070083import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080084import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070085import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
86import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -070087import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070088import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
89import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
90import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
91import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale494009b82016-10-21 09:01:38 -070092import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070093import static com.android.server.wm.WindowManagerService.dipToPixel;
94import static com.android.server.wm.WindowManagerService.localLOGV;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070095import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070096import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -070097import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070098import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070099import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700100
Andrii Kulian3a507b52016-09-19 18:14:12 -0700101import android.annotation.NonNull;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700102import android.app.ActivityManager.StackId;
Andrii Kulian441e4492016-09-29 15:25:00 -0700103import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700104import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700105import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800106import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700107import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700108import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100109import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700110import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700111import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700112import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700113import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700114import android.os.RemoteException;
115import android.os.SystemClock;
Chong Zhang8e89b312015-09-09 15:09:30 -0700116import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700117import android.util.Slog;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700118import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -0700119import android.view.DisplayInfo;
Wale Ogunwaleec731152016-09-08 20:18:57 -0700120import android.view.IWindow;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700121import android.view.InputChannel;
122import android.view.Surface;
123import android.view.SurfaceControl;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700124import android.view.WindowManagerPolicy;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700125
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700126import com.android.internal.util.FastPrintWriter;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700127import com.android.internal.view.IInputMethodClient;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700128import com.android.server.input.InputWindowHandle;
Craig Mautner59c00972012-07-30 12:10:24 -0700129
Robert Carr3b716242016-08-16 16:02:21 -0700130import java.io.FileDescriptor;
Craig Mautner59c00972012-07-30 12:10:24 -0700131import java.io.PrintWriter;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700132import java.io.StringWriter;
Craig Mautner59c00972012-07-30 12:10:24 -0700133import java.util.ArrayList;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700134import java.util.Arrays;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700135import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700136import java.util.HashMap;
137import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700138import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700139import java.util.List;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700140import java.util.function.BiConsumer;
141import java.util.function.Consumer;
142import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700143
Craig Mautner59c00972012-07-30 12:10:24 -0700144/**
145 * Utility class for keeping track of the WindowStates and other pertinent contents of a
146 * particular Display.
147 *
148 * IMPORTANT: No method from this class should ever be used without holding
149 * WindowManagerService.mWindowMap.
150 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700151class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700152 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700153
154 /** Unique identifier of this stack. */
155 private final int mDisplayId;
156
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700157 // The display only has 2 child window containers. mTaskStackContainers which contains all
158 // window containers that are related to apps (Activities) and mNonAppWindowContainers which
159 // contains all window containers not related to apps (e.g. Status bar).
160 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers();
161 private final NonAppWindowContainers mNonAppWindowContainers = new NonAppWindowContainers();
162
Craig Mautner59c00972012-07-30 12:10:24 -0700163 /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element
164 * from mDisplayWindows; */
Craig Mautnerdc548482014-02-05 13:35:24 -0800165 private final WindowList mWindows = new WindowList();
Craig Mautner59c00972012-07-30 12:10:24 -0700166
Wale Ogunwale02319a62016-09-26 15:21:22 -0700167 // Mapping from a token IBinder to a WindowToken object on this display.
168 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
169
Craig Mautner59c00972012-07-30 12:10:24 -0700170 int mInitialDisplayWidth = 0;
171 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700172 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -0700173 int mBaseDisplayWidth = 0;
174 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700175 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700176 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700177 private final DisplayInfo mDisplayInfo = new DisplayInfo();
178 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700179 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -0700180
Craig Mautner6601b7b2013-04-29 10:29:11 -0700181 Rect mBaseDisplayRect = new Rect();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700182 private Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700183
Craig Mautner39834192012-09-02 07:47:24 -0700184 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700185 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700186 int pendingLayoutChanges;
Craig Mautner69b08182012-09-05 13:07:13 -0700187 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700188
Craig Mautnerdc548482014-02-05 13:35:24 -0800189 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700190 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800191
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800192 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
193 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -0700194 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700195
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700196 /** Detect user tapping outside of current focused task bounds .*/
197 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700198
Craig Mautner6601b7b2013-04-29 10:29:11 -0700199 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700200 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700201
Craig Mautner6601b7b2013-04-29 10:29:11 -0700202 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800203 private final Rect mTmpRect = new Rect();
204 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700205 private final RectF mTmpRectF = new RectF();
206 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800207 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700208
Craig Mautner9d808b12013-08-06 18:00:25 -0700209 final WindowManagerService mService;
210
Craig Mautner95da1082014-02-24 17:54:35 -0800211 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700212 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800213
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700214 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700215 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700216
Chong Zhang112eb8c2015-11-02 11:17:00 -0800217 final DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700218
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800219 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
220
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700221 /** Used when rebuilding window list to keep track of windows that have been removed. */
222 private WindowState[] mRebuildTmp = new WindowState[20];
223
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700224 /**
225 * Temporary list for comparison. Always clear this after use so we don't end up with
226 * orphaned windows references
227 */
228 private final ArrayList<WindowState> mTmpWindows = new ArrayList<>();
229
230 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
231
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700232 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
233 new TaskForResizePointSearchResult();
234 private final GetWindowOnDisplaySearchResult mTmpGetWindowOnDisplaySearchResult =
235 new GetWindowOnDisplaySearchResult();
236
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700237 // True if this display is in the process of being removed. Used to determine if the removal of
238 // the display's direct children should be allowed.
239 private boolean mRemovingDisplay = false;
240
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700241 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700242 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700243 int mInputMethodAnimLayerAdjustment;
244
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800245 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700246 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800247 * @param service You know.
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700248 * @param layersController window layer controller used to assign layer to the windows on this
249 * display.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700250 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
251 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700252 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700253 DisplayContent(Display display, WindowManagerService service,
Wale Ogunwale0303c572016-10-20 10:16:29 -0700254 WindowLayersController layersController, WallpaperController wallpaperController) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700255 mDisplay = display;
256 mDisplayId = display.getDisplayId();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700257 mLayersController = layersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700258 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700259 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700260 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700261 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700262 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700263 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800264 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700265 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800266 mDimLayerController = new DimLayerController(this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700267
268 // These are the only direct children we should ever have and they are permanent.
269 super.addChild(mTaskStackContainers, null);
270 super.addChild(mNonAppWindowContainers, null);
Craig Mautner59c00972012-07-30 12:10:24 -0700271 }
272
273 int getDisplayId() {
274 return mDisplayId;
275 }
276
Wale Ogunwale02319a62016-09-26 15:21:22 -0700277 WindowToken getWindowToken(IBinder binder) {
278 return mTokenMap.get(binder);
279 }
280
281 AppWindowToken getAppWindowToken(IBinder binder) {
282 final WindowToken token = getWindowToken(binder);
283 if (token == null) {
284 return null;
285 }
286 return token.asAppWindowToken();
287 }
288
289 void setWindowToken(IBinder binder, WindowToken token) {
290 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
291 if (dc != null) {
292 // We currently don't support adding a window token to the display if the display
293 // already has the binder mapped to another token. If there is a use case for supporting
294 // this moving forward we will either need to merge the WindowTokens some how or have
295 // the binder map to a list of window tokens.
296 throw new IllegalArgumentException("Can't map token=" + token + " to display=" + this
297 + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
298 }
299 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700300
301 if (token.asAppWindowToken() == null) {
302 // Add non-app token to container hierarchy on the display. App tokens are added through
303 // the parent container managing them (e.g. Tasks).
304 mNonAppWindowContainers.addChild(token, null);
305 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700306 }
307
308 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700309 final WindowToken token = mTokenMap.remove(binder);
310 if (token != null && token.asAppWindowToken() == null) {
311 mNonAppWindowContainers.removeChild(token);
312 }
313 return token;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700314 }
315
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700316 void removeAppToken(IBinder binder) {
317 final WindowToken token = removeWindowToken(binder);
318 if (token == null) {
319 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
320 return;
321 }
322
323 final AppWindowToken appToken = token.asAppWindowToken();
324
325 if (appToken == null) {
326 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
327 return;
328 }
329
330 appToken.onRemovedFromDisplay();
331 }
332
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700333 Display getDisplay() {
334 return mDisplay;
335 }
336
Craig Mautner59c00972012-07-30 12:10:24 -0700337 DisplayInfo getDisplayInfo() {
338 return mDisplayInfo;
339 }
340
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700341 DisplayMetrics getDisplayMetrics() {
342 return mDisplayMetrics;
343 }
344
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100345 DockedStackDividerController getDockedDividerController() {
346 return mDividerControllerLocked;
347 }
348
Winson Chung655332c2016-10-31 13:14:28 -0700349 PinnedStackController getPinnedStackController() {
350 return mPinnedStackControllerLocked;
351 }
352
Jeff Browna506a6e2013-06-04 00:02:38 -0700353 /**
354 * Returns true if the specified UID has access to this display.
355 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700356 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700357 return mDisplay.hasAccess(uid);
358 }
359
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700360 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700361 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -0700362 }
363
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700364 TaskStack getHomeStack() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700365 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800366 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
Craig Mautnere0a38842013-12-16 16:14:02 -0800367 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700368 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700369 }
370
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700371 TaskStack getStackById(int stackId) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700372 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
373 final TaskStack stack = mTaskStackContainers.get(i);
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700374 if (stack.mStackId == stackId) {
375 return stack;
376 }
377 }
378 return null;
379 }
380
Andrii Kulian441e4492016-09-29 15:25:00 -0700381 @Override
382 void onConfigurationChanged(Configuration newParentConfig) {
383 super.onConfigurationChanged(newParentConfig);
384
Andrii Kulian3a507b52016-09-19 18:14:12 -0700385 // The display size information is heavily dependent on the resources in the current
386 // configuration, so we need to reconfigure it every time the configuration changes.
387 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
388 mService.reconfigureDisplayLocked(this);
389
390 getDockedDividerController().onConfigurationChanged();
Winson Chung655332c2016-10-31 13:14:28 -0700391 getPinnedStackController().onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700392 }
Andrii Kulian3a507b52016-09-19 18:14:12 -0700393
Andrii Kulian441e4492016-09-29 15:25:00 -0700394 /**
395 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
396 * bounds were updated.
397 */
398 void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700399 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
400 final TaskStack stack = mTaskStackContainers.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700401 if (stack.updateBoundsAfterConfigChange()) {
Andrii Kulian3a507b52016-09-19 18:14:12 -0700402 changedStackList.add(stack.mStackId);
403 }
404 }
405 }
406
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700407 @Override
408 boolean fillsParent() {
409 return true;
410 }
411
412 @Override
413 boolean isVisible() {
414 return true;
415 }
416
417 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700418 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700419 super.onAppTransitionDone();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700420 rebuildAppWindowList();
421 }
422
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700423 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -0700424 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700425 final WindowManagerPolicy policy = mService.mPolicy;
426
427 // TODO: All the logic before the last return statement in this method should really go in
428 // #NonAppWindowContainer.getOrientation() since it is trying to decide orientation based
429 // on non-app windows. But, we can not do that until the window list is always correct in
430 // terms of z-ordering based on layers.
431 if (mService.mDisplayFrozen) {
432 if (mService.mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
433 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
434 "Display is frozen, return " + mService.mLastWindowForcedOrientation);
435 // If the display is frozen, some activities may be in the middle of restarting, and
436 // thus have removed their old window. If the window has the flag to hide the lock
437 // screen, then the lock screen can re-appear and inflict its own orientation on us.
438 // Keep the orientation stable until this all settles down.
439 return mService.mLastWindowForcedOrientation;
440 } else if (policy.isKeyguardLocked()) {
441 // Use the last orientation the while the display is frozen with the keyguard
442 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
443 // window. We don't want to check the show when locked window directly though as
444 // things aren't stable while the display is frozen, for example the window could be
445 // momentarily unavailable due to activity relaunch.
446 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
447 + "return " + mService.mLastOrientation);
448 return mService.mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -0700449 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700450 } else {
451 for (int pos = mWindows.size() - 1; pos >= 0; --pos) {
452 final WindowState win = mWindows.get(pos);
453 if (win.mAppToken != null) {
454 // We hit an application window. so the orientation will be determined by the
455 // app window. No point in continuing further.
456 break;
457 }
458 if (!win.isVisibleLw() || !win.mPolicyVisibilityAfterAnim) {
459 continue;
460 }
461 int req = win.mAttrs.screenOrientation;
462 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND) {
463 continue;
464 }
465
466 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
467 if (policy.isKeyguardHostWindow(win.mAttrs)) {
468 mService.mLastKeyguardForcedOrientation = req;
469 }
470 return (mService.mLastWindowForcedOrientation = req);
471 }
472 mService.mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
473
Jorim Jaggife762342016-10-13 14:33:27 +0200474 if (policy.isKeyguardShowingAndNotOccluded()) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700475 return mService.mLastKeyguardForcedOrientation;
476 }
Wale Ogunwale51362492016-09-08 17:49:17 -0700477 }
478
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700479 // Top system windows are not requesting an orientation. Start searching from apps.
480 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -0700481 }
482
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700483 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700484 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700485 mDisplay.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700486 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
487 mTaskStackContainers.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800488 }
Craig Mautner722285e2012-09-07 13:55:58 -0700489 }
490
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700491 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700492 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
493 if (displayManagerInternal != null) {
494 // Bootstrap the default logical display from the display manager.
495 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
496 if (newDisplayInfo != null) {
497 mDisplayInfo.copyFrom(newDisplayInfo);
498 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700499 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700500
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800501 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
502 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
503 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
504 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700505 }
506
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700507 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700508 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800509 final int orientation = mDisplayInfo.rotation;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700510 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
Craig Mautner4a1cb222013-12-04 16:14:06 -0800511 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
512 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700513 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800514 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700515 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800516 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700517 out.set(left, top, left + width, top + height);
518 }
519
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700520 private void getLogicalDisplayRect(Rect out, int orientation) {
521 getLogicalDisplayRect(out);
522
523 // Rotate the Rect if needed.
524 final int currentRotation = mDisplayInfo.rotation;
525 final int rotationDelta = deltaRotation(currentRotation, orientation);
526 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
527 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
528 mTmpRectF.set(out);
529 mTmpMatrix.mapRect(mTmpRectF);
530 mTmpRectF.round(out);
531 }
532 }
533
Chong Zhangf66db432016-01-13 10:39:51 -0800534 void getContentRect(Rect out) {
535 out.set(mContentRect);
536 }
537
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700538 /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
539 void attachStack(TaskStack stack, boolean onTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700540 mTaskStackContainers.attachStack(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800541 }
542
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800543 void moveStack(TaskStack stack, boolean toTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700544 mTaskStackContainers.moveStack(stack, toTop);
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700545 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700546
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700547 @Override
548 protected void addChild(DisplayChildWindowContainer child,
549 Comparator<DisplayChildWindowContainer> comparator) {
550 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
551 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700552
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700553 @Override
554 protected void addChild(DisplayChildWindowContainer child, int index) {
555 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
556 }
557
558 @Override
559 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700560 // Only allow removal of direct children from this display if the display is in the process
561 // of been removed.
562 if (mRemovingDisplay) {
563 super.removeChild(child);
564 return;
565 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700566 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800567 }
568
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700569 int taskIdFromPoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700570 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
571 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700572 final int taskId = stack.taskIdFromPoint(x, y);
573 if (taskId != -1) {
574 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -0700575 }
576 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800577 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700578 }
579
Chong Zhang8e89b312015-09-09 15:09:30 -0700580 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -0800581 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -0700582 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700583 */
Wale Ogunwale15ead902016-09-02 14:30:11 -0700584 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700585 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700586 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700587 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
588 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -0700589 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700590 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700591 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700592
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700593 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
594 if (mTmpTaskForResizePointSearchResult.searchDone) {
595 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -0700596 }
597 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700598 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700599 }
600
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700601 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700602 mTouchExcludeRegion.set(mBaseDisplayRect);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700603 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700604 mTmpRect2.setEmpty();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700605 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
606 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700607 stack.setTouchExcludeRegion(
608 focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2);
Craig Mautner6601b7b2013-04-29 10:29:11 -0700609 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800610 // If we removed the focused task above, add it back and only leave its
611 // outside touch area in the exclusion. TapDectector is not interested in
612 // any touch inside the focused task itself.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700613 if (!mTmpRect2.isEmpty()) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800614 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
615 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800616 final WindowState inputMethod = mService.mInputMethodWindow;
617 if (inputMethod != null && inputMethod.isVisibleLw()) {
618 // If the input method is visible and the user is typing, we don't want these touch
619 // events to be intercepted and used to change focus. This would likely cause a
620 // disappearance of the input method.
621 inputMethod.getTouchableRegion(mTmpRegion);
622 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
623 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800624 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
625 WindowState win = mTapExcludedWindows.get(i);
626 win.getTouchableRegion(mTmpRegion);
627 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
628 }
Jorim Jaggife762342016-10-13 14:33:27 +0200629 if (getDockedStackLocked() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100630 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -0700631 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100632 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
633 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800634 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700635 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -0800636 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700637 }
638
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700639 void switchUser() {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700640 final int count = mWindows.size();
641 for (int i = 0; i < count; i++) {
642 final WindowState win = mWindows.get(i);
Craig Mautner858d8a62013-04-23 17:08:34 -0700643 if (win.isHiddenFromUserLocked()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800644 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800645 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700646 win.hideLw(false);
647 }
648 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700649
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700650 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
651 mTaskStackContainers.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700652 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700653
654 rebuildAppWindowList();
Craig Mautner858d8a62013-04-23 17:08:34 -0700655 }
656
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700657 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700658 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
659 mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700660 }
661 }
662
663 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800664 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700665 }
666
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700667 private void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800668 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700669 }
670
671 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800672 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700673 }
674
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700675 private void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800676 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700677 }
678
Wale Ogunwale10124582016-09-15 20:25:50 -0700679 @Override
680 void removeIfPossible() {
681 if (isAnimating()) {
682 mDeferredRemoval = true;
683 return;
Craig Mautner2eb15342013-08-07 13:13:35 -0700684 }
Wale Ogunwale10124582016-09-15 20:25:50 -0700685 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -0700686 }
687
Wale Ogunwale10124582016-09-15 20:25:50 -0700688 @Override
689 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700690 mRemovingDisplay = true;
691 try {
692 super.removeImmediately();
693 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
694 mDimLayerController.close();
695 if (mDisplayId == DEFAULT_DISPLAY) {
696 mService.unregisterPointerEventListener(mTapDetector);
697 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
698 }
699 } finally {
700 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -0800701 }
Craig Mautner95da1082014-02-24 17:54:35 -0800702 }
703
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700704 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -0700705 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700706 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700707 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
708
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700709 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -0700710 removeImmediately();
Craig Mautner95da1082014-02-24 17:54:35 -0800711 mService.onDisplayRemoved(mDisplayId);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700712 return false;
Craig Mautner95da1082014-02-24 17:54:35 -0800713 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700714 return true;
Craig Mautner95da1082014-02-24 17:54:35 -0800715 }
716
Wale Ogunwale10124582016-09-15 20:25:50 -0700717 boolean animateForIme(float interpolatedValue, float animationTarget,
718 float dividerAnimationTarget) {
719 boolean updated = false;
720
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700721 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
722 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700723 if (stack == null || !stack.isAdjustedForIme()) {
724 continue;
725 }
726
727 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
728 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
729 updated = true;
730 } else {
731 mDividerControllerLocked.mLastAnimationProgress =
732 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
733 mDividerControllerLocked.mLastDividerProgress =
734 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
735 updated |= stack.updateAdjustForIme(
736 mDividerControllerLocked.mLastAnimationProgress,
737 mDividerControllerLocked.mLastDividerProgress,
738 false /* force */);
739 }
740 if (interpolatedValue >= 1f) {
741 stack.endImeAdjustAnimation();
742 }
743 }
744
745 return updated;
746 }
747
748 boolean clearImeAdjustAnimation() {
749 boolean changed = false;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700750 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
751 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700752 if (stack != null && stack.isAdjustedForIme()) {
753 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
754 changed = true;
755 }
756 }
757 return changed;
758 }
759
760 void beginImeAdjustAnimation() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700761 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
762 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700763 if (stack.isVisible() && stack.isAdjustedForIme()) {
764 stack.beginImeAdjustAnimation();
765 }
766 }
767 }
768
769 void adjustForImeIfNeeded() {
770 final WindowState imeWin = mService.mInputMethodWindow;
771 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
772 && !mDividerControllerLocked.isImeHideRequested();
773 final boolean dockVisible = mService.isStackVisibleLocked(DOCKED_STACK_ID);
774 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
775 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
776 imeTargetStack.getDockSide() : DOCKED_INVALID;
777 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
778 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
779 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
780 final int imeHeight = mService.mPolicy.getInputMethodWindowVisibleHeightLw();
781 final boolean imeHeightChanged = imeVisible &&
782 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
783
784 // The divider could be adjusted for IME position, or be thinner than usual,
785 // or both. There are three possible cases:
786 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
787 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
788 // - If IME is not visible, divider is not moved and is normal width.
789
790 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700791 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
792 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700793 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
794 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)) {
795 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
796 } else {
797 stack.resetAdjustedForIme(false);
798 }
799 }
800 mDividerControllerLocked.setAdjustedForIme(
801 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
802 } else {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700803 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
804 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700805 stack.resetAdjustedForIme(!dockVisible);
806 }
807 mDividerControllerLocked.setAdjustedForIme(
808 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
809 }
Winson Chung655332c2016-10-31 13:14:28 -0700810 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -0700811 }
812
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700813 void setInputMethodAnimLayerAdjustment(int adj) {
814 if (DEBUG_LAYERS) Slog.v(TAG_WM, "Setting im layer adj to " + adj);
815 mInputMethodAnimLayerAdjustment = adj;
816 final WindowState imw = mService.mInputMethodWindow;
817 if (imw != null) {
818 imw.adjustAnimLayer(adj);
819 }
820 for (int i = mService.mInputMethodDialogs.size() - 1; i >= 0; i--) {
821 final WindowState dialog = mService.mInputMethodDialogs.get(i);
822 // TODO: This and other places setting mAnimLayer can probably use WS.adjustAnimLayer,
823 // but need to make sure we are not setting things twice for child windows that are
824 // already in the list.
825 dialog.mWinAnimator.mAnimLayer = dialog.mLayer + adj;
826 if (DEBUG_LAYERS) Slog.v(TAG_WM, "IM win " + imw
827 + " anim layer: " + dialog.mWinAnimator.mAnimLayer);
828 }
829 }
830
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700831 /**
832 * If a window that has an animation specifying a colored background and the current wallpaper
833 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
834 * suddenly disappear.
835 */
836 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
837 for (int i = mWindows.size() - 1; i >= 0; --i) {
838 final WindowState win = mWindows.get(i);
839 if (win.mIsWallpaper && win.isVisibleNow()) {
840 return win.mWinAnimator.mAnimLayer;
841 }
842 }
843 return winAnimator.mAnimLayer;
844 }
845
Wale Ogunwale10124582016-09-15 20:25:50 -0700846 void prepareFreezingTaskBounds() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700847 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
848 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -0700849 stack.prepareFreezingTaskBounds();
850 }
851 }
852
Wale Ogunwale94744212015-09-21 19:01:47 -0700853 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700854 getLogicalDisplayRect(mTmpRect, newRotation);
855
856 // Compute a transform matrix to undo the coordinate space transformation,
857 // and present the window at the same physical position it previously occupied.
858 final int deltaRotation = deltaRotation(newRotation, oldRotation);
859 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
860
861 mTmpRectF.set(bounds);
862 mTmpMatrix.mapRect(mTmpRectF);
863 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -0700864 }
865
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800866 static int deltaRotation(int oldRotation, int newRotation) {
867 int delta = newRotation - oldRotation;
868 if (delta < 0) delta += 4;
869 return delta;
870 }
871
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700872 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700873 Matrix outMatrix) {
874 // For rotations without Z-ordering we don't need the target rectangle's position.
875 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
876 displayHeight, outMatrix);
877 }
878
879 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
880 float displayWidth, float displayHeight, Matrix outMatrix) {
881 switch (rotation) {
882 case ROTATION_0:
883 outMatrix.reset();
884 break;
885 case ROTATION_270:
886 outMatrix.setRotate(270, 0, 0);
887 outMatrix.postTranslate(0, displayHeight);
888 outMatrix.postTranslate(rectTop, 0);
889 break;
890 case ROTATION_180:
891 outMatrix.reset();
892 break;
893 case ROTATION_90:
894 outMatrix.setRotate(90, 0, 0);
895 outMatrix.postTranslate(displayWidth, 0);
896 outMatrix.postTranslate(-rectTop, rectLeft);
897 break;
898 }
899 }
900
Craig Mautnera91f9e22012-09-14 16:22:08 -0700901 public void dump(String prefix, PrintWriter pw) {
902 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
903 final String subPrefix = " " + prefix;
904 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
905 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
906 pw.print("dpi");
907 if (mInitialDisplayWidth != mBaseDisplayWidth
908 || mInitialDisplayHeight != mBaseDisplayHeight
909 || mInitialDisplayDensity != mBaseDisplayDensity) {
910 pw.print(" base=");
911 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
912 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
913 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700914 if (mDisplayScalingDisabled) {
915 pw.println(" noscale");
916 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700917 pw.print(" cur=");
918 pw.print(mDisplayInfo.logicalWidth);
919 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
920 pw.print(" app=");
921 pw.print(mDisplayInfo.appWidth);
922 pw.print("x"); pw.print(mDisplayInfo.appHeight);
923 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
924 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
925 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
926 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700927 pw.println(subPrefix + "deferred=" + mDeferredRemoval
928 + " mLayoutNeeded=" + mLayoutNeeded);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800929
Craig Mautnerdc548482014-02-05 13:35:24 -0800930 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -0700931 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700932 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
933 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800934 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700935 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800936
Craig Mautnerdc548482014-02-05 13:35:24 -0800937 pw.println();
938 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700939 pw.println();
940 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800941 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700942 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700943 pw.print(" Exiting #"); pw.print(i);
944 pw.print(' '); pw.print(token);
945 pw.println(':');
946 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800947 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700948 }
Craig Mautner59c00972012-07-30 12:10:24 -0700949 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -0700950 mDimLayerController.dump(prefix, pw);
Jorim Jaggi31f71702016-05-04 16:43:04 -0700951 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -0700952 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -0700953 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -0700954 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700955
956 if (mInputMethodAnimLayerAdjustment != 0) {
957 pw.println(subPrefix
958 + "mInputMethodAnimLayerAdjustment=" + mInputMethodAnimLayerAdjustment);
959 }
Craig Mautner59c00972012-07-30 12:10:24 -0700960 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800961
962 @Override
963 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700964 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700965 }
966
967 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700968 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -0800969 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700970
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800971 /**
972 * @return The docked stack, but only if it is visible, and {@code null} otherwise.
973 */
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700974 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700975 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700976 return (stack != null && stack.isVisible()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700977 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800978
979 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800980 * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not
Jorim Jaggife762342016-10-13 14:33:27 +0200981 * visible.
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800982 */
Jorim Jaggife762342016-10-13 14:33:27 +0200983 TaskStack getDockedStackIgnoringVisibility() {
984 return mService.mStackIdToStack.get(DOCKED_STACK_ID);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800985 }
986
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700987 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800988 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
989 WindowState touchedWin = null;
990 final int x = (int) xf;
991 final int y = (int) yf;
992
993 for (int i = mWindows.size() - 1; i >= 0; i--) {
994 WindowState window = mWindows.get(i);
995 final int flags = window.mAttrs.flags;
996 if (!window.isVisibleLw()) {
997 continue;
998 }
999 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
1000 continue;
1001 }
1002
1003 window.getVisibleBounds(mTmpRect);
1004 if (!mTmpRect.contains(x, y)) {
1005 continue;
1006 }
1007
1008 window.getTouchableRegion(mTmpRegion);
1009
1010 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
1011 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
1012 touchedWin = window;
1013 break;
1014 }
1015 }
1016
1017 return touchedWin;
1018 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07001019
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001020 boolean canAddToastWindowForUid(int uid) {
1021 // We allow one toast window per UID being shown at a time.
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001022 final int windowCount = mWindows.size();
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001023 for (int i = 0; i < windowCount; i++) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001024 final WindowState window = mWindows.get(i);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001025 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == uid
Svet Ganov62a40f82016-09-29 00:43:51 -07001026 && !window.mPermanentlyHidden && !window.mAnimatingExit
1027 && !window.mRemoveOnExit) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001028 return false;
1029 }
1030 }
1031 return true;
1032 }
1033
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001034 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001035 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
1036 return;
1037 }
1038 final int lostFocusUid = oldFocus.mOwnerUid;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001039 final int windowCount = mWindows.size();
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001040 final Handler handler = mService.mH;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001041 for (int i = 0; i < windowCount; i++) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001042 final WindowState window = mWindows.get(i);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001043 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == lostFocusUid) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001044 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, window)) {
1045 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, window),
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001046 window.mAttrs.hideTimeoutMilliseconds);
1047 }
1048 }
1049 }
1050 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001051
1052 WindowState findFocusedWindow() {
1053 final AppWindowToken focusedApp = mService.mFocusedApp;
1054
1055 for (int i = mWindows.size() - 1; i >= 0; i--) {
1056 final WindowState win = mWindows.get(i);
1057
1058 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + i + " = " + win
1059 + ", flags=" + win.mAttrs.flags + ", canReceive=" + win.canReceiveKeys());
1060
1061 if (!win.canReceiveKeys()) {
1062 continue;
1063 }
1064
1065 final AppWindowToken wtoken = win.mAppToken;
1066
1067 // If this window's application has been removed, just skip it.
1068 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
1069 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
1070 + (wtoken.removed ? "removed" : "sendingToBottom"));
1071 continue;
1072 }
1073
1074 if (focusedApp == null) {
1075 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
1076 + " using new focus @ " + i + " = " + win);
1077 return win;
1078 }
1079
1080 if (!focusedApp.windowsAreFocusable()) {
1081 // Current focused app windows aren't focusable...
1082 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
1083 + " focusable using new focus @ " + i + " = " + win);
1084 return win;
1085 }
1086
1087 // Descend through all of the app tokens and find the first that either matches
1088 // win.mAppToken (return win) or mFocusedApp (return null).
1089 if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001090 if (focusedApp.compareTo(wtoken) > 0) {
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001091 // App stack below focused app stack. No focus for you!!!
1092 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
1093 "findFocusedWindow: Reached focused app=" + focusedApp);
1094 return null;
1095 }
1096 }
1097
1098 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ "
1099 + i + " = " + win);
1100 return win;
1101 }
1102
1103 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
1104 return null;
1105 }
Wale Ogunwaleec731152016-09-08 20:18:57 -07001106
Wale Ogunwale07bcab72016-10-14 15:30:09 -07001107 void addAppWindowToWindowList(final WindowState win) {
Wale Ogunwaleec731152016-09-08 20:18:57 -07001108 final IWindow client = win.mClient;
1109
1110 WindowList tokenWindowList = getTokenWindowsOnDisplay(win.mToken);
1111 if (!tokenWindowList.isEmpty()) {
Wale Ogunwale07bcab72016-10-14 15:30:09 -07001112 addAppWindowExisting(win, tokenWindowList);
1113 return;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001114 }
1115
1116 // No windows from this token on this display
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001117 if (localLOGV) Slog.v(TAG_WM, "Figuring out where to add app window "
Wale Ogunwaleec731152016-09-08 20:18:57 -07001118 + client.asBinder() + " (token=" + this + ")");
1119
1120 final WindowToken wToken = win.mToken;
1121
1122 // Figure out where the window should go, based on the order of applications.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001123 mTmpGetWindowOnDisplaySearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001124 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1125 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001126 stack.getWindowOnDisplayBeforeToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
1127 if (mTmpGetWindowOnDisplaySearchResult.reachedToken) {
Wale Ogunwaleec731152016-09-08 20:18:57 -07001128 // We have reach the token we are interested in. End search.
1129 break;
1130 }
1131 }
1132
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001133 WindowState pos = mTmpGetWindowOnDisplaySearchResult.foundWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001134
1135 // We now know the index into the apps. If we found an app window above, that gives us the
1136 // position; else we need to look some more.
1137 if (pos != null) {
1138 // Move behind any windows attached to this one.
Wale Ogunwale02319a62016-09-26 15:21:22 -07001139 final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
Wale Ogunwaleec731152016-09-08 20:18:57 -07001140 if (atoken != null) {
1141 tokenWindowList = getTokenWindowsOnDisplay(atoken);
1142 final int NC = tokenWindowList.size();
1143 if (NC > 0) {
1144 WindowState bottom = tokenWindowList.get(0);
1145 if (bottom.mSubLayer < 0) {
1146 pos = bottom;
1147 }
1148 }
1149 }
1150 addWindowToListBefore(win, pos);
Wale Ogunwale07bcab72016-10-14 15:30:09 -07001151 return;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001152 }
1153
1154 // Continue looking down until we find the first token that has windows on this display.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001155 mTmpGetWindowOnDisplaySearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001156 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1157 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001158 stack.getWindowOnDisplayAfterToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
1159 if (mTmpGetWindowOnDisplaySearchResult.foundWindow != null) {
Wale Ogunwaleec731152016-09-08 20:18:57 -07001160 // We have found a window after the token. End search.
1161 break;
1162 }
1163 }
1164
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001165 pos = mTmpGetWindowOnDisplaySearchResult.foundWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001166
1167 if (pos != null) {
1168 // Move in front of any windows attached to this one.
Wale Ogunwale02319a62016-09-26 15:21:22 -07001169 final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
Wale Ogunwaleec731152016-09-08 20:18:57 -07001170 if (atoken != null) {
1171 final WindowState top = atoken.getTopWindow();
1172 if (top != null && top.mSubLayer >= 0) {
1173 pos = top;
1174 }
1175 }
1176 addWindowToListAfter(win, pos);
Wale Ogunwale07bcab72016-10-14 15:30:09 -07001177 return;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001178 }
1179
1180 // Just search for the start of this layer.
1181 final int myLayer = win.mBaseLayer;
1182 int i;
1183 for (i = mWindows.size() - 1; i >= 0; --i) {
1184 final WindowState w = mWindows.get(i);
1185 // Dock divider shares the base layer with application windows, but we want to always
1186 // keep it above the application windows. The sharing of the base layer is intended
1187 // for window animations, which need to be above the dock divider for the duration
1188 // of the animation.
1189 if (w.mBaseLayer <= myLayer && w.mAttrs.type != TYPE_DOCK_DIVIDER) {
1190 break;
1191 }
1192 }
1193 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1194 "Based on layer: Adding window " + win + " at " + (i + 1) + " of "
1195 + mWindows.size());
1196 mWindows.add(i + 1, win);
1197 mService.mWindowsChanged = true;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001198 }
1199
1200 /** Adds this non-app window to the window list. */
1201 void addNonAppWindowToWindowList(WindowState win) {
1202 // Figure out where window should go, based on layer.
1203 int i;
1204 for (i = mWindows.size() - 1; i >= 0; i--) {
1205 final WindowState otherWin = mWindows.get(i);
1206 if (otherWin.getBaseType() != TYPE_WALLPAPER && otherWin.mBaseLayer <= win.mBaseLayer) {
1207 // Wallpaper wanders through the window list, for example to position itself
1208 // directly behind keyguard. Because of this it will break the ordering based on
1209 // WindowState.mBaseLayer. There might windows with higher mBaseLayer behind it and
1210 // we don't want the new window to appear above them. An example of this is adding
1211 // of the docked stack divider. Consider a scenario with the following ordering (top
1212 // to bottom): keyguard, wallpaper, assist preview, apps. We want the dock divider
1213 // to land below the assist preview, so the dock divider must ignore the wallpaper,
1214 // with which it shares the base layer.
1215 break;
1216 }
1217 }
1218
1219 i++;
1220 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1221 "Free window: Adding window " + this + " at " + i + " of " + mWindows.size());
1222 mWindows.add(i, win);
1223 mService.mWindowsChanged = true;
1224 }
1225
Wale Ogunwaleb9a07c32016-10-12 14:55:56 -07001226 void addToWindowList(WindowState win, int index) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001227 mService.mWindowsChanged = true;
Wale Ogunwaleb9a07c32016-10-12 14:55:56 -07001228 mWindows.add(index, win);
1229 }
1230
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001231 boolean removeFromWindowList(WindowState win) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001232 mService.mWindowsChanged = true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001233 return mWindows.remove(win);
1234 }
1235
1236 private int removeWindowAndChildrenFromWindowList(WindowState win, int interestingPos) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001237 int wpos = mWindows.indexOf(win);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001238 if (wpos < 0) {
1239 return interestingPos;
1240 }
1241
1242 if (wpos < interestingPos) interestingPos--;
1243 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001244 mWindows.remove(wpos);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001245 mService.mWindowsChanged = true;
1246 int childWinCount = win.mChildren.size();
1247 while (childWinCount > 0) {
1248 childWinCount--;
1249 final WindowState cw = win.mChildren.get(childWinCount);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001250 int cpos = mWindows.indexOf(cw);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001251 if (cpos >= 0) {
1252 if (cpos < interestingPos) interestingPos--;
1253 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
1254 "Temp removing child at " + cpos + ": " + cw);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001255 mWindows.remove(cpos);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001256 }
1257 }
1258 return interestingPos;
1259 }
1260
Wale Ogunwaleec731152016-09-08 20:18:57 -07001261 void addChildWindowToWindowList(WindowState win) {
1262 final WindowState parentWindow = win.getParentWindow();
1263
1264 WindowList windowsOnSameDisplay = getTokenWindowsOnDisplay(win.mToken);
1265
1266 // Figure out this window's ordering relative to the parent window.
1267 final int wCount = windowsOnSameDisplay.size();
1268 final int sublayer = win.mSubLayer;
1269 int largestSublayer = Integer.MIN_VALUE;
1270 WindowState windowWithLargestSublayer = null;
1271 int i;
1272 for (i = 0; i < wCount; i++) {
1273 WindowState w = windowsOnSameDisplay.get(i);
1274 final int wSublayer = w.mSubLayer;
1275 if (wSublayer >= largestSublayer) {
1276 largestSublayer = wSublayer;
1277 windowWithLargestSublayer = w;
1278 }
1279 if (sublayer < 0) {
1280 // For negative sublayers, we go below all windows in the same sublayer.
1281 if (wSublayer >= sublayer) {
1282 addWindowToListBefore(win, wSublayer >= 0 ? parentWindow : w);
1283 break;
1284 }
1285 } else {
1286 // For positive sublayers, we go above all windows in the same sublayer.
1287 if (wSublayer > sublayer) {
1288 addWindowToListBefore(win, w);
1289 break;
1290 }
1291 }
1292 }
1293 if (i >= wCount) {
1294 if (sublayer < 0) {
1295 addWindowToListBefore(win, parentWindow);
1296 } else {
1297 addWindowToListAfter(win,
1298 largestSublayer >= 0 ? windowWithLargestSublayer : parentWindow);
1299 }
1300 }
1301 }
1302
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001303 /** Updates the layer assignment of windows on this display. */
1304 void assignWindowLayers(boolean setLayoutNeeded) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001305 mLayersController.assignWindowLayers(mWindows.getReadOnly());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001306 if (setLayoutNeeded) {
1307 setLayoutNeeded();
1308 }
1309 }
1310
Wale Ogunwale0303c572016-10-20 10:16:29 -07001311 void adjustWallpaperWindows() {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001312 if (mWallpaperController.adjustWallpaperWindows(mWindows.getReadOnly())) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07001313 assignWindowLayers(true /*setLayoutNeeded*/);
1314 }
1315 }
1316
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001317 /**
1318 * Z-orders the display window list so that:
1319 * <ul>
1320 * <li>Any windows that are currently below the wallpaper window stay below the wallpaper
1321 * window.
1322 * <li>Exiting application windows are at the bottom, but above the wallpaper window.
1323 * <li>All other application windows are above the exiting application windows and ordered based
1324 * on the ordering of their stacks and tasks on the display.
1325 * <li>Non-application windows are at the very top.
1326 * </ul>
1327 * <p>
1328 * NOTE: This isn't a complete picture of what the user see. Further manipulation of the window
1329 * surface layering is done in {@link WindowLayersController}.
1330 */
1331 void rebuildAppWindowList() {
1332 int count = mWindows.size();
1333 int i;
1334 int lastBelow = -1;
1335 int numRemoved = 0;
1336
1337 if (mRebuildTmp.length < count) {
1338 mRebuildTmp = new WindowState[count + 10];
1339 }
1340
1341 // First remove all existing app windows.
1342 i = 0;
1343 while (i < count) {
1344 final WindowState w = mWindows.get(i);
1345 if (w.mAppToken != null) {
1346 final WindowState win = mWindows.remove(i);
1347 win.mRebuilding = true;
1348 mRebuildTmp[numRemoved] = win;
1349 mService.mWindowsChanged = true;
1350 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Rebuild removing window: " + win);
1351 count--;
1352 numRemoved++;
1353 continue;
1354 } else if (lastBelow == i-1) {
1355 if (w.mAttrs.type == TYPE_WALLPAPER) {
1356 lastBelow = i;
1357 }
1358 }
1359 i++;
1360 }
1361
1362 // Keep whatever windows were below the app windows still below, by skipping them.
1363 lastBelow++;
1364 i = lastBelow;
1365
1366 // First add all of the exiting app tokens... these are no longer in the main app list,
1367 // but still have windows shown. We put them in the back because now that the animation is
1368 // over we no longer will care about them.
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001369 final int numStacks = mTaskStackContainers.size();
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001370 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001371 AppTokenList exitingAppTokens = mTaskStackContainers.get(stackNdx).mExitingAppTokens;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001372 int NT = exitingAppTokens.size();
1373 for (int j = 0; j < NT; j++) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001374 i = exitingAppTokens.get(j).rebuildWindowListUnchecked(i);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001375 }
1376 }
1377
1378 // And add in the still active app tokens in Z order.
1379 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001380 i = mTaskStackContainers.get(stackNdx).rebuildWindowList(i);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001381 }
1382
1383 i -= lastBelow;
1384 if (i != numRemoved) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001385 setLayoutNeeded();
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001386 Slog.w(TAG_WM, "On display=" + mDisplayId + " Rebuild removed " + numRemoved
1387 + " windows but added " + i + " rebuildAppWindowListLocked() "
1388 + " callers=" + Debug.getCallers(10));
1389 for (i = 0; i < numRemoved; i++) {
1390 WindowState ws = mRebuildTmp[i];
1391 if (ws.mRebuilding) {
1392 StringWriter sw = new StringWriter();
1393 PrintWriter pw = new FastPrintWriter(sw, false, 1024);
1394 ws.dump(pw, "", true);
1395 pw.flush();
1396 Slog.w(TAG_WM, "This window was lost: " + ws);
1397 Slog.w(TAG_WM, sw.toString());
1398 ws.mWinAnimator.destroySurfaceLocked();
1399 }
1400 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001401 Slog.w(TAG_WM, "Current window hierarchy:");
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001402 dumpChildrenNames();
1403 Slog.w(TAG_WM, "Final window list:");
1404 dumpWindows();
1405 }
1406 Arrays.fill(mRebuildTmp, null);
1407 }
1408
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001409 /** Rebuilds the display's window list and does a relayout if something changed. */
1410 void rebuildAppWindowsAndLayoutIfNeeded() {
1411 mTmpWindows.clear();
1412 mTmpWindows.addAll(mWindows);
1413
1414 rebuildAppWindowList();
1415
1416 // Set displayContent.mLayoutNeeded if window order changed.
1417 final int tmpSize = mTmpWindows.size();
1418 final int winSize = mWindows.size();
1419 int tmpNdx = 0, winNdx = 0;
1420 while (tmpNdx < tmpSize && winNdx < winSize) {
1421 // Skip over all exiting windows, they've been moved out of order.
1422 WindowState tmp;
1423 do {
1424 tmp = mTmpWindows.get(tmpNdx++);
1425 } while (tmpNdx < tmpSize && tmp.mAppToken != null && tmp.mAppToken.mIsExiting);
1426
1427 WindowState win;
1428 do {
1429 win = mWindows.get(winNdx++);
1430 } while (winNdx < winSize && win.mAppToken != null && win.mAppToken.mIsExiting);
1431
1432 if (tmp != win) {
1433 // Window order changed.
1434 setLayoutNeeded();
1435 break;
1436 }
1437 }
1438 if (tmpNdx != winNdx) {
1439 // One list was different from the other.
1440 setLayoutNeeded();
1441 }
1442 mTmpWindows.clear();
1443
1444 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
1445 false /*updateInputWindows*/)) {
1446 assignWindowLayers(false /* setLayoutNeeded */);
1447 }
1448
1449 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
1450 mService.mWindowPlacerLocked.performSurfacePlacement();
1451 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1452 }
1453
1454 void updateInputWindows(InputMonitor inputMonitor, WindowState inputFocus, boolean inDrag) {
1455 final InputConsumerImpl navInputConsumer =
1456 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_NAVIGATION, mDisplayId);
1457 final InputConsumerImpl pipInputConsumer =
1458 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_PIP, mDisplayId);
1459 final InputConsumerImpl wallpaperInputConsumer =
1460 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_WALLPAPER, mDisplayId);
1461 boolean addInputConsumerHandle = navInputConsumer != null;
1462 boolean addPipInputConsumerHandle = pipInputConsumer != null;
1463 boolean addWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
1464 final Rect pipTouchableBounds = addPipInputConsumerHandle ? new Rect() : null;
1465 boolean disableWallpaperTouchEvents = false;
1466
1467 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
1468 final WindowState child = mWindows.get(winNdx);
1469 final InputChannel inputChannel = child.mInputChannel;
1470 final InputWindowHandle inputWindowHandle = child.mInputWindowHandle;
1471 if (inputChannel == null || inputWindowHandle == null || child.mRemoved
1472 || child.isAdjustedForMinimizedDock()) {
1473 // Skip this window because it cannot possibly receive input.
1474 continue;
1475 }
1476
1477 if (addPipInputConsumerHandle
1478 && child.getStackId() == PINNED_STACK_ID
1479 && inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer) {
1480 // Update the bounds of the Pip input consumer to match the Pinned stack
1481 child.getStack().getBounds(pipTouchableBounds);
1482 pipInputConsumer.mWindowHandle.touchableRegion.set(pipTouchableBounds);
1483 inputMonitor.addInputWindowHandle(pipInputConsumer.mWindowHandle);
1484 addPipInputConsumerHandle = false;
1485 }
1486
1487 if (addInputConsumerHandle
1488 && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) {
1489 inputMonitor.addInputWindowHandle(navInputConsumer.mWindowHandle);
1490 addInputConsumerHandle = false;
1491 }
1492
1493 if (addWallpaperInputConsumerHandle) {
1494 if (child.mAttrs.type == TYPE_WALLPAPER && child.isVisibleLw()) {
1495 // Add the wallpaper input consumer above the first visible wallpaper.
1496 inputMonitor.addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
1497 addWallpaperInputConsumerHandle = false;
1498 }
1499 }
1500
1501 final int flags = child.mAttrs.flags;
1502 final int privateFlags = child.mAttrs.privateFlags;
1503 final int type = child.mAttrs.type;
1504
1505 final boolean hasFocus = child == inputFocus;
1506 final boolean isVisible = child.isVisibleLw();
1507 if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
1508 disableWallpaperTouchEvents = true;
1509 }
1510 final boolean hasWallpaper = mWallpaperController.isWallpaperTarget(child)
1511 && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
1512 && !disableWallpaperTouchEvents;
1513
1514 // If there's a drag in progress and 'child' is a potential drop target,
1515 // make sure it's been told about the drag
1516 if (inDrag && isVisible && isDefaultDisplay) {
1517 mService.mDragState.sendDragStartedIfNeededLw(child);
1518 }
1519
1520 inputMonitor.addInputWindowHandle(
1521 inputWindowHandle, child, flags, type, isVisible, hasFocus, hasWallpaper);
1522 }
1523
1524 if (addWallpaperInputConsumerHandle) {
1525 // No visible wallpaper found, add the wallpaper input consumer at the end.
1526 inputMonitor.addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
1527 }
1528 }
1529
1530 /** Returns true if a leaked surface was destroyed */
1531 boolean destroyLeakedSurfaces() {
1532 boolean leakedSurface = false;
1533 final int numWindows = mWindows.size();
1534 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
1535 final WindowState ws = mWindows.get(winNdx);
1536 final WindowStateAnimator wsa = ws.mWinAnimator;
1537 if (wsa.mSurfaceController == null) {
1538 continue;
1539 }
1540 if (!mService.mSessions.contains(wsa.mSession)) {
1541 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
1542 + ws + " surface=" + wsa.mSurfaceController
1543 + " token=" + ws.mToken
1544 + " pid=" + ws.mSession.mPid
1545 + " uid=" + ws.mSession.mUid);
1546 wsa.destroySurface();
1547 mService.mForceRemoves.add(ws);
1548 leakedSurface = true;
1549 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
1550 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
1551 + ws + " surface=" + wsa.mSurfaceController
1552 + " token=" + ws.mAppToken
1553 + " saved=" + ws.hasSavedSurface());
1554 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", false);
1555 wsa.destroySurface();
1556 leakedSurface = true;
1557 }
1558 }
1559
1560 return leakedSurface;
1561 }
1562
Wale Ogunwaleec731152016-09-08 20:18:57 -07001563 /** Return the list of Windows on this display associated with the input token. */
1564 WindowList getTokenWindowsOnDisplay(WindowToken token) {
1565 final WindowList windowList = new WindowList();
1566 final int count = mWindows.size();
1567 for (int i = 0; i < count; i++) {
1568 final WindowState win = mWindows.get(i);
1569 if (win.mToken == token) {
1570 windowList.add(win);
1571 }
1572 }
1573 return windowList;
1574 }
1575
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001576 private void reAddToWindowList(WindowState win) {
1577 win.mToken.addWindow(win);
1578 // This is a hack to get all of the child windows added as well at the right position. Child
1579 // windows should be rare and this case should be rare, so it shouldn't be that big a deal.
1580 int wpos = mWindows.indexOf(win);
1581 if (wpos >= 0) {
1582 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "ReAdd removing from " + wpos + ": " + win);
1583 mWindows.remove(wpos);
1584 mService.mWindowsChanged = true;
1585 win.reAddWindow(wpos);
1586 }
1587 }
1588
1589 void moveInputMethodDialogs(int pos) {
1590 ArrayList<WindowState> dialogs = mService.mInputMethodDialogs;
1591
1592 final int N = dialogs.size();
1593 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Removing " + N + " dialogs w/pos=" + pos);
1594 for (int i = 0; i < N; i++) {
1595 pos = removeWindowAndChildrenFromWindowList(dialogs.get(i), pos);
1596 }
1597 if (DEBUG_INPUT_METHOD) {
1598 Slog.v(TAG_WM, "Window list w/pos=" + pos);
1599 logWindowList(mWindows, " ");
1600 }
1601
1602 WindowState ime = mService.mInputMethodWindow;
1603 if (pos >= 0) {
1604 // Skip windows owned by the input method.
1605 if (ime != null) {
1606 while (pos < mWindows.size()) {
1607 WindowState wp = mWindows.get(pos);
1608 if (wp == ime || wp.getParentWindow() == ime) {
1609 pos++;
1610 continue;
1611 }
1612 break;
1613 }
1614 }
1615 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Adding " + N + " dialogs at pos=" + pos);
1616 for (int i=0; i<N; i++) {
1617 WindowState win = dialogs.get(i);
1618 pos = win.reAddWindow(pos);
1619 }
1620 if (DEBUG_INPUT_METHOD) {
1621 Slog.v(TAG_WM, "Final window list:");
1622 logWindowList(mWindows, " ");
1623 }
1624 return;
1625 }
1626 for (int i=0; i<N; i++) {
1627 WindowState win = dialogs.get(i);
1628 reAddToWindowList(win);
1629 if (DEBUG_INPUT_METHOD) {
1630 Slog.v(TAG_WM, "No IM target, final list:");
1631 logWindowList(mWindows, " ");
1632 }
1633 }
1634 }
1635
1636 boolean moveInputMethodWindowsIfNeeded(boolean needAssignLayers) {
1637 final WindowState imWin = mService.mInputMethodWindow;
1638 final int DN = mService.mInputMethodDialogs.size();
1639 if (imWin == null && DN == 0) {
1640 return false;
1641 }
1642
1643 // TODO(multidisplay): IMEs are only supported on the default display.
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001644 int imPos = findDesiredInputMethodWindowIndex(true);
1645 if (imPos >= 0) {
1646 // In this case, the input method windows are to be placed
1647 // immediately above the window they are targeting.
1648
1649 // First check to see if the input method windows are already
1650 // located here, and contiguous.
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001651 final int N = mWindows.size();
1652 final WindowState firstImWin = imPos < N ? mWindows.get(imPos) : null;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001653
1654 // Figure out the actual input method window that should be
1655 // at the bottom of their stack.
1656 WindowState baseImWin = imWin != null ? imWin : mService.mInputMethodDialogs.get(0);
1657 final WindowState cw = baseImWin.getBottomChild();
1658 if (cw != null && cw.mSubLayer < 0) {
1659 baseImWin = cw;
1660 }
1661
1662 if (firstImWin == baseImWin) {
1663 // The windows haven't moved... but are they still contiguous?
1664 // First find the top IM window.
1665 int pos = imPos+1;
1666 while (pos < N) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001667 if (!(mWindows.get(pos)).mIsImWindow) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001668 break;
1669 }
1670 pos++;
1671 }
1672 pos++;
1673 // Now there should be no more input method windows above.
1674 while (pos < N) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001675 if ((mWindows.get(pos)).mIsImWindow) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001676 break;
1677 }
1678 pos++;
1679 }
1680 if (pos >= N) {
1681 return false;
1682 }
1683 }
1684
1685 if (imWin != null) {
1686 if (DEBUG_INPUT_METHOD) {
1687 Slog.v(TAG_WM, "Moving IM from " + imPos);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001688 logWindowList(mWindows, " ");
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001689 }
1690 imPos = removeWindowAndChildrenFromWindowList(imWin, imPos);
1691 if (DEBUG_INPUT_METHOD) {
1692 Slog.v(TAG_WM, "List after removing with new pos " + imPos + ":");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001693 logWindowList(mWindows, " ");
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001694 }
1695 imWin.reAddWindow(imPos);
1696 if (DEBUG_INPUT_METHOD) {
1697 Slog.v(TAG_WM, "List after moving IM to " + imPos + ":");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001698 logWindowList(mWindows, " ");
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001699 }
1700 if (DN > 0) moveInputMethodDialogs(imPos+1);
1701 } else {
1702 moveInputMethodDialogs(imPos);
1703 }
1704
1705 } else {
1706 // In this case, the input method windows go in a fixed layer,
1707 // because they aren't currently associated with a focus window.
1708
1709 if (imWin != null) {
1710 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Moving IM from " + imPos);
1711 removeWindowAndChildrenFromWindowList(imWin, 0);
1712 reAddToWindowList(imWin);
1713 if (DEBUG_INPUT_METHOD) {
1714 Slog.v(TAG_WM, "List with no IM target:");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001715 logWindowList(mWindows, " ");
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001716 }
1717 if (DN > 0) moveInputMethodDialogs(-1);
1718 } else {
1719 moveInputMethodDialogs(-1);
1720 }
1721
1722 }
1723
1724 if (needAssignLayers) {
1725 assignWindowLayers(false /* setLayoutNeeded */);
1726 }
1727
1728 return true;
1729 }
1730
1731 /**
1732 * Dig through the WindowStates and find the one that the Input Method will target.
1733 * @param willMove
1734 * @return The index+1 in mWindows of the discovered target.
1735 */
1736 int findDesiredInputMethodWindowIndex(boolean willMove) {
1737 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
1738 // same display. Or even when the current IME/target are not on the same screen as the next
1739 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001740 WindowState w = null;
1741 int i;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001742 for (i = mWindows.size() - 1; i >= 0; --i) {
1743 final WindowState win = mWindows.get(i);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001744
1745 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG_WM, "Checking window @" + i
1746 + " " + win + " fl=0x" + Integer.toHexString(win.mAttrs.flags));
1747 if (canBeImeTarget(win)) {
1748 w = win;
1749 //Slog.i(TAG_WM, "Putting input method here!");
1750
1751 // Yet more tricksyness! If this window is a "starting" window, we do actually want
1752 // to be on top of it, but it is not -really- where input will go. So if the caller
1753 // is not actually looking to move the IME, look down below for a real window to
1754 // target...
1755 if (!willMove && w.mAttrs.type == TYPE_APPLICATION_STARTING && i > 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001756 final WindowState wb = mWindows.get(i-1);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001757 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1758 i--;
1759 w = wb;
1760 }
1761 }
1762 break;
1763 }
1764 }
1765
1766 // Now w is either mWindows[0] or an IME (or null if mWindows is empty).
1767
1768 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG_WM, "Proposed new IME target: " + w);
1769
1770 // Now, a special case -- if the last target's window is in the process of exiting, and is
1771 // above the new target, keep on the last target to avoid flicker. Consider for example a
1772 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
1773 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
1774 // scrim.
1775 final WindowState curTarget = mService.mInputMethodTarget;
1776 if (curTarget != null
1777 && curTarget.isDisplayedLw()
1778 && curTarget.isClosing()
1779 && (w == null || curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer)) {
1780 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001781 return mWindows.indexOf(curTarget) + 1;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001782 }
1783
1784 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target="
1785 + w + " willMove=" + willMove);
1786
1787 if (willMove && w != null) {
1788 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
1789 if (token != null) {
1790
1791 // Now some fun for dealing with window animations that modify the Z order. We need
1792 // to look at all windows below the current target that are in this app, finding the
1793 // highest visible one in layering.
1794 WindowState highestTarget = null;
1795 int highestPos = 0;
1796 if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001797 WindowList curWindows = token.getDisplayContent().mWindows;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001798 int pos = curWindows.indexOf(curTarget);
1799 while (pos >= 0) {
1800 WindowState win = curWindows.get(pos);
1801 if (win.mAppToken != token) {
1802 break;
1803 }
1804 if (!win.mRemoved) {
1805 if (highestTarget == null || win.mWinAnimator.mAnimLayer >
1806 highestTarget.mWinAnimator.mAnimLayer) {
1807 highestTarget = win;
1808 highestPos = pos;
1809 }
1810 }
1811 pos--;
1812 }
1813 }
1814
1815 if (highestTarget != null) {
1816 final AppTransition appTransition = mService.mAppTransition;
1817 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
1818 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
1819 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
1820 + " new layer=" + w.mWinAnimator.mAnimLayer);
1821
1822 if (appTransition.isTransitionSet()) {
1823 // If we are currently setting up for an animation, hold everything until we
1824 // can find out what will happen.
1825 mService.mInputMethodTargetWaitingAnim = true;
1826 mService.mInputMethodTarget = highestTarget;
1827 return highestPos + 1;
1828 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
1829 highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) {
1830 // If the window we are currently targeting is involved with an animation,
1831 // and it is on top of the next target we will be over, then hold off on
1832 // moving until that is done.
1833 mService.mInputMethodTargetWaitingAnim = true;
1834 mService.mInputMethodTarget = highestTarget;
1835 return highestPos + 1;
1836 }
1837 }
1838 }
1839 }
1840
1841 //Slog.i(TAG_WM, "Placing input method @" + (i+1));
1842 if (w != null) {
1843 if (willMove) {
1844 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
1845 + w + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
1846 mService.mInputMethodTarget = w;
1847 mService.mInputMethodTargetWaitingAnim = false;
1848 if (w.mAppToken != null) {
1849 setInputMethodAnimLayerAdjustment(
1850 w.mAppToken.mAppAnimator.animLayerAdjustment);
1851 } else {
1852 setInputMethodAnimLayerAdjustment(0);
1853 }
1854 }
1855
1856 // If the docked divider is visible, we still need to go through this whole excercise to
1857 // find the appropriate input method target (used for animations and dialog
1858 // adjustments), but for purposes of Z ordering we simply wish to place it above the
1859 // docked divider. Unless it is already above the divider.
1860 final WindowState dockedDivider = mDividerControllerLocked.getWindow();
1861 if (dockedDivider != null && dockedDivider.isVisibleLw()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001862 int dividerIndex = mWindows.indexOf(dockedDivider);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001863 if (dividerIndex > 0 && dividerIndex > i) {
1864 return dividerIndex + 1;
1865 }
1866 }
1867 return i+1;
1868 }
1869 if (willMove) {
1870 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
1871 + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
1872 mService.mInputMethodTarget = null;
1873 setInputMethodAnimLayerAdjustment(0);
1874 }
1875 return -1;
1876 }
1877
1878 private static boolean canBeImeTarget(WindowState w) {
1879 final int fl = w.mAttrs.flags & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1880 final int type = w.mAttrs.type;
1881
1882 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
1883 && type != TYPE_APPLICATION_STARTING) {
1884 return false;
1885 }
1886
1887 if (DEBUG_INPUT_METHOD) {
1888 Slog.i(TAG_WM, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1889 if (!w.isVisibleOrAdding()) {
1890 Slog.i(TAG_WM, " mSurfaceController=" + w.mWinAnimator.mSurfaceController
1891 + " relayoutCalled=" + w.mRelayoutCalled
1892 + " viewVis=" + w.mViewVisibility
1893 + " policyVis=" + w.mPolicyVisibility
1894 + " policyVisAfterAnim=" + w.mPolicyVisibilityAfterAnim
1895 + " parentHidden=" + w.isParentWindowHidden()
1896 + " exiting=" + w.mAnimatingExit + " destroying=" + w.mDestroying);
1897 if (w.mAppToken != null) {
1898 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1899 }
1900 }
1901 }
1902 return w.isVisibleOrAdding();
1903 }
1904
1905 private void logWindowList(final WindowList windows, String prefix) {
1906 int N = windows.size();
1907 while (N > 0) {
1908 N--;
1909 Slog.v(TAG_WM, prefix + "#" + N + ": " + windows.get(N));
1910 }
1911 }
1912
1913 boolean getNeedsMenu(WindowState win, WindowManagerPolicy.WindowState bottom) {
1914 int index = -1;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001915 while (true) {
1916 if (win.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
1917 return win.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
1918 }
1919 // If we reached the bottom of the range of windows we are considering,
1920 // assume no menu is needed.
1921 if (win == bottom) {
1922 return false;
1923 }
1924 // The current window hasn't specified whether menu key is needed; look behind it.
1925 // First, we may need to determine the starting position.
1926 if (index < 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001927 index = mWindows.indexOf(win);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001928 }
1929 index--;
1930 if (index < 0) {
1931 return false;
1932 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001933 win = mWindows.get(index);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001934 }
1935 }
1936
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001937 void setLayoutNeeded() {
1938 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
1939 mLayoutNeeded = true;
1940 }
1941
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001942 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001943 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
1944 mLayoutNeeded = false;
1945 }
1946
1947 boolean isLayoutNeeded() {
1948 return mLayoutNeeded;
1949 }
1950
Wale Ogunwale07bcab72016-10-14 15:30:09 -07001951 private void addAppWindowExisting(WindowState win, WindowList tokenWindowList) {
Wale Ogunwaleec731152016-09-08 20:18:57 -07001952
Wale Ogunwaleec731152016-09-08 20:18:57 -07001953 // If this application has existing windows, we simply place the new window on top of
1954 // them... but keep the starting window on top.
1955 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1956 // Base windows go behind everything else.
1957 final WindowState lowestWindow = tokenWindowList.get(0);
1958 addWindowToListBefore(win, lowestWindow);
Wale Ogunwaleec731152016-09-08 20:18:57 -07001959 } else {
1960 final AppWindowToken atoken = win.mAppToken;
1961 final int windowListPos = tokenWindowList.size();
1962 final WindowState lastWindow = tokenWindowList.get(windowListPos - 1);
1963 if (atoken != null && lastWindow == atoken.startingWindow) {
1964 addWindowToListBefore(win, lastWindow);
Wale Ogunwaleec731152016-09-08 20:18:57 -07001965 } else {
1966 int newIdx = findIdxBasedOnAppTokens(win);
1967 // There is a window above this one associated with the same apptoken note that the
1968 // window could be a floating window that was created later or a window at the top
1969 // of the list of windows associated with this token.
1970 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1971 "not Base app: Adding window " + win + " at " + (newIdx + 1) + " of "
1972 + mWindows.size());
1973 mWindows.add(newIdx + 1, win);
Wale Ogunwaleec731152016-09-08 20:18:57 -07001974 mService.mWindowsChanged = true;
1975 }
1976 }
Wale Ogunwaleec731152016-09-08 20:18:57 -07001977 }
1978
1979 /** Places the first input window after the second input window in the window list. */
1980 private void addWindowToListAfter(WindowState first, WindowState second) {
1981 final int i = mWindows.indexOf(second);
1982 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1983 "Adding window " + this + " at " + (i + 1) + " of " + mWindows.size()
1984 + " (after " + second + ")");
1985 mWindows.add(i + 1, first);
1986 mService.mWindowsChanged = true;
1987 }
1988
1989 /** Places the first input window before the second input window in the window list. */
1990 private void addWindowToListBefore(WindowState first, WindowState second) {
1991 int i = mWindows.indexOf(second);
1992 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1993 "Adding window " + this + " at " + i + " of " + mWindows.size()
1994 + " (before " + second + ")");
1995 if (i < 0) {
1996 Slog.w(TAG_WM, "addWindowToListBefore: Unable to find " + second + " in " + mWindows);
1997 i = 0;
1998 }
1999 mWindows.add(i, first);
2000 mService.mWindowsChanged = true;
2001 }
2002
2003 /**
2004 * This method finds out the index of a window that has the same app token as win. used for z
2005 * ordering the windows in mWindows
2006 */
2007 private int findIdxBasedOnAppTokens(WindowState win) {
2008 for(int j = mWindows.size() - 1; j >= 0; j--) {
2009 final WindowState wentry = mWindows.get(j);
2010 if(wentry.mAppToken == win.mAppToken) {
2011 return j;
2012 }
2013 }
2014 return -1;
2015 }
2016
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002017 private void dumpChildrenNames() {
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002018 StringBuilder output = new StringBuilder();
2019 dumpChildrenNames(output, " ");
2020 Slog.v(TAG_WM, output.toString());
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002021 }
2022
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002023 private void dumpWindows() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002024 Slog.v(TAG_WM, " Display #" + mDisplayId);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002025 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
2026 Slog.v(TAG_WM, " #" + winNdx + ": " + mWindows.get(winNdx));
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002027 }
2028 }
2029
Wale Ogunwale02319a62016-09-26 15:21:22 -07002030 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2031 if (mTokenMap.isEmpty()) {
2032 return;
2033 }
2034 pw.println(" Display #" + mDisplayId);
2035 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2036 while (it.hasNext()) {
2037 final WindowToken token = it.next();
2038 pw.print(" ");
2039 pw.print(token);
2040 if (dumpAll) {
2041 pw.println(':');
2042 token.dump(pw, " ");
2043 } else {
2044 pw.println();
2045 }
2046 }
2047 }
2048
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002049 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
2050 final int count = mWindows.size();
2051 for (int j = 0; j < count; j++) {
2052 final WindowStateAnimator wAnim = mWindows.get(j).mWinAnimator;
2053 pw.println(subPrefix + "Window #" + j + ": " + wAnim);
2054 }
2055 }
2056
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002057 void enableSurfaceTrace(FileDescriptor fd) {
2058 for (int i = mWindows.size() - 1; i >= 0; i--) {
2059 final WindowState win = mWindows.get(i);
2060 win.mWinAnimator.enableSurfaceTrace(fd);
2061 }
2062 }
2063
2064 void disableSurfaceTrace() {
2065 for (int i = mWindows.size() - 1; i >= 0; i--) {
2066 final WindowState win = mWindows.get(i);
2067 win.mWinAnimator.disableSurfaceTrace();
2068 }
2069 }
2070
Jorim Jaggife762342016-10-13 14:33:27 +02002071 /**
2072 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2073 */
2074 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2075 final WindowManagerPolicy policy = mService.mPolicy;
2076 for (int i = mWindows.size() - 1; i >= 0; i--) {
2077 final WindowState window = mWindows.get(i);
2078 if (window.mAppToken == null && policy.canBeHiddenByKeyguardLw(window)) {
2079 window.mWinAnimator.setAnimation(
2080 policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
2081 }
2082 }
2083 }
2084
Wale Ogunwale494009b82016-10-21 09:01:38 -07002085 boolean checkWaitingForWindows() {
2086
2087 boolean haveBootMsg = false;
2088 boolean haveApp = false;
2089 // if the wallpaper service is disabled on the device, we're never going to have
2090 // wallpaper, don't bother waiting for it
2091 boolean haveWallpaper = false;
2092 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2093 com.android.internal.R.bool.config_enableWallpaperService)
2094 && !mService.mOnlyCore;
2095 boolean haveKeyguard = true;
2096 final int count = mWindows.size();
2097 for (int i = 0; i < count; i++) {
2098 final WindowState w = mWindows.get(i);
2099 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2100 return true;
2101 }
2102 if (w.isDrawnLw()) {
2103 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
2104 haveBootMsg = true;
2105 } else if (w.mAttrs.type == TYPE_APPLICATION
2106 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
2107 haveApp = true;
2108 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
2109 haveWallpaper = true;
2110 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
2111 haveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
2112 }
2113 }
2114 }
2115
2116 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2117 "******** booted=" + mService.mSystemBooted
2118 + " msg=" + mService.mShowingBootMessages
2119 + " haveBoot=" + haveBootMsg + " haveApp=" + haveApp
2120 + " haveWall=" + haveWallpaper + " wallEnabled=" + wallpaperEnabled
2121 + " haveKeyguard=" + haveKeyguard);
2122
2123 // If we are turning on the screen to show the boot message, don't do it until the boot
2124 // message is actually displayed.
2125 if (!mService.mSystemBooted && !haveBootMsg) {
2126 return true;
2127 }
2128
2129 // If we are turning on the screen after the boot is completed normally, don't do so until
2130 // we have the application and wallpaper.
2131 if (mService.mSystemBooted && ((!haveApp && !haveKeyguard) ||
2132 (wallpaperEnabled && !haveWallpaper))) {
2133 return true;
2134 }
2135
2136 return false;
2137 }
2138
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002139 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07002140 final WallpaperController wallpaperController = mWallpaperController;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002141 for (int i = mWindows.size() - 1; i >= 0; i--) {
2142 WindowState win = mWindows.get(i);
2143 WindowStateAnimator winAnimator = win.mWinAnimator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002144 if (winAnimator.hasSurface()) {
2145 final boolean wasAnimating = winAnimator.mWasAnimating;
2146 final boolean nowAnimating = winAnimator.stepAnimationLocked(animator.mCurrentTime);
2147 winAnimator.mWasAnimating = nowAnimating;
2148 animator.orAnimating(nowAnimating);
2149
2150 if (DEBUG_WALLPAPER) Slog.v(TAG,
2151 win + ": wasAnimating=" + wasAnimating + ", nowAnimating=" + nowAnimating);
2152
2153 if (wasAnimating && !winAnimator.mAnimating
2154 && wallpaperController.isWallpaperTarget(win)) {
2155 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2156 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
2157 if (DEBUG_LAYOUT_REPEATS) {
2158 mService.mWindowPlacerLocked.debugLayoutRepeats(
2159 "updateWindowsAndWallpaperLocked 2", pendingLayoutChanges);
2160 }
2161 }
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002162 }
2163
2164 final AppWindowToken atoken = win.mAppToken;
2165 if (winAnimator.mDrawState == READY_TO_SHOW) {
2166 if (atoken == null || atoken.allDrawn) {
2167 if (win.performShowLocked()) {
2168 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
2169 if (DEBUG_LAYOUT_REPEATS) {
2170 mService.mWindowPlacerLocked.debugLayoutRepeats(
2171 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
2172 }
2173 }
2174 }
2175 }
2176 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
2177 if (appAnimator != null && appAnimator.thumbnail != null) {
2178 if (appAnimator.thumbnailTransactionSeq != animator.mAnimTransactionSequence) {
2179 appAnimator.thumbnailTransactionSeq = animator.mAnimTransactionSequence;
2180 appAnimator.thumbnailLayer = 0;
2181 }
2182 if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
2183 appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
2184 }
2185 }
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002186 } // end forall windows
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002187 }
2188
2189 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002190 resetAnimationBackgroundAnimator();
2191
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002192 final WindowList windows = mWindows;
2193 WindowState detachedWallpaper = null;
2194
2195 for (int i = windows.size() - 1; i >= 0; i--) {
2196 final WindowState win = windows.get(i);
2197 final WindowStateAnimator winAnimator = win.mWinAnimator;
2198 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
2199 continue;
2200 }
2201
2202 final int flags = win.mAttrs.flags;
2203
2204 // If this window is animating, make a note that we have an animating window and take
2205 // care of a request to run a detached wallpaper animation.
2206 if (winAnimator.mAnimating) {
2207 if (winAnimator.mAnimation != null) {
2208 if ((flags & FLAG_SHOW_WALLPAPER) != 0
2209 && winAnimator.mAnimation.getDetachWallpaper()) {
2210 detachedWallpaper = win;
2211 }
2212 final int color = winAnimator.mAnimation.getBackgroundColor();
2213 if (color != 0) {
2214 final TaskStack stack = win.getStack();
2215 if (stack != null) {
2216 stack.setAnimationBackground(winAnimator, color);
2217 }
2218 }
2219 }
2220 animator.setAnimating(true);
2221 }
2222
2223 // If this window's app token is running a detached wallpaper animation, make a note so
2224 // we can ensure the wallpaper is displayed behind it.
2225 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
2226 if (appAnimator != null && appAnimator.animation != null
2227 && appAnimator.animating) {
2228 if ((flags & FLAG_SHOW_WALLPAPER) != 0
2229 && appAnimator.animation.getDetachWallpaper()) {
2230 detachedWallpaper = win;
2231 }
2232
2233 final int color = appAnimator.animation.getBackgroundColor();
2234 if (color != 0) {
2235 final TaskStack stack = win.getStack();
2236 if (stack != null) {
2237 stack.setAnimationBackground(winAnimator, color);
2238 }
2239 }
2240 }
2241 } // end forall windows
2242
2243 if (animator.mWindowDetachedWallpaper != detachedWallpaper) {
2244 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
2245 + animator.mWindowDetachedWallpaper + " to " + detachedWallpaper);
2246 animator.mWindowDetachedWallpaper = detachedWallpaper;
2247 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2248 }
2249 }
2250
2251 void prepareWindowSurfaces() {
2252 final int count = mWindows.size();
2253 for (int j = 0; j < count; j++) {
2254 mWindows.get(j).mWinAnimator.prepareSurfaceLocked(true);
2255 }
2256 }
2257
Wale Ogunwale494009b82016-10-21 09:01:38 -07002258 boolean inputMethodClientHasFocus(IInputMethodClient client) {
2259 // The focus for the client is the window immediately below where we would place the input
2260 // method window.
2261 int idx = findDesiredInputMethodWindowIndex(false);
2262 if (idx <= 0) {
2263 return false;
2264 }
2265
2266 WindowState imFocus = mWindows.get(idx - 1);
2267 if (DEBUG_INPUT_METHOD) {
2268 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2269 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2270 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
2271 }
2272
2273 if (imFocus == null) {
2274 return false;
2275 }
2276
2277 // This may be a starting window, in which case we still want to count it as okay.
2278 if (imFocus.mAttrs.type == TYPE_APPLICATION_STARTING && imFocus.mAppToken != null) {
2279 // The client has definitely started, so it really should have a window in this app
2280 // token. Let's look for it.
2281 final WindowState w = imFocus.mAppToken.getFirstNonStartingWindow();
2282 if (w != null) {
2283 if (DEBUG_INPUT_METHOD) Slog.i(TAG_WM, "Switching to real app window: " + w);
2284 imFocus = w;
2285 }
2286 }
2287
2288 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2289
2290 if (DEBUG_INPUT_METHOD) {
2291 Slog.i(TAG_WM, "IM target client: " + imeClient);
2292 if (imeClient != null) {
2293 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2294 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2295 }
2296 }
2297
2298 return imeClient != null && imeClient.asBinder() == client.asBinder();
2299 }
2300
2301 boolean hasSecureWindowOnScreen() {
2302 for (int i = mWindows.size() - 1; i >= 0; --i) {
2303 final WindowState ws = mWindows.get(i);
2304 if (ws.isOnScreen() && (ws.mAttrs.flags & FLAG_SECURE) != 0) {
2305 return true;
2306 }
2307 }
2308 return false;
2309 }
2310
2311 void updateSystemUiVisibility(int visibility, int globalDiff) {
2312 for (int i = mWindows.size() - 1; i >= 0; --i) {
2313 final WindowState ws = mWindows.get(i);
2314 try {
2315 int curValue = ws.mSystemUiVisibility;
2316 int diff = (curValue ^ visibility) & globalDiff;
2317 int newValue = (curValue & ~diff) | (visibility & diff);
2318 if (newValue != curValue) {
2319 ws.mSeq++;
2320 ws.mSystemUiVisibility = newValue;
2321 }
2322 if (newValue != curValue || ws.mAttrs.hasSystemUiListeners) {
2323 ws.mClient.dispatchSystemUiVisibilityChanged(ws.mSeq,
2324 visibility, newValue, diff);
2325 }
2326 } catch (RemoteException e) {
2327 // so sorry
2328 }
2329 }
2330 }
2331
2332 void onWindowFreezeTimeout() {
2333 Slog.w(TAG_WM, "Window freeze timeout expired.");
2334 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
2335 for (int i = mWindows.size() - 1; i >= 0; --i) {
2336 final WindowState w = mWindows.get(i);
2337 if (!w.mOrientationChanging) {
2338 continue;
2339 }
2340 w.mOrientationChanging = false;
2341 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2342 - mService.mDisplayFreezeTime);
2343 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
2344 }
2345 mService.mWindowPlacerLocked.performSurfacePlacement();
2346 }
2347
2348 void waitForAllWindowsDrawn() {
2349 final WindowManagerPolicy policy = mService.mPolicy;
2350 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
2351 final WindowState win = mWindows.get(winNdx);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002352 final boolean keyguard = policy.isKeyguardHostWindow(win.mAttrs);
Jorim Jaggife762342016-10-13 14:33:27 +02002353 if (win.isVisibleLw() && (win.mAppToken != null || keyguard)) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002354 win.mWinAnimator.mDrawState = DRAW_PENDING;
2355 // Force add to mResizingWindows.
2356 win.mLastContentInsets.set(-1, -1, -1, -1);
2357 mService.mWaitingForDrawn.add(win);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002358 }
2359 }
2360 }
2361
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002362 ReadOnlyWindowList getReadOnlyWindowList() {
2363 return mWindows.getReadOnly();
2364 }
2365
2366 void getWindows(WindowList output) {
2367 output.addAll(mWindows);
2368 }
2369
2370 // TODO: Super crazy long method that should be broken down...
2371 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2372
2373 boolean focusDisplayed = false;
2374 boolean displayHasContent = false;
2375 float preferredRefreshRate = 0;
2376 int preferredModeId = 0;
2377
2378
2379 final int dw = mDisplayInfo.logicalWidth;
2380 final int dh = mDisplayInfo.logicalHeight;
2381 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2382
2383 mTmpUpdateAllDrawn.clear();
2384
2385 int repeats = 0;
2386 do {
2387 repeats++;
2388 if (repeats > 6) {
2389 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2390 clearLayoutNeeded();
2391 break;
2392 }
2393
2394 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2395 pendingLayoutChanges);
2396
2397 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
2398 adjustWallpaperWindows();
2399 }
2400
2401 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2402 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2403 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2404 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002405 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002406 }
2407 }
2408
2409 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2410 setLayoutNeeded();
2411 }
2412
2413 // FIRST LOOP: Perform a layout, if needed.
2414 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2415 performLayout(repeats == 1, false /* updateInputWindows */);
2416 } else {
2417 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2418 }
2419
2420 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2421 pendingLayoutChanges = 0;
2422
2423 if (isDefaultDisplay) {
2424 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
2425 for (int i = mWindows.size() - 1; i >= 0; i--) {
2426 final WindowState w = mWindows.get(i);
Jorim Jaggife762342016-10-13 14:33:27 +02002427 mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
2428 mService.mInputMethodTarget);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002429 }
2430 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2431 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2432 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2433 }
2434 } while (pendingLayoutChanges != 0);
2435
2436 RootWindowContainer root = mService.mRoot;
2437 boolean obscured = false;
2438 boolean syswin = false;
2439 resetDimming();
2440
2441 // Only used if default window
2442 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
2443
2444 for (int i = mWindows.size() - 1; i >= 0; i--) {
2445 final WindowState w = mWindows.get(i);
2446 final Task task = w.getTask();
2447 final boolean obscuredChanged = w.mObscured != obscured;
2448
2449 // Update effect.
2450 w.mObscured = obscured;
2451 if (!obscured) {
2452 final boolean isDisplayed = w.isDisplayedLw();
2453
2454 if (isDisplayed && w.isObscuringFullscreen(mDisplayInfo)) {
2455 // This window completely covers everything behind it, so we want to leave all
2456 // of them as undimmed (for performance reasons).
2457 root.mObscuringWindow = w;
2458 obscured = true;
2459 }
2460
2461 displayHasContent |= root.handleNotObscuredLocked(w, obscured, syswin);
2462
2463 if (w.mHasSurface && isDisplayed) {
2464 final int type = w.mAttrs.type;
2465 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
2466 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
2467 syswin = true;
2468 }
2469 if (preferredRefreshRate == 0 && w.mAttrs.preferredRefreshRate != 0) {
2470 preferredRefreshRate = w.mAttrs.preferredRefreshRate;
2471 }
2472 if (preferredModeId == 0 && w.mAttrs.preferredDisplayModeId != 0) {
2473 preferredModeId = w.mAttrs.preferredDisplayModeId;
2474 }
2475 }
2476 }
2477
2478 w.applyDimLayerIfNeeded();
2479
2480 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
2481 && mWallpaperController.isWallpaperTarget(w)) {
2482 // This is the wallpaper target and its obscured state changed... make sure the
2483 // current wallpaper's visibility has been updated accordingly.
2484 mWallpaperController.updateWallpaperVisibility();
2485 }
2486
2487 w.handleWindowMovedIfNeeded();
2488
2489 final WindowStateAnimator winAnimator = w.mWinAnimator;
2490
2491 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
2492 w.mContentChanged = false;
2493
2494 // Moved from updateWindowsAndWallpaperLocked().
2495 if (w.mHasSurface) {
2496 // Take care of the window being ready to display.
2497 final boolean committed = winAnimator.commitFinishDrawingLocked();
2498 if (isDefaultDisplay && committed) {
2499 if (w.mAttrs.type == TYPE_DREAM) {
2500 // HACK: When a dream is shown, it may at that point hide the lock screen.
2501 // So we need to redo the layout to let the phone window manager make this
2502 // happen.
2503 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
2504 if (DEBUG_LAYOUT_REPEATS) {
2505 surfacePlacer.debugLayoutRepeats(
2506 "dream and commitFinishDrawingLocked true",
2507 pendingLayoutChanges);
2508 }
2509 }
2510 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
2511 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
2512 "First draw done in potential wallpaper target " + w);
2513 root.mWallpaperMayChange = true;
2514 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
2515 if (DEBUG_LAYOUT_REPEATS) {
2516 surfacePlacer.debugLayoutRepeats(
2517 "wallpaper and commitFinishDrawingLocked true",
2518 pendingLayoutChanges);
2519 }
2520 }
2521 }
2522 if (!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening()) {
2523 // Updates the shown frame before we set up the surface. This is needed
2524 // because the resizing could change the top-left position (in addition to
2525 // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to
2526 // position the surface.
2527 //
2528 // If an animation is being started, we can't call this method because the
2529 // animation hasn't processed its initial transformation yet, but in general
2530 // we do want to update the position if the window is animating.
2531 winAnimator.computeShownFrameLocked();
2532 }
2533 winAnimator.setSurfaceBoundariesLocked(recoveringMemory);
2534 }
2535
2536 final AppWindowToken atoken = w.mAppToken;
2537 if (atoken != null) {
2538 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
2539 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
2540 mTmpUpdateAllDrawn.add(atoken);
2541 }
2542 }
2543
2544 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
2545 && w.isDisplayedLw()) {
2546 focusDisplayed = true;
2547 }
2548
2549 w.updateResizingWindowIfNeeded();
2550 }
2551
2552 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
2553 displayHasContent,
2554 preferredRefreshRate,
2555 preferredModeId,
2556 true /* inTraversal, must call performTraversalInTrans... below */);
2557
2558 stopDimmingIfNeeded();
2559
2560 while (!mTmpUpdateAllDrawn.isEmpty()) {
2561 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2562 // See if any windows have been drawn, so they (and others associated with them)
2563 // can now be shown.
2564 atoken.updateAllDrawn(this);
2565 }
2566
2567 return focusDisplayed;
2568 }
2569
2570 void performLayout(boolean initial, boolean updateInputWindows) {
2571 if (!isLayoutNeeded()) {
2572 return;
2573 }
2574 clearLayoutNeeded();
2575
2576 final int dw = mDisplayInfo.logicalWidth;
2577 final int dh = mDisplayInfo.logicalHeight;
2578
2579 int i;
2580
2581 if (DEBUG_LAYOUT) {
2582 Slog.v(TAG, "-------------------------------------");
2583 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2584 }
2585
2586 mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mService.mRotation,
2587 getConfiguration().uiMode);
2588 if (isDefaultDisplay) {
2589 // Not needed on non-default displays.
2590 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2591 mService.mScreenRect.set(0, 0, dw, dh);
2592 }
2593
2594 mService.mPolicy.getContentRectLw(mContentRect);
2595
2596 int seq = mService.mLayoutSeq + 1;
2597 if (seq < 0) seq = 0;
2598 mService.mLayoutSeq = seq;
2599
2600 boolean behindDream = false;
2601
2602 // First perform layout of any root windows (not attached to another window).
2603 int topAttached = -1;
2604 for (i = mWindows.size() - 1; i >= 0; i--) {
2605 final WindowState win = mWindows.get(i);
2606
2607 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
2608 // wasting time and funky changes while a window is animating away.
Jorim Jaggife762342016-10-13 14:33:27 +02002609 final boolean gone = (behindDream && mService.mPolicy.canBeHiddenByKeyguardLw(win))
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002610 || win.isGoneForLayoutLw();
2611
2612 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
2613 Slog.v(TAG, "1ST PASS " + win + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
2614 + " mLayoutAttached=" + win.mLayoutAttached
2615 + " screen changed=" + win.isConfigChanged());
2616 final AppWindowToken atoken = win.mAppToken;
2617 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + win.mViewVisibility
2618 + " mRelayoutCalled=" + win.mRelayoutCalled + " hidden=" + win.mToken.hidden
2619 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
2620 + " parentHidden=" + win.isParentWindowHidden());
2621 else Slog.v(TAG, " VIS: mViewVisibility=" + win.mViewVisibility
2622 + " mRelayoutCalled=" + win.mRelayoutCalled + " hidden=" + win.mToken.hidden
2623 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
2624 + " parentHidden=" + win.isParentWindowHidden());
2625 }
2626
2627 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
2628 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
2629 // since that means "perform layout as normal, just don't display").
2630 if (!gone || !win.mHaveFrame || win.mLayoutNeeded
2631 || ((win.isConfigChanged() || win.setReportResizeHints())
2632 && !win.isGoneForLayoutLw() &&
2633 ((win.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
2634 (win.mHasSurface && win.mAppToken != null &&
2635 win.mAppToken.layoutConfigChanges)))) {
2636 if (!win.mLayoutAttached) {
2637 if (initial) {
2638 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
2639 win.mContentChanged = false;
2640 }
2641 if (win.mAttrs.type == TYPE_DREAM) {
2642 // Don't layout windows behind a dream, so that if it does stuff like hide
2643 // the status bar we won't get a bad transition when it goes away.
2644 behindDream = true;
2645 }
2646 win.mLayoutNeeded = false;
2647 win.prelayout();
2648 mService.mPolicy.layoutWindowLw(win, null);
2649 win.mLayoutSeq = seq;
2650
2651 // Window frames may have changed. Update dim layer with the new bounds.
2652 final Task task = win.getTask();
2653 if (task != null) {
2654 mDimLayerController.updateDimLayer(task);
2655 }
2656
2657 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + win.mFrame
2658 + " mContainingFrame=" + win.mContainingFrame
2659 + " mDisplayFrame=" + win.mDisplayFrame);
2660 } else {
2661 if (topAttached < 0) topAttached = i;
2662 }
2663 }
2664 }
2665
2666 boolean attachedBehindDream = false;
2667
2668 // Now perform layout of attached windows, which usually depend on the position of the
2669 // window they are attached to. XXX does not deal with windows that are attached to windows
2670 // that are themselves attached.
2671 for (i = topAttached; i >= 0; i--) {
2672 final WindowState win = mWindows.get(i);
2673
2674 if (win.mLayoutAttached) {
2675 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + win + " mHaveFrame=" + win.mHaveFrame
2676 + " mViewVisibility=" + win.mViewVisibility
2677 + " mRelayoutCalled=" + win.mRelayoutCalled);
2678 // If this view is GONE, then skip it -- keep the current frame, and let the caller
2679 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
2680 // windows, since that means "perform layout as normal, just don't display").
Jorim Jaggife762342016-10-13 14:33:27 +02002681 if (attachedBehindDream && mService.mPolicy.canBeHiddenByKeyguardLw(win)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002682 continue;
2683 }
2684 if ((win.mViewVisibility != GONE && win.mRelayoutCalled) || !win.mHaveFrame
2685 || win.mLayoutNeeded) {
2686 if (initial) {
2687 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
2688 win.mContentChanged = false;
2689 }
2690 win.mLayoutNeeded = false;
2691 win.prelayout();
2692 mService.mPolicy.layoutWindowLw(win, win.getParentWindow());
2693 win.mLayoutSeq = seq;
2694 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + win.mFrame
2695 + " mContainingFrame=" + win.mContainingFrame
2696 + " mDisplayFrame=" + win.mDisplayFrame);
2697 }
2698 } else if (win.mAttrs.type == TYPE_DREAM) {
2699 // Don't layout windows behind a dream, so that if it does stuff like hide the
2700 // status bar we won't get a bad transition when it goes away.
2701 attachedBehindDream = behindDream;
2702 }
2703 }
2704
2705 // Window frames may have changed. Tell the input dispatcher about it.
2706 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2707 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2708 if (updateInputWindows) {
2709 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2710 }
2711
2712 mService.mPolicy.finishLayoutLw();
2713 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2714 }
2715
2716 /**
2717 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2718 * In portrait mode, it grabs the full screenshot.
2719 *
2720 * @param width the width of the target bitmap
2721 * @param height the height of the target bitmap
2722 * @param includeFullDisplay true if the screen should not be cropped before capture
2723 * @param frameScale the scale to apply to the frame, only used when width = -1 and height = -1
2724 * @param config of the output bitmap
2725 * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
2726 */
2727 Bitmap screenshotApplications(IBinder appToken, int displayId, int width, int height,
2728 boolean includeFullDisplay, float frameScale, Bitmap.Config config,
2729 boolean wallpaperOnly) {
2730 int dw = mDisplayInfo.logicalWidth;
2731 int dh = mDisplayInfo.logicalHeight;
2732 if (dw == 0 || dh == 0) {
2733 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
2734 + ": returning null. logical widthxheight=" + dw + "x" + dh);
2735 return null;
2736 }
2737
2738 Bitmap bm = null;
2739
2740 int maxLayer = 0;
2741 final Rect frame = new Rect();
2742 final Rect stackBounds = new Rect();
2743
2744 boolean screenshotReady;
2745 int minLayer;
2746 if (appToken == null && !wallpaperOnly) {
2747 screenshotReady = true;
2748 minLayer = 0;
2749 } else {
2750 screenshotReady = false;
2751 minLayer = Integer.MAX_VALUE;
2752 }
2753
2754 WindowState appWin = null;
2755
2756 boolean includeImeInScreenshot;
2757 synchronized(mService.mWindowMap) {
2758 final AppWindowToken imeTargetAppToken = mService.mInputMethodTarget != null
2759 ? mService.mInputMethodTarget.mAppToken : null;
2760 // We only include the Ime in the screenshot if the app we are screenshoting is the IME
2761 // target and isn't in multi-window mode. We don't screenshot the IME in multi-window
2762 // mode because the frame of the IME might not overlap with that of the app.
2763 // E.g. IME target app at the top in split-screen mode and the IME at the bottom
2764 // overlapping with the bottom app.
2765 includeImeInScreenshot = imeTargetAppToken != null
2766 && imeTargetAppToken.appToken != null
2767 && imeTargetAppToken.appToken.asBinder() == appToken
2768 && !mService.mInputMethodTarget.isInMultiWindowMode();
2769 }
2770
2771 final int aboveAppLayer = (mService.mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) + 1)
2772 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
2773
2774 synchronized(mService.mWindowMap) {
2775 // Figure out the part of the screen that is actually the app.
2776 appWin = null;
2777 for (int i = mWindows.size() - 1; i >= 0; i--) {
2778 final WindowState ws = mWindows.get(i);
2779 if (!ws.mHasSurface) {
2780 continue;
2781 }
2782 if (ws.mLayer >= aboveAppLayer) {
2783 continue;
2784 }
2785 if (wallpaperOnly && !ws.mIsWallpaper) {
2786 continue;
2787 }
2788 if (ws.mIsImWindow) {
2789 if (!includeImeInScreenshot) {
2790 continue;
2791 }
2792 } else if (ws.mIsWallpaper) {
2793 // If this is the wallpaper layer and we're only looking for the wallpaper layer
2794 // then the target window state is this one.
2795 if (wallpaperOnly) {
2796 appWin = ws;
2797 }
2798
2799 if (appWin == null) {
2800 // We have not ran across the target window yet, so it is probably behind
2801 // the wallpaper. This can happen when the keyguard is up and all windows
2802 // are moved behind the wallpaper. We don't want to include the wallpaper
2803 // layer in the screenshot as it will cover-up the layer of the target
2804 // window.
2805 continue;
2806 }
2807 // Fall through. The target window is in front of the wallpaper. For this
2808 // case we want to include the wallpaper layer in the screenshot because
2809 // the target window might have some transparent areas.
2810 } else if (appToken != null) {
2811 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
2812 // This app window is of no interest if it is not associated with the
2813 // screenshot app.
2814 continue;
2815 }
2816 appWin = ws;
2817 }
2818
2819 // Include this window.
2820
2821 final WindowStateAnimator winAnim = ws.mWinAnimator;
2822 int layer = winAnim.mSurfaceController.getLayer();
2823 if (maxLayer < layer) {
2824 maxLayer = layer;
2825 }
2826 if (minLayer > layer) {
2827 minLayer = layer;
2828 }
2829
2830 // Don't include wallpaper in bounds calculation
2831 if (!includeFullDisplay && !ws.mIsWallpaper) {
2832 final Rect wf = ws.mFrame;
2833 final Rect cr = ws.mContentInsets;
2834 int left = wf.left + cr.left;
2835 int top = wf.top + cr.top;
2836 int right = wf.right - cr.right;
2837 int bottom = wf.bottom - cr.bottom;
2838 frame.union(left, top, right, bottom);
2839 ws.getVisibleBounds(stackBounds);
2840 if (!Rect.intersects(frame, stackBounds)) {
2841 // Set frame empty if there's no intersection.
2842 frame.setEmpty();
2843 }
2844 }
2845
2846 final boolean foundTargetWs =
2847 (ws.mAppToken != null && ws.mAppToken.token == appToken)
2848 || (appWin != null && wallpaperOnly);
2849 if (foundTargetWs && ws.isDisplayedLw() && winAnim.getShown()) {
2850 screenshotReady = true;
2851 }
2852
2853 if (ws.isObscuringFullscreen(mDisplayInfo)){
2854 break;
2855 }
2856 }
2857
2858 if (appToken != null && appWin == null) {
2859 // Can't find a window to snapshot.
2860 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM,
2861 "Screenshot: Couldn't find a surface matching " + appToken);
2862 return null;
2863 }
2864
2865 if (!screenshotReady) {
2866 Slog.i(TAG_WM, "Failed to capture screenshot of " + appToken +
2867 " appWin=" + (appWin == null ? "null" : (appWin + " drawState=" +
2868 appWin.mWinAnimator.mDrawState)));
2869 return null;
2870 }
2871
2872 // Screenshot is ready to be taken. Everything from here below will continue
2873 // through the bottom of the loop and return a value. We only stay in the loop
2874 // because we don't want to release the mWindowMap lock until the screenshot is
2875 // taken.
2876
2877 if (maxLayer == 0) {
2878 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
2879 + ": returning null maxLayer=" + maxLayer);
2880 return null;
2881 }
2882
2883 if (!includeFullDisplay) {
2884 // Constrain frame to the screen size.
2885 if (!frame.intersect(0, 0, dw, dh)) {
2886 frame.setEmpty();
2887 }
2888 } else {
2889 // Caller just wants entire display.
2890 frame.set(0, 0, dw, dh);
2891 }
2892 if (frame.isEmpty()) {
2893 return null;
2894 }
2895
2896 if (width < 0) {
2897 width = (int) (frame.width() * frameScale);
2898 }
2899 if (height < 0) {
2900 height = (int) (frame.height() * frameScale);
2901 }
2902
2903 // Tell surface flinger what part of the image to crop. Take the top
2904 // right part of the application, and crop the larger dimension to fit.
2905 Rect crop = new Rect(frame);
2906 if (width / (float) frame.width() < height / (float) frame.height()) {
2907 int cropWidth = (int)((float)width / (float)height * frame.height());
2908 crop.right = crop.left + cropWidth;
2909 } else {
2910 int cropHeight = (int)((float)height / (float)width * frame.width());
2911 crop.bottom = crop.top + cropHeight;
2912 }
2913
2914 // The screenshot API does not apply the current screen rotation.
2915 int rot = mDisplay.getRotation();
2916
2917 if (rot == ROTATION_90 || rot == ROTATION_270) {
2918 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
2919 }
2920
2921 // Surfaceflinger is not aware of orientation, so convert our logical
2922 // crop to surfaceflinger's portrait orientation.
2923 convertCropForSurfaceFlinger(crop, rot, dw, dh);
2924
2925 if (DEBUG_SCREENSHOT) {
2926 Slog.i(TAG_WM, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to "
2927 + maxLayer + " appToken=" + appToken);
2928 for (int i = 0; i < mWindows.size(); i++) {
2929 final WindowState win = mWindows.get(i);
2930 final WindowSurfaceController controller = win.mWinAnimator.mSurfaceController;
2931 Slog.i(TAG_WM, win + ": " + win.mLayer
2932 + " animLayer=" + win.mWinAnimator.mAnimLayer
2933 + " surfaceLayer=" + ((controller == null)
2934 ? "null" : controller.getLayer()));
2935 }
2936 }
2937
2938 final ScreenRotationAnimation screenRotationAnimation =
2939 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
2940 final boolean inRotation = screenRotationAnimation != null &&
2941 screenRotationAnimation.isAnimating();
2942 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM,
2943 "Taking screenshot while rotating");
2944
2945 // We force pending transactions to flush before taking
2946 // the screenshot by pushing an empty synchronous transaction.
2947 SurfaceControl.openTransaction();
2948 SurfaceControl.closeTransactionSync();
2949
2950 bm = SurfaceControl.screenshot(crop, width, height, minLayer, maxLayer,
2951 inRotation, rot);
2952 if (bm == null) {
2953 Slog.w(TAG_WM, "Screenshot failure taking screenshot for (" + dw + "x" + dh
2954 + ") to layer " + maxLayer);
2955 return null;
2956 }
2957 }
2958
2959 if (DEBUG_SCREENSHOT) {
2960 // TEST IF IT's ALL BLACK
2961 int[] buffer = new int[bm.getWidth() * bm.getHeight()];
2962 bm.getPixels(buffer, 0, bm.getWidth(), 0, 0, bm.getWidth(), bm.getHeight());
2963 boolean allBlack = true;
2964 final int firstColor = buffer[0];
2965 for (int i = 0; i < buffer.length; i++) {
2966 if (buffer[i] != firstColor) {
2967 allBlack = false;
2968 break;
2969 }
2970 }
2971 if (allBlack) {
2972 Slog.i(TAG_WM, "Screenshot " + appWin + " was monochrome(" +
2973 Integer.toHexString(firstColor) + ")! mSurfaceLayer=" +
2974 (appWin != null ?
2975 appWin.mWinAnimator.mSurfaceController.getLayer() : "null") +
2976 " minLayer=" + minLayer + " maxLayer=" + maxLayer);
2977 }
2978 }
2979
2980 // Create a copy of the screenshot that is immutable and backed in ashmem.
2981 // This greatly reduces the overhead of passing the bitmap between processes.
2982 Bitmap ret = bm.createAshmemBitmap(config);
2983 bm.recycle();
2984 return ret;
2985 }
2986
2987 // TODO: Can this use createRotationMatrix()?
2988 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
2989 if (rot == Surface.ROTATION_90) {
2990 final int tmp = crop.top;
2991 crop.top = dw - crop.right;
2992 crop.right = crop.bottom;
2993 crop.bottom = dw - crop.left;
2994 crop.left = tmp;
2995 } else if (rot == Surface.ROTATION_180) {
2996 int tmp = crop.top;
2997 crop.top = dh - crop.bottom;
2998 crop.bottom = dh - tmp;
2999 tmp = crop.right;
3000 crop.right = dw - crop.left;
3001 crop.left = dw - tmp;
3002 } else if (rot == Surface.ROTATION_270) {
3003 final int tmp = crop.top;
3004 crop.top = crop.left;
3005 crop.left = dh - crop.bottom;
3006 crop.bottom = crop.right;
3007 crop.right = dh - tmp;
3008 }
3009 }
3010
3011 void onSeamlessRotationTimeout() {
3012 boolean layoutNeeded = false;
3013 for (int i = mWindows.size() - 1; i >= 0; i--) {
3014 final WindowState w = mWindows.get(i);
3015 if (!w.mSeamlesslyRotated) {
3016 continue;
3017 }
3018 layoutNeeded = true;
3019 w.setDisplayLayoutNeeded();
3020 mService.markForSeamlessRotation(w, false);
3021 }
3022
3023 if (layoutNeeded) {
3024 mService.mWindowPlacerLocked.performSurfacePlacement();
3025 }
3026 }
3027
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003028 static final class GetWindowOnDisplaySearchResult {
Wale Ogunwaleec731152016-09-08 20:18:57 -07003029 boolean reachedToken;
3030 WindowState foundWindow;
3031
3032 void reset() {
3033 reachedToken = false;
3034 foundWindow = null;
3035 }
3036 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003037
3038 static final class TaskForResizePointSearchResult {
3039 boolean searchDone;
3040 Task taskForResize;
3041
3042 void reset() {
3043 searchDone = false;
3044 taskForResize = null;
3045 }
3046 }
Robert Carr3b716242016-08-16 16:02:21 -07003047
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003048 /**
3049 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3050 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3051 * homogeneous children type which is currently required by sub-classes of
3052 * {@link WindowContainer} class.
3053 */
3054 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3055
3056 int size() {
3057 return mChildren.size();
3058 }
3059
3060 E get(int index) {
3061 return mChildren.get(index);
3062 }
3063
3064 @Override
3065 boolean fillsParent() {
3066 return true;
3067 }
3068
3069 @Override
3070 boolean isVisible() {
3071 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003072 }
3073 }
3074
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003075 /**
3076 * Window container class that contains all containers on this display relating to Apps.
3077 * I.e Activities.
3078 */
3079 private class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
3080
3081 void attachStack(TaskStack stack, boolean onTop) {
3082 if (stack.mStackId == HOME_STACK_ID) {
3083 if (mHomeStack != null) {
3084 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
3085 }
3086 mHomeStack = stack;
3087 }
3088 addChild(stack, onTop);
3089 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003090 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003091
3092 void moveStack(TaskStack stack, boolean toTop) {
3093 if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
3094 // This stack is always-on-top silly...
3095 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
3096 return;
3097 }
3098
3099 if (!mChildren.contains(stack)) {
3100 Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
3101 }
3102 removeChild(stack);
3103 addChild(stack, toTop);
3104 }
3105
3106 private void addChild(TaskStack stack, boolean toTop) {
3107 int addIndex = toTop ? mChildren.size() : 0;
3108
3109 if (toTop
3110 && mService.isStackVisibleLocked(PINNED_STACK_ID)
3111 && stack.mStackId != PINNED_STACK_ID) {
3112 // The pinned stack is always the top most stack (always-on-top) when it is visible.
3113 // So, stack is moved just below the pinned stack.
3114 addIndex--;
3115 TaskStack topStack = mChildren.get(addIndex);
3116 if (topStack.mStackId != PINNED_STACK_ID) {
3117 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3118 }
3119 }
3120 addChild(stack, addIndex);
3121 setLayoutNeeded();
3122 }
3123
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003124 @Override
3125 int getOrientation() {
3126 if (mService.isStackVisibleLocked(DOCKED_STACK_ID)
3127 || mService.isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID)) {
3128 // Apps and their containers are not allowed to specify an orientation while the
3129 // docked or freeform stack is visible...except for the home stack/task if the
3130 // docked stack is minimized and it actually set something.
3131 if (mHomeStack != null && mHomeStack.isVisible()
3132 && mDividerControllerLocked.isMinimizedDock()) {
3133 final int orientation = mHomeStack.getOrientation();
3134 if (orientation != SCREEN_ORIENTATION_UNSET) {
3135 return orientation;
3136 }
3137 }
3138 return SCREEN_ORIENTATION_UNSPECIFIED;
3139 }
3140
3141 final int orientation = super.getOrientation();
3142 if (orientation != SCREEN_ORIENTATION_UNSET
3143 && orientation != SCREEN_ORIENTATION_BEHIND) {
3144 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3145 "App is requesting an orientation, return " + orientation);
3146 return orientation;
3147 }
3148
3149 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3150 "No app is requesting an orientation, return " + mService.mLastOrientation);
3151 // The next app has not been requested to be visible, so we keep the current orientation
3152 // to prevent freezing/unfreezing the display too early.
3153 return mService.mLastOrientation;
3154 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003155 }
3156
3157 /**
3158 * Window container class that contains all containers on this display that are not related to
3159 * Apps. E.g. status bar.
3160 */
3161 private static class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
3162
Robert Carr3b716242016-08-16 16:02:21 -07003163 }
Craig Mautner59c00972012-07-30 12:10:24 -07003164}