blob: 1960285be76fc00ee9630485fbb83251ab70e069 [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;
Jorim Jaggife762342016-10-13 14:33:27 +020065
Wale Ogunwaleec731152016-09-08 20:18:57 -070066import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070067import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070069import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
70import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070071import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwalec69694a2016-10-18 13:51:15 -070072import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070073import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070074import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020075import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070076import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070077import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Jorim Jaggife762342016-10-13 14:33:27 +020078import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070079import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070080import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleec731152016-09-08 20:18:57 -070081import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070082import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070083import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070084import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080085import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070086import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
87import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -070088import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070089import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
90import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
91import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
92import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale494009b82016-10-21 09:01:38 -070093import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070094import static com.android.server.wm.WindowManagerService.dipToPixel;
95import static com.android.server.wm.WindowManagerService.localLOGV;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070096import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070097import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -070098import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070099import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700100import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700101
Andrii Kulian3a507b52016-09-19 18:14:12 -0700102import android.annotation.NonNull;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700103import android.app.ActivityManager.StackId;
Andrii Kulian441e4492016-09-29 15:25:00 -0700104import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700105import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700106import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800107import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700108import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700109import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100110import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700111import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700112import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700113import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700114import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700115import android.os.RemoteException;
116import android.os.SystemClock;
Chong Zhang8e89b312015-09-09 15:09:30 -0700117import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700118import android.util.Slog;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700119import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -0700120import android.view.DisplayInfo;
Wale Ogunwaleec731152016-09-08 20:18:57 -0700121import android.view.IWindow;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700122import android.view.InputChannel;
123import android.view.Surface;
124import android.view.SurfaceControl;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700125import android.view.WindowManagerPolicy;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700126
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700127import com.android.internal.util.FastPrintWriter;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700128import com.android.internal.view.IInputMethodClient;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700129import com.android.server.input.InputWindowHandle;
Craig Mautner59c00972012-07-30 12:10:24 -0700130
Robert Carr3b716242016-08-16 16:02:21 -0700131import java.io.FileDescriptor;
Craig Mautner59c00972012-07-30 12:10:24 -0700132import java.io.PrintWriter;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700133import java.io.StringWriter;
Craig Mautner59c00972012-07-30 12:10:24 -0700134import java.util.ArrayList;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700135import java.util.Arrays;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700136import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700137import java.util.HashMap;
138import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700139import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700140import java.util.List;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700141import java.util.function.BiConsumer;
142import java.util.function.Consumer;
143import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700144
Craig Mautner59c00972012-07-30 12:10:24 -0700145/**
146 * Utility class for keeping track of the WindowStates and other pertinent contents of a
147 * particular Display.
148 *
149 * IMPORTANT: No method from this class should ever be used without holding
150 * WindowManagerService.mWindowMap.
151 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700152class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700153 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700154
155 /** Unique identifier of this stack. */
156 private final int mDisplayId;
157
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700158 // The display only has 2 child window containers. mTaskStackContainers which contains all
159 // window containers that are related to apps (Activities) and mNonAppWindowContainers which
160 // contains all window containers not related to apps (e.g. Status bar).
161 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers();
162 private final NonAppWindowContainers mNonAppWindowContainers = new NonAppWindowContainers();
163
Craig Mautner59c00972012-07-30 12:10:24 -0700164 /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element
165 * from mDisplayWindows; */
Craig Mautnerdc548482014-02-05 13:35:24 -0800166 private final WindowList mWindows = new WindowList();
Craig Mautner59c00972012-07-30 12:10:24 -0700167
Wale Ogunwale02319a62016-09-26 15:21:22 -0700168 // Mapping from a token IBinder to a WindowToken object on this display.
169 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
170
Craig Mautner59c00972012-07-30 12:10:24 -0700171 int mInitialDisplayWidth = 0;
172 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700173 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -0700174 int mBaseDisplayWidth = 0;
175 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700176 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700177 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700178 private final DisplayInfo mDisplayInfo = new DisplayInfo();
179 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700180 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -0700181
Craig Mautner6601b7b2013-04-29 10:29:11 -0700182 Rect mBaseDisplayRect = new Rect();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700183 private Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700184
Craig Mautner39834192012-09-02 07:47:24 -0700185 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700186 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700187 int pendingLayoutChanges;
Craig Mautner69b08182012-09-05 13:07:13 -0700188 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700189
Craig Mautnerdc548482014-02-05 13:35:24 -0800190 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700191 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800192
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800193 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
194 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -0700195 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700196
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700197 /** Detect user tapping outside of current focused task bounds .*/
198 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700199
Craig Mautner6601b7b2013-04-29 10:29:11 -0700200 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700201 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700202
Craig Mautner6601b7b2013-04-29 10:29:11 -0700203 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800204 private final Rect mTmpRect = new Rect();
205 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700206 private final RectF mTmpRectF = new RectF();
207 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800208 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700209
Craig Mautner9d808b12013-08-06 18:00:25 -0700210 final WindowManagerService mService;
211
Craig Mautner95da1082014-02-24 17:54:35 -0800212 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700213 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800214
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700215 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700216 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700217
Chong Zhang112eb8c2015-11-02 11:17:00 -0800218 final DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700219
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800220 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
221
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700222 /** Used when rebuilding window list to keep track of windows that have been removed. */
223 private WindowState[] mRebuildTmp = new WindowState[20];
224
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700225 /**
226 * Temporary list for comparison. Always clear this after use so we don't end up with
227 * orphaned windows references
228 */
229 private final ArrayList<WindowState> mTmpWindows = new ArrayList<>();
230
231 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
232
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700233 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
234 new TaskForResizePointSearchResult();
235 private final GetWindowOnDisplaySearchResult mTmpGetWindowOnDisplaySearchResult =
236 new GetWindowOnDisplaySearchResult();
237
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700238 // True if this display is in the process of being removed. Used to determine if the removal of
239 // the display's direct children should be allowed.
240 private boolean mRemovingDisplay = false;
241
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700242 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700243 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700244 int mInputMethodAnimLayerAdjustment;
245
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800246 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700247 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800248 * @param service You know.
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700249 * @param layersController window layer controller used to assign layer to the windows on this
250 * display.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700251 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
252 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700253 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700254 DisplayContent(Display display, WindowManagerService service,
Wale Ogunwale0303c572016-10-20 10:16:29 -0700255 WindowLayersController layersController, WallpaperController wallpaperController) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700256 mDisplay = display;
257 mDisplayId = display.getDisplayId();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700258 mLayersController = layersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700259 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700260 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700261 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700262 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700263 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700264 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800265 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700266 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800267 mDimLayerController = new DimLayerController(this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700268
269 // These are the only direct children we should ever have and they are permanent.
270 super.addChild(mTaskStackContainers, null);
271 super.addChild(mNonAppWindowContainers, null);
Craig Mautner59c00972012-07-30 12:10:24 -0700272 }
273
274 int getDisplayId() {
275 return mDisplayId;
276 }
277
Wale Ogunwale02319a62016-09-26 15:21:22 -0700278 WindowToken getWindowToken(IBinder binder) {
279 return mTokenMap.get(binder);
280 }
281
282 AppWindowToken getAppWindowToken(IBinder binder) {
283 final WindowToken token = getWindowToken(binder);
284 if (token == null) {
285 return null;
286 }
287 return token.asAppWindowToken();
288 }
289
290 void setWindowToken(IBinder binder, WindowToken token) {
291 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
292 if (dc != null) {
293 // We currently don't support adding a window token to the display if the display
294 // already has the binder mapped to another token. If there is a use case for supporting
295 // this moving forward we will either need to merge the WindowTokens some how or have
296 // the binder map to a list of window tokens.
297 throw new IllegalArgumentException("Can't map token=" + token + " to display=" + this
298 + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
299 }
300 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700301
302 if (token.asAppWindowToken() == null) {
303 // Add non-app token to container hierarchy on the display. App tokens are added through
304 // the parent container managing them (e.g. Tasks).
305 mNonAppWindowContainers.addChild(token, null);
306 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700307 }
308
309 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700310 final WindowToken token = mTokenMap.remove(binder);
311 if (token != null && token.asAppWindowToken() == null) {
312 mNonAppWindowContainers.removeChild(token);
313 }
314 return token;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700315 }
316
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700317 Display getDisplay() {
318 return mDisplay;
319 }
320
Craig Mautner59c00972012-07-30 12:10:24 -0700321 DisplayInfo getDisplayInfo() {
322 return mDisplayInfo;
323 }
324
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700325 DisplayMetrics getDisplayMetrics() {
326 return mDisplayMetrics;
327 }
328
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100329 DockedStackDividerController getDockedDividerController() {
330 return mDividerControllerLocked;
331 }
332
Winson Chung655332c2016-10-31 13:14:28 -0700333 PinnedStackController getPinnedStackController() {
334 return mPinnedStackControllerLocked;
335 }
336
Jeff Browna506a6e2013-06-04 00:02:38 -0700337 /**
338 * Returns true if the specified UID has access to this display.
339 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700340 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700341 return mDisplay.hasAccess(uid);
342 }
343
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700344 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700345 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -0700346 }
347
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700348 TaskStack getHomeStack() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700349 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800350 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
Craig Mautnere0a38842013-12-16 16:14:02 -0800351 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700352 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700353 }
354
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700355 TaskStack getStackById(int stackId) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700356 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
357 final TaskStack stack = mTaskStackContainers.get(i);
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700358 if (stack.mStackId == stackId) {
359 return stack;
360 }
361 }
362 return null;
363 }
364
Andrii Kulian441e4492016-09-29 15:25:00 -0700365 @Override
366 void onConfigurationChanged(Configuration newParentConfig) {
367 super.onConfigurationChanged(newParentConfig);
368
Andrii Kulian3a507b52016-09-19 18:14:12 -0700369 // The display size information is heavily dependent on the resources in the current
370 // configuration, so we need to reconfigure it every time the configuration changes.
371 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
372 mService.reconfigureDisplayLocked(this);
373
374 getDockedDividerController().onConfigurationChanged();
Winson Chung655332c2016-10-31 13:14:28 -0700375 getPinnedStackController().onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700376 }
Andrii Kulian3a507b52016-09-19 18:14:12 -0700377
Andrii Kulian441e4492016-09-29 15:25:00 -0700378 /**
379 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
380 * bounds were updated.
381 */
382 void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700383 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
384 final TaskStack stack = mTaskStackContainers.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700385 if (stack.updateBoundsAfterConfigChange()) {
Andrii Kulian3a507b52016-09-19 18:14:12 -0700386 changedStackList.add(stack.mStackId);
387 }
388 }
389 }
390
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700391 @Override
392 boolean fillsParent() {
393 return true;
394 }
395
396 @Override
397 boolean isVisible() {
398 return true;
399 }
400
401 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700402 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700403 super.onAppTransitionDone();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700404 rebuildAppWindowList();
405 }
406
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700407 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -0700408 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700409 final WindowManagerPolicy policy = mService.mPolicy;
410
411 // TODO: All the logic before the last return statement in this method should really go in
412 // #NonAppWindowContainer.getOrientation() since it is trying to decide orientation based
413 // on non-app windows. But, we can not do that until the window list is always correct in
414 // terms of z-ordering based on layers.
415 if (mService.mDisplayFrozen) {
416 if (mService.mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
417 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
418 "Display is frozen, return " + mService.mLastWindowForcedOrientation);
419 // If the display is frozen, some activities may be in the middle of restarting, and
420 // thus have removed their old window. If the window has the flag to hide the lock
421 // screen, then the lock screen can re-appear and inflict its own orientation on us.
422 // Keep the orientation stable until this all settles down.
423 return mService.mLastWindowForcedOrientation;
424 } else if (policy.isKeyguardLocked()) {
425 // Use the last orientation the while the display is frozen with the keyguard
426 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
427 // window. We don't want to check the show when locked window directly though as
428 // things aren't stable while the display is frozen, for example the window could be
429 // momentarily unavailable due to activity relaunch.
430 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
431 + "return " + mService.mLastOrientation);
432 return mService.mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -0700433 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700434 } else {
435 for (int pos = mWindows.size() - 1; pos >= 0; --pos) {
436 final WindowState win = mWindows.get(pos);
437 if (win.mAppToken != null) {
438 // We hit an application window. so the orientation will be determined by the
439 // app window. No point in continuing further.
440 break;
441 }
442 if (!win.isVisibleLw() || !win.mPolicyVisibilityAfterAnim) {
443 continue;
444 }
445 int req = win.mAttrs.screenOrientation;
446 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND) {
447 continue;
448 }
449
450 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
451 if (policy.isKeyguardHostWindow(win.mAttrs)) {
452 mService.mLastKeyguardForcedOrientation = req;
453 }
454 return (mService.mLastWindowForcedOrientation = req);
455 }
456 mService.mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
457
Jorim Jaggife762342016-10-13 14:33:27 +0200458 if (policy.isKeyguardShowingAndNotOccluded()) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700459 return mService.mLastKeyguardForcedOrientation;
460 }
Wale Ogunwale51362492016-09-08 17:49:17 -0700461 }
462
Wale Ogunwalee6f806e2016-10-20 15:29:42 -0700463 // Top system windows are not requesting an orientation. Start searching from apps.
464 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -0700465 }
466
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700467 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700468 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700469 mDisplay.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700470 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
471 mTaskStackContainers.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800472 }
Craig Mautner722285e2012-09-07 13:55:58 -0700473 }
474
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700475 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700476 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
477 if (displayManagerInternal != null) {
478 // Bootstrap the default logical display from the display manager.
479 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
480 if (newDisplayInfo != null) {
481 mDisplayInfo.copyFrom(newDisplayInfo);
482 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700483 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700484
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800485 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
486 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
487 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
488 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700489 }
490
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700491 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700492 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800493 final int orientation = mDisplayInfo.rotation;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700494 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
Craig Mautner4a1cb222013-12-04 16:14:06 -0800495 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
496 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700497 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800498 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700499 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800500 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700501 out.set(left, top, left + width, top + height);
502 }
503
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700504 private void getLogicalDisplayRect(Rect out, int orientation) {
505 getLogicalDisplayRect(out);
506
507 // Rotate the Rect if needed.
508 final int currentRotation = mDisplayInfo.rotation;
509 final int rotationDelta = deltaRotation(currentRotation, orientation);
510 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
511 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
512 mTmpRectF.set(out);
513 mTmpMatrix.mapRect(mTmpRectF);
514 mTmpRectF.round(out);
515 }
516 }
517
Chong Zhangf66db432016-01-13 10:39:51 -0800518 void getContentRect(Rect out) {
519 out.set(mContentRect);
520 }
521
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700522 /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
523 void attachStack(TaskStack stack, boolean onTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700524 mTaskStackContainers.attachStack(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800525 }
526
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800527 void moveStack(TaskStack stack, boolean toTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700528 mTaskStackContainers.moveStack(stack, toTop);
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700529 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700530
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700531 @Override
532 protected void addChild(DisplayChildWindowContainer child,
533 Comparator<DisplayChildWindowContainer> comparator) {
534 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
535 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700536
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700537 @Override
538 protected void addChild(DisplayChildWindowContainer child, int index) {
539 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
540 }
541
542 @Override
543 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700544 // Only allow removal of direct children from this display if the display is in the process
545 // of been removed.
546 if (mRemovingDisplay) {
547 super.removeChild(child);
548 return;
549 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700550 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800551 }
552
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700553 int taskIdFromPoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700554 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
555 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700556 final int taskId = stack.taskIdFromPoint(x, y);
557 if (taskId != -1) {
558 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -0700559 }
560 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800561 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700562 }
563
Chong Zhang8e89b312015-09-09 15:09:30 -0700564 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -0800565 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -0700566 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700567 */
Wale Ogunwale15ead902016-09-02 14:30:11 -0700568 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700569 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700570 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700571 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
572 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -0700573 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700574 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700575 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700576
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700577 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
578 if (mTmpTaskForResizePointSearchResult.searchDone) {
579 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -0700580 }
581 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700582 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700583 }
584
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700585 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700586 mTouchExcludeRegion.set(mBaseDisplayRect);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700587 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700588 mTmpRect2.setEmpty();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700589 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
590 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700591 stack.setTouchExcludeRegion(
592 focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2);
Craig Mautner6601b7b2013-04-29 10:29:11 -0700593 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800594 // If we removed the focused task above, add it back and only leave its
595 // outside touch area in the exclusion. TapDectector is not interested in
596 // any touch inside the focused task itself.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700597 if (!mTmpRect2.isEmpty()) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800598 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
599 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800600 final WindowState inputMethod = mService.mInputMethodWindow;
601 if (inputMethod != null && inputMethod.isVisibleLw()) {
602 // If the input method is visible and the user is typing, we don't want these touch
603 // events to be intercepted and used to change focus. This would likely cause a
604 // disappearance of the input method.
605 inputMethod.getTouchableRegion(mTmpRegion);
606 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
607 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800608 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
609 WindowState win = mTapExcludedWindows.get(i);
610 win.getTouchableRegion(mTmpRegion);
611 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
612 }
Jorim Jaggife762342016-10-13 14:33:27 +0200613 if (getDockedStackLocked() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100614 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -0700615 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100616 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
617 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800618 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700619 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -0800620 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700621 }
622
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700623 void switchUser() {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700624 final int count = mWindows.size();
625 for (int i = 0; i < count; i++) {
626 final WindowState win = mWindows.get(i);
Craig Mautner858d8a62013-04-23 17:08:34 -0700627 if (win.isHiddenFromUserLocked()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800628 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800629 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700630 win.hideLw(false);
631 }
632 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700633
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700634 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
635 mTaskStackContainers.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700636 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700637
638 rebuildAppWindowList();
Craig Mautner858d8a62013-04-23 17:08:34 -0700639 }
640
Craig Mautner05d29032013-05-03 13:40:13 -0700641 void resetAnimationBackgroundAnimator() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700642 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
643 mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700644 }
645 }
646
647 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800648 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700649 }
650
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700651 private void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800652 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700653 }
654
655 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800656 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700657 }
658
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700659 private void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800660 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700661 }
662
Wale Ogunwale10124582016-09-15 20:25:50 -0700663 @Override
664 void removeIfPossible() {
665 if (isAnimating()) {
666 mDeferredRemoval = true;
667 return;
Craig Mautner2eb15342013-08-07 13:13:35 -0700668 }
Wale Ogunwale10124582016-09-15 20:25:50 -0700669 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -0700670 }
671
Wale Ogunwale10124582016-09-15 20:25:50 -0700672 @Override
673 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700674 mRemovingDisplay = true;
675 try {
676 super.removeImmediately();
677 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
678 mDimLayerController.close();
679 if (mDisplayId == DEFAULT_DISPLAY) {
680 mService.unregisterPointerEventListener(mTapDetector);
681 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
682 }
683 } finally {
684 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -0800685 }
Craig Mautner95da1082014-02-24 17:54:35 -0800686 }
687
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700688 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -0700689 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700690 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700691 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
692
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700693 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -0700694 removeImmediately();
Craig Mautner95da1082014-02-24 17:54:35 -0800695 mService.onDisplayRemoved(mDisplayId);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700696 return false;
Craig Mautner95da1082014-02-24 17:54:35 -0800697 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700698 return true;
Craig Mautner95da1082014-02-24 17:54:35 -0800699 }
700
Wale Ogunwale10124582016-09-15 20:25:50 -0700701 boolean animateForIme(float interpolatedValue, float animationTarget,
702 float dividerAnimationTarget) {
703 boolean updated = false;
704
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700705 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
706 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700707 if (stack == null || !stack.isAdjustedForIme()) {
708 continue;
709 }
710
711 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
712 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
713 updated = true;
714 } else {
715 mDividerControllerLocked.mLastAnimationProgress =
716 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
717 mDividerControllerLocked.mLastDividerProgress =
718 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
719 updated |= stack.updateAdjustForIme(
720 mDividerControllerLocked.mLastAnimationProgress,
721 mDividerControllerLocked.mLastDividerProgress,
722 false /* force */);
723 }
724 if (interpolatedValue >= 1f) {
725 stack.endImeAdjustAnimation();
726 }
727 }
728
729 return updated;
730 }
731
732 boolean clearImeAdjustAnimation() {
733 boolean changed = false;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700734 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
735 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700736 if (stack != null && stack.isAdjustedForIme()) {
737 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
738 changed = true;
739 }
740 }
741 return changed;
742 }
743
744 void beginImeAdjustAnimation() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700745 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
746 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700747 if (stack.isVisible() && stack.isAdjustedForIme()) {
748 stack.beginImeAdjustAnimation();
749 }
750 }
751 }
752
753 void adjustForImeIfNeeded() {
754 final WindowState imeWin = mService.mInputMethodWindow;
755 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
756 && !mDividerControllerLocked.isImeHideRequested();
757 final boolean dockVisible = mService.isStackVisibleLocked(DOCKED_STACK_ID);
758 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
759 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
760 imeTargetStack.getDockSide() : DOCKED_INVALID;
761 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
762 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
763 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
764 final int imeHeight = mService.mPolicy.getInputMethodWindowVisibleHeightLw();
765 final boolean imeHeightChanged = imeVisible &&
766 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
767
768 // The divider could be adjusted for IME position, or be thinner than usual,
769 // or both. There are three possible cases:
770 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
771 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
772 // - If IME is not visible, divider is not moved and is normal width.
773
774 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700775 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
776 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700777 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
778 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)) {
779 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
780 } else {
781 stack.resetAdjustedForIme(false);
782 }
783 }
784 mDividerControllerLocked.setAdjustedForIme(
785 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
786 } else {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700787 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
788 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700789 stack.resetAdjustedForIme(!dockVisible);
790 }
791 mDividerControllerLocked.setAdjustedForIme(
792 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
793 }
Winson Chung655332c2016-10-31 13:14:28 -0700794 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -0700795 }
796
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700797 void setInputMethodAnimLayerAdjustment(int adj) {
798 if (DEBUG_LAYERS) Slog.v(TAG_WM, "Setting im layer adj to " + adj);
799 mInputMethodAnimLayerAdjustment = adj;
800 final WindowState imw = mService.mInputMethodWindow;
801 if (imw != null) {
802 imw.adjustAnimLayer(adj);
803 }
804 for (int i = mService.mInputMethodDialogs.size() - 1; i >= 0; i--) {
805 final WindowState dialog = mService.mInputMethodDialogs.get(i);
806 // TODO: This and other places setting mAnimLayer can probably use WS.adjustAnimLayer,
807 // but need to make sure we are not setting things twice for child windows that are
808 // already in the list.
809 dialog.mWinAnimator.mAnimLayer = dialog.mLayer + adj;
810 if (DEBUG_LAYERS) Slog.v(TAG_WM, "IM win " + imw
811 + " anim layer: " + dialog.mWinAnimator.mAnimLayer);
812 }
813 }
814
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700815 /**
816 * If a window that has an animation specifying a colored background and the current wallpaper
817 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
818 * suddenly disappear.
819 */
820 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
821 for (int i = mWindows.size() - 1; i >= 0; --i) {
822 final WindowState win = mWindows.get(i);
823 if (win.mIsWallpaper && win.isVisibleNow()) {
824 return win.mWinAnimator.mAnimLayer;
825 }
826 }
827 return winAnimator.mAnimLayer;
828 }
829
Wale Ogunwale10124582016-09-15 20:25:50 -0700830 void prepareFreezingTaskBounds() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700831 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
832 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -0700833 stack.prepareFreezingTaskBounds();
834 }
835 }
836
Wale Ogunwale94744212015-09-21 19:01:47 -0700837 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700838 getLogicalDisplayRect(mTmpRect, newRotation);
839
840 // Compute a transform matrix to undo the coordinate space transformation,
841 // and present the window at the same physical position it previously occupied.
842 final int deltaRotation = deltaRotation(newRotation, oldRotation);
843 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
844
845 mTmpRectF.set(bounds);
846 mTmpMatrix.mapRect(mTmpRectF);
847 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -0700848 }
849
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800850 static int deltaRotation(int oldRotation, int newRotation) {
851 int delta = newRotation - oldRotation;
852 if (delta < 0) delta += 4;
853 return delta;
854 }
855
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700856 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700857 Matrix outMatrix) {
858 // For rotations without Z-ordering we don't need the target rectangle's position.
859 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
860 displayHeight, outMatrix);
861 }
862
863 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
864 float displayWidth, float displayHeight, Matrix outMatrix) {
865 switch (rotation) {
866 case ROTATION_0:
867 outMatrix.reset();
868 break;
869 case ROTATION_270:
870 outMatrix.setRotate(270, 0, 0);
871 outMatrix.postTranslate(0, displayHeight);
872 outMatrix.postTranslate(rectTop, 0);
873 break;
874 case ROTATION_180:
875 outMatrix.reset();
876 break;
877 case ROTATION_90:
878 outMatrix.setRotate(90, 0, 0);
879 outMatrix.postTranslate(displayWidth, 0);
880 outMatrix.postTranslate(-rectTop, rectLeft);
881 break;
882 }
883 }
884
Craig Mautnera91f9e22012-09-14 16:22:08 -0700885 public void dump(String prefix, PrintWriter pw) {
886 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
887 final String subPrefix = " " + prefix;
888 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
889 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
890 pw.print("dpi");
891 if (mInitialDisplayWidth != mBaseDisplayWidth
892 || mInitialDisplayHeight != mBaseDisplayHeight
893 || mInitialDisplayDensity != mBaseDisplayDensity) {
894 pw.print(" base=");
895 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
896 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
897 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700898 if (mDisplayScalingDisabled) {
899 pw.println(" noscale");
900 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700901 pw.print(" cur=");
902 pw.print(mDisplayInfo.logicalWidth);
903 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
904 pw.print(" app=");
905 pw.print(mDisplayInfo.appWidth);
906 pw.print("x"); pw.print(mDisplayInfo.appHeight);
907 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
908 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
909 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
910 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700911 pw.println(subPrefix + "deferred=" + mDeferredRemoval
912 + " mLayoutNeeded=" + mLayoutNeeded);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800913
Craig Mautnerdc548482014-02-05 13:35:24 -0800914 pw.println();
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700915 pw.println(" Application tokens in top down Z order:");
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700916 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
917 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800918 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700919 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800920
Craig Mautnerdc548482014-02-05 13:35:24 -0800921 pw.println();
922 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700923 pw.println();
924 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800925 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700926 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700927 pw.print(" Exiting #"); pw.print(i);
928 pw.print(' '); pw.print(token);
929 pw.println(':');
930 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800931 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700932 }
Craig Mautner59c00972012-07-30 12:10:24 -0700933 pw.println();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800934 mDimLayerController.dump(prefix + " ", pw);
Jorim Jaggi31f71702016-05-04 16:43:04 -0700935 pw.println();
936 mDividerControllerLocked.dump(prefix + " ", pw);
Winson Chung655332c2016-10-31 13:14:28 -0700937 pw.println();
938 mPinnedStackControllerLocked.dump(prefix + " ", pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700939
940 if (mInputMethodAnimLayerAdjustment != 0) {
941 pw.println(subPrefix
942 + "mInputMethodAnimLayerAdjustment=" + mInputMethodAnimLayerAdjustment);
943 }
Craig Mautner59c00972012-07-30 12:10:24 -0700944 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800945
946 @Override
947 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700948 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700949 }
950
951 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700952 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -0800953 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700954
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800955 /**
956 * @return The docked stack, but only if it is visible, and {@code null} otherwise.
957 */
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700958 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700959 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700960 return (stack != null && stack.isVisible()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700961 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800962
963 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800964 * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not
Jorim Jaggife762342016-10-13 14:33:27 +0200965 * visible.
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800966 */
Jorim Jaggife762342016-10-13 14:33:27 +0200967 TaskStack getDockedStackIgnoringVisibility() {
968 return mService.mStackIdToStack.get(DOCKED_STACK_ID);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800969 }
970
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700971 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800972 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
973 WindowState touchedWin = null;
974 final int x = (int) xf;
975 final int y = (int) yf;
976
977 for (int i = mWindows.size() - 1; i >= 0; i--) {
978 WindowState window = mWindows.get(i);
979 final int flags = window.mAttrs.flags;
980 if (!window.isVisibleLw()) {
981 continue;
982 }
983 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
984 continue;
985 }
986
987 window.getVisibleBounds(mTmpRect);
988 if (!mTmpRect.contains(x, y)) {
989 continue;
990 }
991
992 window.getTouchableRegion(mTmpRegion);
993
994 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
995 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
996 touchedWin = window;
997 break;
998 }
999 }
1000
1001 return touchedWin;
1002 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07001003
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001004 boolean canAddToastWindowForUid(int uid) {
1005 // We allow one toast window per UID being shown at a time.
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001006 final int windowCount = mWindows.size();
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001007 for (int i = 0; i < windowCount; i++) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001008 final WindowState window = mWindows.get(i);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001009 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == uid
Svet Ganov62a40f82016-09-29 00:43:51 -07001010 && !window.mPermanentlyHidden && !window.mAnimatingExit
1011 && !window.mRemoveOnExit) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001012 return false;
1013 }
1014 }
1015 return true;
1016 }
1017
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001018 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001019 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
1020 return;
1021 }
1022 final int lostFocusUid = oldFocus.mOwnerUid;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001023 final int windowCount = mWindows.size();
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001024 final Handler handler = mService.mH;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001025 for (int i = 0; i < windowCount; i++) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001026 final WindowState window = mWindows.get(i);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001027 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == lostFocusUid) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001028 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, window)) {
1029 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, window),
Svetoslav Ganovaa076532016-08-01 19:16:43 -07001030 window.mAttrs.hideTimeoutMilliseconds);
1031 }
1032 }
1033 }
1034 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001035
1036 WindowState findFocusedWindow() {
1037 final AppWindowToken focusedApp = mService.mFocusedApp;
1038
1039 for (int i = mWindows.size() - 1; i >= 0; i--) {
1040 final WindowState win = mWindows.get(i);
1041
1042 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + i + " = " + win
1043 + ", flags=" + win.mAttrs.flags + ", canReceive=" + win.canReceiveKeys());
1044
1045 if (!win.canReceiveKeys()) {
1046 continue;
1047 }
1048
1049 final AppWindowToken wtoken = win.mAppToken;
1050
1051 // If this window's application has been removed, just skip it.
1052 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
1053 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
1054 + (wtoken.removed ? "removed" : "sendingToBottom"));
1055 continue;
1056 }
1057
1058 if (focusedApp == null) {
1059 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
1060 + " using new focus @ " + i + " = " + win);
1061 return win;
1062 }
1063
1064 if (!focusedApp.windowsAreFocusable()) {
1065 // Current focused app windows aren't focusable...
1066 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
1067 + " focusable using new focus @ " + i + " = " + win);
1068 return win;
1069 }
1070
1071 // Descend through all of the app tokens and find the first that either matches
1072 // win.mAppToken (return win) or mFocusedApp (return null).
1073 if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001074 if (focusedApp.compareTo(wtoken) > 0) {
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001075 // App stack below focused app stack. No focus for you!!!
1076 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
1077 "findFocusedWindow: Reached focused app=" + focusedApp);
1078 return null;
1079 }
1080 }
1081
1082 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ "
1083 + i + " = " + win);
1084 return win;
1085 }
1086
1087 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
1088 return null;
1089 }
Wale Ogunwaleec731152016-09-08 20:18:57 -07001090
Wale Ogunwale07bcab72016-10-14 15:30:09 -07001091 void addAppWindowToWindowList(final WindowState win) {
Wale Ogunwaleec731152016-09-08 20:18:57 -07001092 final IWindow client = win.mClient;
1093
1094 WindowList tokenWindowList = getTokenWindowsOnDisplay(win.mToken);
1095 if (!tokenWindowList.isEmpty()) {
Wale Ogunwale07bcab72016-10-14 15:30:09 -07001096 addAppWindowExisting(win, tokenWindowList);
1097 return;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001098 }
1099
1100 // No windows from this token on this display
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001101 if (localLOGV) Slog.v(TAG_WM, "Figuring out where to add app window "
Wale Ogunwaleec731152016-09-08 20:18:57 -07001102 + client.asBinder() + " (token=" + this + ")");
1103
1104 final WindowToken wToken = win.mToken;
1105
1106 // Figure out where the window should go, based on the order of applications.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001107 mTmpGetWindowOnDisplaySearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001108 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1109 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001110 stack.getWindowOnDisplayBeforeToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
1111 if (mTmpGetWindowOnDisplaySearchResult.reachedToken) {
Wale Ogunwaleec731152016-09-08 20:18:57 -07001112 // We have reach the token we are interested in. End search.
1113 break;
1114 }
1115 }
1116
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001117 WindowState pos = mTmpGetWindowOnDisplaySearchResult.foundWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001118
1119 // We now know the index into the apps. If we found an app window above, that gives us the
1120 // position; else we need to look some more.
1121 if (pos != null) {
1122 // Move behind any windows attached to this one.
Wale Ogunwale02319a62016-09-26 15:21:22 -07001123 final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
Wale Ogunwaleec731152016-09-08 20:18:57 -07001124 if (atoken != null) {
1125 tokenWindowList = getTokenWindowsOnDisplay(atoken);
1126 final int NC = tokenWindowList.size();
1127 if (NC > 0) {
1128 WindowState bottom = tokenWindowList.get(0);
1129 if (bottom.mSubLayer < 0) {
1130 pos = bottom;
1131 }
1132 }
1133 }
1134 addWindowToListBefore(win, pos);
Wale Ogunwale07bcab72016-10-14 15:30:09 -07001135 return;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001136 }
1137
1138 // Continue looking down until we find the first token that has windows on this display.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001139 mTmpGetWindowOnDisplaySearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001140 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1141 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001142 stack.getWindowOnDisplayAfterToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
1143 if (mTmpGetWindowOnDisplaySearchResult.foundWindow != null) {
Wale Ogunwaleec731152016-09-08 20:18:57 -07001144 // We have found a window after the token. End search.
1145 break;
1146 }
1147 }
1148
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001149 pos = mTmpGetWindowOnDisplaySearchResult.foundWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001150
1151 if (pos != null) {
1152 // Move in front of any windows attached to this one.
Wale Ogunwale02319a62016-09-26 15:21:22 -07001153 final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
Wale Ogunwaleec731152016-09-08 20:18:57 -07001154 if (atoken != null) {
1155 final WindowState top = atoken.getTopWindow();
1156 if (top != null && top.mSubLayer >= 0) {
1157 pos = top;
1158 }
1159 }
1160 addWindowToListAfter(win, pos);
Wale Ogunwale07bcab72016-10-14 15:30:09 -07001161 return;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001162 }
1163
1164 // Just search for the start of this layer.
1165 final int myLayer = win.mBaseLayer;
1166 int i;
1167 for (i = mWindows.size() - 1; i >= 0; --i) {
1168 final WindowState w = mWindows.get(i);
1169 // Dock divider shares the base layer with application windows, but we want to always
1170 // keep it above the application windows. The sharing of the base layer is intended
1171 // for window animations, which need to be above the dock divider for the duration
1172 // of the animation.
1173 if (w.mBaseLayer <= myLayer && w.mAttrs.type != TYPE_DOCK_DIVIDER) {
1174 break;
1175 }
1176 }
1177 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1178 "Based on layer: Adding window " + win + " at " + (i + 1) + " of "
1179 + mWindows.size());
1180 mWindows.add(i + 1, win);
1181 mService.mWindowsChanged = true;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001182 }
1183
1184 /** Adds this non-app window to the window list. */
1185 void addNonAppWindowToWindowList(WindowState win) {
1186 // Figure out where window should go, based on layer.
1187 int i;
1188 for (i = mWindows.size() - 1; i >= 0; i--) {
1189 final WindowState otherWin = mWindows.get(i);
1190 if (otherWin.getBaseType() != TYPE_WALLPAPER && otherWin.mBaseLayer <= win.mBaseLayer) {
1191 // Wallpaper wanders through the window list, for example to position itself
1192 // directly behind keyguard. Because of this it will break the ordering based on
1193 // WindowState.mBaseLayer. There might windows with higher mBaseLayer behind it and
1194 // we don't want the new window to appear above them. An example of this is adding
1195 // of the docked stack divider. Consider a scenario with the following ordering (top
1196 // to bottom): keyguard, wallpaper, assist preview, apps. We want the dock divider
1197 // to land below the assist preview, so the dock divider must ignore the wallpaper,
1198 // with which it shares the base layer.
1199 break;
1200 }
1201 }
1202
1203 i++;
1204 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1205 "Free window: Adding window " + this + " at " + i + " of " + mWindows.size());
1206 mWindows.add(i, win);
1207 mService.mWindowsChanged = true;
1208 }
1209
Wale Ogunwaleb9a07c32016-10-12 14:55:56 -07001210 void addToWindowList(WindowState win, int index) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001211 mService.mWindowsChanged = true;
Wale Ogunwaleb9a07c32016-10-12 14:55:56 -07001212 mWindows.add(index, win);
1213 }
1214
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001215 boolean removeFromWindowList(WindowState win) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001216 mService.mWindowsChanged = true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001217 return mWindows.remove(win);
1218 }
1219
1220 private int removeWindowAndChildrenFromWindowList(WindowState win, int interestingPos) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001221 int wpos = mWindows.indexOf(win);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001222 if (wpos < 0) {
1223 return interestingPos;
1224 }
1225
1226 if (wpos < interestingPos) interestingPos--;
1227 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001228 mWindows.remove(wpos);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001229 mService.mWindowsChanged = true;
1230 int childWinCount = win.mChildren.size();
1231 while (childWinCount > 0) {
1232 childWinCount--;
1233 final WindowState cw = win.mChildren.get(childWinCount);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001234 int cpos = mWindows.indexOf(cw);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001235 if (cpos >= 0) {
1236 if (cpos < interestingPos) interestingPos--;
1237 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
1238 "Temp removing child at " + cpos + ": " + cw);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001239 mWindows.remove(cpos);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001240 }
1241 }
1242 return interestingPos;
1243 }
1244
Wale Ogunwaleec731152016-09-08 20:18:57 -07001245 void addChildWindowToWindowList(WindowState win) {
1246 final WindowState parentWindow = win.getParentWindow();
1247
1248 WindowList windowsOnSameDisplay = getTokenWindowsOnDisplay(win.mToken);
1249
1250 // Figure out this window's ordering relative to the parent window.
1251 final int wCount = windowsOnSameDisplay.size();
1252 final int sublayer = win.mSubLayer;
1253 int largestSublayer = Integer.MIN_VALUE;
1254 WindowState windowWithLargestSublayer = null;
1255 int i;
1256 for (i = 0; i < wCount; i++) {
1257 WindowState w = windowsOnSameDisplay.get(i);
1258 final int wSublayer = w.mSubLayer;
1259 if (wSublayer >= largestSublayer) {
1260 largestSublayer = wSublayer;
1261 windowWithLargestSublayer = w;
1262 }
1263 if (sublayer < 0) {
1264 // For negative sublayers, we go below all windows in the same sublayer.
1265 if (wSublayer >= sublayer) {
1266 addWindowToListBefore(win, wSublayer >= 0 ? parentWindow : w);
1267 break;
1268 }
1269 } else {
1270 // For positive sublayers, we go above all windows in the same sublayer.
1271 if (wSublayer > sublayer) {
1272 addWindowToListBefore(win, w);
1273 break;
1274 }
1275 }
1276 }
1277 if (i >= wCount) {
1278 if (sublayer < 0) {
1279 addWindowToListBefore(win, parentWindow);
1280 } else {
1281 addWindowToListAfter(win,
1282 largestSublayer >= 0 ? windowWithLargestSublayer : parentWindow);
1283 }
1284 }
1285 }
1286
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001287 /** Updates the layer assignment of windows on this display. */
1288 void assignWindowLayers(boolean setLayoutNeeded) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001289 mLayersController.assignWindowLayers(mWindows.getReadOnly());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001290 if (setLayoutNeeded) {
1291 setLayoutNeeded();
1292 }
1293 }
1294
Wale Ogunwale0303c572016-10-20 10:16:29 -07001295 void adjustWallpaperWindows() {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001296 if (mWallpaperController.adjustWallpaperWindows(mWindows.getReadOnly())) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07001297 assignWindowLayers(true /*setLayoutNeeded*/);
1298 }
1299 }
1300
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001301 /**
1302 * Z-orders the display window list so that:
1303 * <ul>
1304 * <li>Any windows that are currently below the wallpaper window stay below the wallpaper
1305 * window.
1306 * <li>Exiting application windows are at the bottom, but above the wallpaper window.
1307 * <li>All other application windows are above the exiting application windows and ordered based
1308 * on the ordering of their stacks and tasks on the display.
1309 * <li>Non-application windows are at the very top.
1310 * </ul>
1311 * <p>
1312 * NOTE: This isn't a complete picture of what the user see. Further manipulation of the window
1313 * surface layering is done in {@link WindowLayersController}.
1314 */
1315 void rebuildAppWindowList() {
1316 int count = mWindows.size();
1317 int i;
1318 int lastBelow = -1;
1319 int numRemoved = 0;
1320
1321 if (mRebuildTmp.length < count) {
1322 mRebuildTmp = new WindowState[count + 10];
1323 }
1324
1325 // First remove all existing app windows.
1326 i = 0;
1327 while (i < count) {
1328 final WindowState w = mWindows.get(i);
1329 if (w.mAppToken != null) {
1330 final WindowState win = mWindows.remove(i);
1331 win.mRebuilding = true;
1332 mRebuildTmp[numRemoved] = win;
1333 mService.mWindowsChanged = true;
1334 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Rebuild removing window: " + win);
1335 count--;
1336 numRemoved++;
1337 continue;
1338 } else if (lastBelow == i-1) {
1339 if (w.mAttrs.type == TYPE_WALLPAPER) {
1340 lastBelow = i;
1341 }
1342 }
1343 i++;
1344 }
1345
1346 // Keep whatever windows were below the app windows still below, by skipping them.
1347 lastBelow++;
1348 i = lastBelow;
1349
1350 // First add all of the exiting app tokens... these are no longer in the main app list,
1351 // but still have windows shown. We put them in the back because now that the animation is
1352 // over we no longer will care about them.
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001353 final int numStacks = mTaskStackContainers.size();
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001354 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001355 AppTokenList exitingAppTokens = mTaskStackContainers.get(stackNdx).mExitingAppTokens;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001356 int NT = exitingAppTokens.size();
1357 for (int j = 0; j < NT; j++) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001358 i = exitingAppTokens.get(j).rebuildWindowListUnchecked(i);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001359 }
1360 }
1361
1362 // And add in the still active app tokens in Z order.
1363 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001364 i = mTaskStackContainers.get(stackNdx).rebuildWindowList(i);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001365 }
1366
1367 i -= lastBelow;
1368 if (i != numRemoved) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001369 setLayoutNeeded();
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001370 Slog.w(TAG_WM, "On display=" + mDisplayId + " Rebuild removed " + numRemoved
1371 + " windows but added " + i + " rebuildAppWindowListLocked() "
1372 + " callers=" + Debug.getCallers(10));
1373 for (i = 0; i < numRemoved; i++) {
1374 WindowState ws = mRebuildTmp[i];
1375 if (ws.mRebuilding) {
1376 StringWriter sw = new StringWriter();
1377 PrintWriter pw = new FastPrintWriter(sw, false, 1024);
1378 ws.dump(pw, "", true);
1379 pw.flush();
1380 Slog.w(TAG_WM, "This window was lost: " + ws);
1381 Slog.w(TAG_WM, sw.toString());
1382 ws.mWinAnimator.destroySurfaceLocked();
1383 }
1384 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001385 Slog.w(TAG_WM, "Current window hierarchy:");
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001386 dumpChildrenNames();
1387 Slog.w(TAG_WM, "Final window list:");
1388 dumpWindows();
1389 }
1390 Arrays.fill(mRebuildTmp, null);
1391 }
1392
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001393 /** Rebuilds the display's window list and does a relayout if something changed. */
1394 void rebuildAppWindowsAndLayoutIfNeeded() {
1395 mTmpWindows.clear();
1396 mTmpWindows.addAll(mWindows);
1397
1398 rebuildAppWindowList();
1399
1400 // Set displayContent.mLayoutNeeded if window order changed.
1401 final int tmpSize = mTmpWindows.size();
1402 final int winSize = mWindows.size();
1403 int tmpNdx = 0, winNdx = 0;
1404 while (tmpNdx < tmpSize && winNdx < winSize) {
1405 // Skip over all exiting windows, they've been moved out of order.
1406 WindowState tmp;
1407 do {
1408 tmp = mTmpWindows.get(tmpNdx++);
1409 } while (tmpNdx < tmpSize && tmp.mAppToken != null && tmp.mAppToken.mIsExiting);
1410
1411 WindowState win;
1412 do {
1413 win = mWindows.get(winNdx++);
1414 } while (winNdx < winSize && win.mAppToken != null && win.mAppToken.mIsExiting);
1415
1416 if (tmp != win) {
1417 // Window order changed.
1418 setLayoutNeeded();
1419 break;
1420 }
1421 }
1422 if (tmpNdx != winNdx) {
1423 // One list was different from the other.
1424 setLayoutNeeded();
1425 }
1426 mTmpWindows.clear();
1427
1428 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
1429 false /*updateInputWindows*/)) {
1430 assignWindowLayers(false /* setLayoutNeeded */);
1431 }
1432
1433 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
1434 mService.mWindowPlacerLocked.performSurfacePlacement();
1435 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1436 }
1437
1438 void updateInputWindows(InputMonitor inputMonitor, WindowState inputFocus, boolean inDrag) {
1439 final InputConsumerImpl navInputConsumer =
1440 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_NAVIGATION, mDisplayId);
1441 final InputConsumerImpl pipInputConsumer =
1442 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_PIP, mDisplayId);
1443 final InputConsumerImpl wallpaperInputConsumer =
1444 mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_WALLPAPER, mDisplayId);
1445 boolean addInputConsumerHandle = navInputConsumer != null;
1446 boolean addPipInputConsumerHandle = pipInputConsumer != null;
1447 boolean addWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
1448 final Rect pipTouchableBounds = addPipInputConsumerHandle ? new Rect() : null;
1449 boolean disableWallpaperTouchEvents = false;
1450
1451 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
1452 final WindowState child = mWindows.get(winNdx);
1453 final InputChannel inputChannel = child.mInputChannel;
1454 final InputWindowHandle inputWindowHandle = child.mInputWindowHandle;
1455 if (inputChannel == null || inputWindowHandle == null || child.mRemoved
1456 || child.isAdjustedForMinimizedDock()) {
1457 // Skip this window because it cannot possibly receive input.
1458 continue;
1459 }
1460
1461 if (addPipInputConsumerHandle
1462 && child.getStackId() == PINNED_STACK_ID
1463 && inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer) {
1464 // Update the bounds of the Pip input consumer to match the Pinned stack
1465 child.getStack().getBounds(pipTouchableBounds);
1466 pipInputConsumer.mWindowHandle.touchableRegion.set(pipTouchableBounds);
1467 inputMonitor.addInputWindowHandle(pipInputConsumer.mWindowHandle);
1468 addPipInputConsumerHandle = false;
1469 }
1470
1471 if (addInputConsumerHandle
1472 && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) {
1473 inputMonitor.addInputWindowHandle(navInputConsumer.mWindowHandle);
1474 addInputConsumerHandle = false;
1475 }
1476
1477 if (addWallpaperInputConsumerHandle) {
1478 if (child.mAttrs.type == TYPE_WALLPAPER && child.isVisibleLw()) {
1479 // Add the wallpaper input consumer above the first visible wallpaper.
1480 inputMonitor.addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
1481 addWallpaperInputConsumerHandle = false;
1482 }
1483 }
1484
1485 final int flags = child.mAttrs.flags;
1486 final int privateFlags = child.mAttrs.privateFlags;
1487 final int type = child.mAttrs.type;
1488
1489 final boolean hasFocus = child == inputFocus;
1490 final boolean isVisible = child.isVisibleLw();
1491 if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
1492 disableWallpaperTouchEvents = true;
1493 }
1494 final boolean hasWallpaper = mWallpaperController.isWallpaperTarget(child)
1495 && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
1496 && !disableWallpaperTouchEvents;
1497
1498 // If there's a drag in progress and 'child' is a potential drop target,
1499 // make sure it's been told about the drag
1500 if (inDrag && isVisible && isDefaultDisplay) {
1501 mService.mDragState.sendDragStartedIfNeededLw(child);
1502 }
1503
1504 inputMonitor.addInputWindowHandle(
1505 inputWindowHandle, child, flags, type, isVisible, hasFocus, hasWallpaper);
1506 }
1507
1508 if (addWallpaperInputConsumerHandle) {
1509 // No visible wallpaper found, add the wallpaper input consumer at the end.
1510 inputMonitor.addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
1511 }
1512 }
1513
1514 /** Returns true if a leaked surface was destroyed */
1515 boolean destroyLeakedSurfaces() {
1516 boolean leakedSurface = false;
1517 final int numWindows = mWindows.size();
1518 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
1519 final WindowState ws = mWindows.get(winNdx);
1520 final WindowStateAnimator wsa = ws.mWinAnimator;
1521 if (wsa.mSurfaceController == null) {
1522 continue;
1523 }
1524 if (!mService.mSessions.contains(wsa.mSession)) {
1525 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
1526 + ws + " surface=" + wsa.mSurfaceController
1527 + " token=" + ws.mToken
1528 + " pid=" + ws.mSession.mPid
1529 + " uid=" + ws.mSession.mUid);
1530 wsa.destroySurface();
1531 mService.mForceRemoves.add(ws);
1532 leakedSurface = true;
1533 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
1534 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
1535 + ws + " surface=" + wsa.mSurfaceController
1536 + " token=" + ws.mAppToken
1537 + " saved=" + ws.hasSavedSurface());
1538 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", false);
1539 wsa.destroySurface();
1540 leakedSurface = true;
1541 }
1542 }
1543
1544 return leakedSurface;
1545 }
1546
Wale Ogunwaleec731152016-09-08 20:18:57 -07001547 /** Return the list of Windows on this display associated with the input token. */
1548 WindowList getTokenWindowsOnDisplay(WindowToken token) {
1549 final WindowList windowList = new WindowList();
1550 final int count = mWindows.size();
1551 for (int i = 0; i < count; i++) {
1552 final WindowState win = mWindows.get(i);
1553 if (win.mToken == token) {
1554 windowList.add(win);
1555 }
1556 }
1557 return windowList;
1558 }
1559
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001560 private void reAddToWindowList(WindowState win) {
1561 win.mToken.addWindow(win);
1562 // This is a hack to get all of the child windows added as well at the right position. Child
1563 // windows should be rare and this case should be rare, so it shouldn't be that big a deal.
1564 int wpos = mWindows.indexOf(win);
1565 if (wpos >= 0) {
1566 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "ReAdd removing from " + wpos + ": " + win);
1567 mWindows.remove(wpos);
1568 mService.mWindowsChanged = true;
1569 win.reAddWindow(wpos);
1570 }
1571 }
1572
1573 void moveInputMethodDialogs(int pos) {
1574 ArrayList<WindowState> dialogs = mService.mInputMethodDialogs;
1575
1576 final int N = dialogs.size();
1577 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Removing " + N + " dialogs w/pos=" + pos);
1578 for (int i = 0; i < N; i++) {
1579 pos = removeWindowAndChildrenFromWindowList(dialogs.get(i), pos);
1580 }
1581 if (DEBUG_INPUT_METHOD) {
1582 Slog.v(TAG_WM, "Window list w/pos=" + pos);
1583 logWindowList(mWindows, " ");
1584 }
1585
1586 WindowState ime = mService.mInputMethodWindow;
1587 if (pos >= 0) {
1588 // Skip windows owned by the input method.
1589 if (ime != null) {
1590 while (pos < mWindows.size()) {
1591 WindowState wp = mWindows.get(pos);
1592 if (wp == ime || wp.getParentWindow() == ime) {
1593 pos++;
1594 continue;
1595 }
1596 break;
1597 }
1598 }
1599 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Adding " + N + " dialogs at pos=" + pos);
1600 for (int i=0; i<N; i++) {
1601 WindowState win = dialogs.get(i);
1602 pos = win.reAddWindow(pos);
1603 }
1604 if (DEBUG_INPUT_METHOD) {
1605 Slog.v(TAG_WM, "Final window list:");
1606 logWindowList(mWindows, " ");
1607 }
1608 return;
1609 }
1610 for (int i=0; i<N; i++) {
1611 WindowState win = dialogs.get(i);
1612 reAddToWindowList(win);
1613 if (DEBUG_INPUT_METHOD) {
1614 Slog.v(TAG_WM, "No IM target, final list:");
1615 logWindowList(mWindows, " ");
1616 }
1617 }
1618 }
1619
1620 boolean moveInputMethodWindowsIfNeeded(boolean needAssignLayers) {
1621 final WindowState imWin = mService.mInputMethodWindow;
1622 final int DN = mService.mInputMethodDialogs.size();
1623 if (imWin == null && DN == 0) {
1624 return false;
1625 }
1626
1627 // TODO(multidisplay): IMEs are only supported on the default display.
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001628 int imPos = findDesiredInputMethodWindowIndex(true);
1629 if (imPos >= 0) {
1630 // In this case, the input method windows are to be placed
1631 // immediately above the window they are targeting.
1632
1633 // First check to see if the input method windows are already
1634 // located here, and contiguous.
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001635 final int N = mWindows.size();
1636 final WindowState firstImWin = imPos < N ? mWindows.get(imPos) : null;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001637
1638 // Figure out the actual input method window that should be
1639 // at the bottom of their stack.
1640 WindowState baseImWin = imWin != null ? imWin : mService.mInputMethodDialogs.get(0);
1641 final WindowState cw = baseImWin.getBottomChild();
1642 if (cw != null && cw.mSubLayer < 0) {
1643 baseImWin = cw;
1644 }
1645
1646 if (firstImWin == baseImWin) {
1647 // The windows haven't moved... but are they still contiguous?
1648 // First find the top IM window.
1649 int pos = imPos+1;
1650 while (pos < N) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001651 if (!(mWindows.get(pos)).mIsImWindow) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001652 break;
1653 }
1654 pos++;
1655 }
1656 pos++;
1657 // Now there should be no more input method windows above.
1658 while (pos < N) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001659 if ((mWindows.get(pos)).mIsImWindow) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001660 break;
1661 }
1662 pos++;
1663 }
1664 if (pos >= N) {
1665 return false;
1666 }
1667 }
1668
1669 if (imWin != null) {
1670 if (DEBUG_INPUT_METHOD) {
1671 Slog.v(TAG_WM, "Moving IM from " + imPos);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001672 logWindowList(mWindows, " ");
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001673 }
1674 imPos = removeWindowAndChildrenFromWindowList(imWin, imPos);
1675 if (DEBUG_INPUT_METHOD) {
1676 Slog.v(TAG_WM, "List after removing with new pos " + imPos + ":");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001677 logWindowList(mWindows, " ");
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001678 }
1679 imWin.reAddWindow(imPos);
1680 if (DEBUG_INPUT_METHOD) {
1681 Slog.v(TAG_WM, "List after moving IM to " + imPos + ":");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001682 logWindowList(mWindows, " ");
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001683 }
1684 if (DN > 0) moveInputMethodDialogs(imPos+1);
1685 } else {
1686 moveInputMethodDialogs(imPos);
1687 }
1688
1689 } else {
1690 // In this case, the input method windows go in a fixed layer,
1691 // because they aren't currently associated with a focus window.
1692
1693 if (imWin != null) {
1694 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Moving IM from " + imPos);
1695 removeWindowAndChildrenFromWindowList(imWin, 0);
1696 reAddToWindowList(imWin);
1697 if (DEBUG_INPUT_METHOD) {
1698 Slog.v(TAG_WM, "List with no IM target:");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001699 logWindowList(mWindows, " ");
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001700 }
1701 if (DN > 0) moveInputMethodDialogs(-1);
1702 } else {
1703 moveInputMethodDialogs(-1);
1704 }
1705
1706 }
1707
1708 if (needAssignLayers) {
1709 assignWindowLayers(false /* setLayoutNeeded */);
1710 }
1711
1712 return true;
1713 }
1714
1715 /**
1716 * Dig through the WindowStates and find the one that the Input Method will target.
1717 * @param willMove
1718 * @return The index+1 in mWindows of the discovered target.
1719 */
1720 int findDesiredInputMethodWindowIndex(boolean willMove) {
1721 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
1722 // same display. Or even when the current IME/target are not on the same screen as the next
1723 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001724 WindowState w = null;
1725 int i;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001726 for (i = mWindows.size() - 1; i >= 0; --i) {
1727 final WindowState win = mWindows.get(i);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001728
1729 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG_WM, "Checking window @" + i
1730 + " " + win + " fl=0x" + Integer.toHexString(win.mAttrs.flags));
1731 if (canBeImeTarget(win)) {
1732 w = win;
1733 //Slog.i(TAG_WM, "Putting input method here!");
1734
1735 // Yet more tricksyness! If this window is a "starting" window, we do actually want
1736 // to be on top of it, but it is not -really- where input will go. So if the caller
1737 // is not actually looking to move the IME, look down below for a real window to
1738 // target...
1739 if (!willMove && w.mAttrs.type == TYPE_APPLICATION_STARTING && i > 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001740 final WindowState wb = mWindows.get(i-1);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001741 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1742 i--;
1743 w = wb;
1744 }
1745 }
1746 break;
1747 }
1748 }
1749
1750 // Now w is either mWindows[0] or an IME (or null if mWindows is empty).
1751
1752 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG_WM, "Proposed new IME target: " + w);
1753
1754 // Now, a special case -- if the last target's window is in the process of exiting, and is
1755 // above the new target, keep on the last target to avoid flicker. Consider for example a
1756 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
1757 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
1758 // scrim.
1759 final WindowState curTarget = mService.mInputMethodTarget;
1760 if (curTarget != null
1761 && curTarget.isDisplayedLw()
1762 && curTarget.isClosing()
1763 && (w == null || curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer)) {
1764 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001765 return mWindows.indexOf(curTarget) + 1;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001766 }
1767
1768 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target="
1769 + w + " willMove=" + willMove);
1770
1771 if (willMove && w != null) {
1772 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
1773 if (token != null) {
1774
1775 // Now some fun for dealing with window animations that modify the Z order. We need
1776 // to look at all windows below the current target that are in this app, finding the
1777 // highest visible one in layering.
1778 WindowState highestTarget = null;
1779 int highestPos = 0;
1780 if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001781 WindowList curWindows = token.getDisplayContent().mWindows;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001782 int pos = curWindows.indexOf(curTarget);
1783 while (pos >= 0) {
1784 WindowState win = curWindows.get(pos);
1785 if (win.mAppToken != token) {
1786 break;
1787 }
1788 if (!win.mRemoved) {
1789 if (highestTarget == null || win.mWinAnimator.mAnimLayer >
1790 highestTarget.mWinAnimator.mAnimLayer) {
1791 highestTarget = win;
1792 highestPos = pos;
1793 }
1794 }
1795 pos--;
1796 }
1797 }
1798
1799 if (highestTarget != null) {
1800 final AppTransition appTransition = mService.mAppTransition;
1801 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
1802 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
1803 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
1804 + " new layer=" + w.mWinAnimator.mAnimLayer);
1805
1806 if (appTransition.isTransitionSet()) {
1807 // If we are currently setting up for an animation, hold everything until we
1808 // can find out what will happen.
1809 mService.mInputMethodTargetWaitingAnim = true;
1810 mService.mInputMethodTarget = highestTarget;
1811 return highestPos + 1;
1812 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
1813 highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) {
1814 // If the window we are currently targeting is involved with an animation,
1815 // and it is on top of the next target we will be over, then hold off on
1816 // moving until that is done.
1817 mService.mInputMethodTargetWaitingAnim = true;
1818 mService.mInputMethodTarget = highestTarget;
1819 return highestPos + 1;
1820 }
1821 }
1822 }
1823 }
1824
1825 //Slog.i(TAG_WM, "Placing input method @" + (i+1));
1826 if (w != null) {
1827 if (willMove) {
1828 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
1829 + w + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
1830 mService.mInputMethodTarget = w;
1831 mService.mInputMethodTargetWaitingAnim = false;
1832 if (w.mAppToken != null) {
1833 setInputMethodAnimLayerAdjustment(
1834 w.mAppToken.mAppAnimator.animLayerAdjustment);
1835 } else {
1836 setInputMethodAnimLayerAdjustment(0);
1837 }
1838 }
1839
1840 // If the docked divider is visible, we still need to go through this whole excercise to
1841 // find the appropriate input method target (used for animations and dialog
1842 // adjustments), but for purposes of Z ordering we simply wish to place it above the
1843 // docked divider. Unless it is already above the divider.
1844 final WindowState dockedDivider = mDividerControllerLocked.getWindow();
1845 if (dockedDivider != null && dockedDivider.isVisibleLw()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001846 int dividerIndex = mWindows.indexOf(dockedDivider);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001847 if (dividerIndex > 0 && dividerIndex > i) {
1848 return dividerIndex + 1;
1849 }
1850 }
1851 return i+1;
1852 }
1853 if (willMove) {
1854 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
1855 + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
1856 mService.mInputMethodTarget = null;
1857 setInputMethodAnimLayerAdjustment(0);
1858 }
1859 return -1;
1860 }
1861
1862 private static boolean canBeImeTarget(WindowState w) {
1863 final int fl = w.mAttrs.flags & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1864 final int type = w.mAttrs.type;
1865
1866 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
1867 && type != TYPE_APPLICATION_STARTING) {
1868 return false;
1869 }
1870
1871 if (DEBUG_INPUT_METHOD) {
1872 Slog.i(TAG_WM, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1873 if (!w.isVisibleOrAdding()) {
1874 Slog.i(TAG_WM, " mSurfaceController=" + w.mWinAnimator.mSurfaceController
1875 + " relayoutCalled=" + w.mRelayoutCalled
1876 + " viewVis=" + w.mViewVisibility
1877 + " policyVis=" + w.mPolicyVisibility
1878 + " policyVisAfterAnim=" + w.mPolicyVisibilityAfterAnim
1879 + " parentHidden=" + w.isParentWindowHidden()
1880 + " exiting=" + w.mAnimatingExit + " destroying=" + w.mDestroying);
1881 if (w.mAppToken != null) {
1882 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1883 }
1884 }
1885 }
1886 return w.isVisibleOrAdding();
1887 }
1888
1889 private void logWindowList(final WindowList windows, String prefix) {
1890 int N = windows.size();
1891 while (N > 0) {
1892 N--;
1893 Slog.v(TAG_WM, prefix + "#" + N + ": " + windows.get(N));
1894 }
1895 }
1896
1897 boolean getNeedsMenu(WindowState win, WindowManagerPolicy.WindowState bottom) {
1898 int index = -1;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001899 while (true) {
1900 if (win.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
1901 return win.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
1902 }
1903 // If we reached the bottom of the range of windows we are considering,
1904 // assume no menu is needed.
1905 if (win == bottom) {
1906 return false;
1907 }
1908 // The current window hasn't specified whether menu key is needed; look behind it.
1909 // First, we may need to determine the starting position.
1910 if (index < 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001911 index = mWindows.indexOf(win);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001912 }
1913 index--;
1914 if (index < 0) {
1915 return false;
1916 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001917 win = mWindows.get(index);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001918 }
1919 }
1920
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001921 void setLayoutNeeded() {
1922 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
1923 mLayoutNeeded = true;
1924 }
1925
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001926 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001927 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
1928 mLayoutNeeded = false;
1929 }
1930
1931 boolean isLayoutNeeded() {
1932 return mLayoutNeeded;
1933 }
1934
Wale Ogunwale07bcab72016-10-14 15:30:09 -07001935 private void addAppWindowExisting(WindowState win, WindowList tokenWindowList) {
Wale Ogunwaleec731152016-09-08 20:18:57 -07001936
Wale Ogunwaleec731152016-09-08 20:18:57 -07001937 // If this application has existing windows, we simply place the new window on top of
1938 // them... but keep the starting window on top.
1939 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1940 // Base windows go behind everything else.
1941 final WindowState lowestWindow = tokenWindowList.get(0);
1942 addWindowToListBefore(win, lowestWindow);
Wale Ogunwaleec731152016-09-08 20:18:57 -07001943 } else {
1944 final AppWindowToken atoken = win.mAppToken;
1945 final int windowListPos = tokenWindowList.size();
1946 final WindowState lastWindow = tokenWindowList.get(windowListPos - 1);
1947 if (atoken != null && lastWindow == atoken.startingWindow) {
1948 addWindowToListBefore(win, lastWindow);
Wale Ogunwaleec731152016-09-08 20:18:57 -07001949 } else {
1950 int newIdx = findIdxBasedOnAppTokens(win);
1951 // There is a window above this one associated with the same apptoken note that the
1952 // window could be a floating window that was created later or a window at the top
1953 // of the list of windows associated with this token.
1954 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1955 "not Base app: Adding window " + win + " at " + (newIdx + 1) + " of "
1956 + mWindows.size());
1957 mWindows.add(newIdx + 1, win);
Wale Ogunwaleec731152016-09-08 20:18:57 -07001958 mService.mWindowsChanged = true;
1959 }
1960 }
Wale Ogunwaleec731152016-09-08 20:18:57 -07001961 }
1962
1963 /** Places the first input window after the second input window in the window list. */
1964 private void addWindowToListAfter(WindowState first, WindowState second) {
1965 final int i = mWindows.indexOf(second);
1966 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1967 "Adding window " + this + " at " + (i + 1) + " of " + mWindows.size()
1968 + " (after " + second + ")");
1969 mWindows.add(i + 1, first);
1970 mService.mWindowsChanged = true;
1971 }
1972
1973 /** Places the first input window before the second input window in the window list. */
1974 private void addWindowToListBefore(WindowState first, WindowState second) {
1975 int i = mWindows.indexOf(second);
1976 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1977 "Adding window " + this + " at " + i + " of " + mWindows.size()
1978 + " (before " + second + ")");
1979 if (i < 0) {
1980 Slog.w(TAG_WM, "addWindowToListBefore: Unable to find " + second + " in " + mWindows);
1981 i = 0;
1982 }
1983 mWindows.add(i, first);
1984 mService.mWindowsChanged = true;
1985 }
1986
1987 /**
1988 * This method finds out the index of a window that has the same app token as win. used for z
1989 * ordering the windows in mWindows
1990 */
1991 private int findIdxBasedOnAppTokens(WindowState win) {
1992 for(int j = mWindows.size() - 1; j >= 0; j--) {
1993 final WindowState wentry = mWindows.get(j);
1994 if(wentry.mAppToken == win.mAppToken) {
1995 return j;
1996 }
1997 }
1998 return -1;
1999 }
2000
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002001 private void dumpChildrenNames() {
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002002 StringBuilder output = new StringBuilder();
2003 dumpChildrenNames(output, " ");
2004 Slog.v(TAG_WM, output.toString());
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002005 }
2006
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002007 private void dumpWindows() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002008 Slog.v(TAG_WM, " Display #" + mDisplayId);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002009 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
2010 Slog.v(TAG_WM, " #" + winNdx + ": " + mWindows.get(winNdx));
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002011 }
2012 }
2013
Wale Ogunwale02319a62016-09-26 15:21:22 -07002014 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2015 if (mTokenMap.isEmpty()) {
2016 return;
2017 }
2018 pw.println(" Display #" + mDisplayId);
2019 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2020 while (it.hasNext()) {
2021 final WindowToken token = it.next();
2022 pw.print(" ");
2023 pw.print(token);
2024 if (dumpAll) {
2025 pw.println(':');
2026 token.dump(pw, " ");
2027 } else {
2028 pw.println();
2029 }
2030 }
2031 }
2032
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002033 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
2034 final int count = mWindows.size();
2035 for (int j = 0; j < count; j++) {
2036 final WindowStateAnimator wAnim = mWindows.get(j).mWinAnimator;
2037 pw.println(subPrefix + "Window #" + j + ": " + wAnim);
2038 }
2039 }
2040
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002041 void enableSurfaceTrace(FileDescriptor fd) {
2042 for (int i = mWindows.size() - 1; i >= 0; i--) {
2043 final WindowState win = mWindows.get(i);
2044 win.mWinAnimator.enableSurfaceTrace(fd);
2045 }
2046 }
2047
2048 void disableSurfaceTrace() {
2049 for (int i = mWindows.size() - 1; i >= 0; i--) {
2050 final WindowState win = mWindows.get(i);
2051 win.mWinAnimator.disableSurfaceTrace();
2052 }
2053 }
2054
Jorim Jaggife762342016-10-13 14:33:27 +02002055 /**
2056 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2057 */
2058 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2059 final WindowManagerPolicy policy = mService.mPolicy;
2060 for (int i = mWindows.size() - 1; i >= 0; i--) {
2061 final WindowState window = mWindows.get(i);
2062 if (window.mAppToken == null && policy.canBeHiddenByKeyguardLw(window)) {
2063 window.mWinAnimator.setAnimation(
2064 policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
2065 }
2066 }
2067 }
2068
Wale Ogunwale494009b82016-10-21 09:01:38 -07002069 boolean checkWaitingForWindows() {
2070
2071 boolean haveBootMsg = false;
2072 boolean haveApp = false;
2073 // if the wallpaper service is disabled on the device, we're never going to have
2074 // wallpaper, don't bother waiting for it
2075 boolean haveWallpaper = false;
2076 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2077 com.android.internal.R.bool.config_enableWallpaperService)
2078 && !mService.mOnlyCore;
2079 boolean haveKeyguard = true;
2080 final int count = mWindows.size();
2081 for (int i = 0; i < count; i++) {
2082 final WindowState w = mWindows.get(i);
2083 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2084 return true;
2085 }
2086 if (w.isDrawnLw()) {
2087 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
2088 haveBootMsg = true;
2089 } else if (w.mAttrs.type == TYPE_APPLICATION
2090 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
2091 haveApp = true;
2092 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
2093 haveWallpaper = true;
2094 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
2095 haveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
2096 }
2097 }
2098 }
2099
2100 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2101 "******** booted=" + mService.mSystemBooted
2102 + " msg=" + mService.mShowingBootMessages
2103 + " haveBoot=" + haveBootMsg + " haveApp=" + haveApp
2104 + " haveWall=" + haveWallpaper + " wallEnabled=" + wallpaperEnabled
2105 + " haveKeyguard=" + haveKeyguard);
2106
2107 // If we are turning on the screen to show the boot message, don't do it until the boot
2108 // message is actually displayed.
2109 if (!mService.mSystemBooted && !haveBootMsg) {
2110 return true;
2111 }
2112
2113 // If we are turning on the screen after the boot is completed normally, don't do so until
2114 // we have the application and wallpaper.
2115 if (mService.mSystemBooted && ((!haveApp && !haveKeyguard) ||
2116 (wallpaperEnabled && !haveWallpaper))) {
2117 return true;
2118 }
2119
2120 return false;
2121 }
2122
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002123 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07002124 final WallpaperController wallpaperController = mWallpaperController;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002125 for (int i = mWindows.size() - 1; i >= 0; i--) {
2126 WindowState win = mWindows.get(i);
2127 WindowStateAnimator winAnimator = win.mWinAnimator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002128 if (winAnimator.hasSurface()) {
2129 final boolean wasAnimating = winAnimator.mWasAnimating;
2130 final boolean nowAnimating = winAnimator.stepAnimationLocked(animator.mCurrentTime);
2131 winAnimator.mWasAnimating = nowAnimating;
2132 animator.orAnimating(nowAnimating);
2133
2134 if (DEBUG_WALLPAPER) Slog.v(TAG,
2135 win + ": wasAnimating=" + wasAnimating + ", nowAnimating=" + nowAnimating);
2136
2137 if (wasAnimating && !winAnimator.mAnimating
2138 && wallpaperController.isWallpaperTarget(win)) {
2139 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2140 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
2141 if (DEBUG_LAYOUT_REPEATS) {
2142 mService.mWindowPlacerLocked.debugLayoutRepeats(
2143 "updateWindowsAndWallpaperLocked 2", pendingLayoutChanges);
2144 }
2145 }
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002146 }
2147
2148 final AppWindowToken atoken = win.mAppToken;
2149 if (winAnimator.mDrawState == READY_TO_SHOW) {
2150 if (atoken == null || atoken.allDrawn) {
2151 if (win.performShowLocked()) {
2152 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
2153 if (DEBUG_LAYOUT_REPEATS) {
2154 mService.mWindowPlacerLocked.debugLayoutRepeats(
2155 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
2156 }
2157 }
2158 }
2159 }
2160 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
2161 if (appAnimator != null && appAnimator.thumbnail != null) {
2162 if (appAnimator.thumbnailTransactionSeq != animator.mAnimTransactionSequence) {
2163 appAnimator.thumbnailTransactionSeq = animator.mAnimTransactionSequence;
2164 appAnimator.thumbnailLayer = 0;
2165 }
2166 if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
2167 appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
2168 }
2169 }
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002170 } // end forall windows
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002171 }
2172
2173 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002174 resetAnimationBackgroundAnimator();
2175
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002176 final WindowList windows = mWindows;
2177 WindowState detachedWallpaper = null;
2178
2179 for (int i = windows.size() - 1; i >= 0; i--) {
2180 final WindowState win = windows.get(i);
2181 final WindowStateAnimator winAnimator = win.mWinAnimator;
2182 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
2183 continue;
2184 }
2185
2186 final int flags = win.mAttrs.flags;
2187
2188 // If this window is animating, make a note that we have an animating window and take
2189 // care of a request to run a detached wallpaper animation.
2190 if (winAnimator.mAnimating) {
2191 if (winAnimator.mAnimation != null) {
2192 if ((flags & FLAG_SHOW_WALLPAPER) != 0
2193 && winAnimator.mAnimation.getDetachWallpaper()) {
2194 detachedWallpaper = win;
2195 }
2196 final int color = winAnimator.mAnimation.getBackgroundColor();
2197 if (color != 0) {
2198 final TaskStack stack = win.getStack();
2199 if (stack != null) {
2200 stack.setAnimationBackground(winAnimator, color);
2201 }
2202 }
2203 }
2204 animator.setAnimating(true);
2205 }
2206
2207 // If this window's app token is running a detached wallpaper animation, make a note so
2208 // we can ensure the wallpaper is displayed behind it.
2209 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
2210 if (appAnimator != null && appAnimator.animation != null
2211 && appAnimator.animating) {
2212 if ((flags & FLAG_SHOW_WALLPAPER) != 0
2213 && appAnimator.animation.getDetachWallpaper()) {
2214 detachedWallpaper = win;
2215 }
2216
2217 final int color = appAnimator.animation.getBackgroundColor();
2218 if (color != 0) {
2219 final TaskStack stack = win.getStack();
2220 if (stack != null) {
2221 stack.setAnimationBackground(winAnimator, color);
2222 }
2223 }
2224 }
2225 } // end forall windows
2226
2227 if (animator.mWindowDetachedWallpaper != detachedWallpaper) {
2228 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
2229 + animator.mWindowDetachedWallpaper + " to " + detachedWallpaper);
2230 animator.mWindowDetachedWallpaper = detachedWallpaper;
2231 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2232 }
2233 }
2234
2235 void prepareWindowSurfaces() {
2236 final int count = mWindows.size();
2237 for (int j = 0; j < count; j++) {
2238 mWindows.get(j).mWinAnimator.prepareSurfaceLocked(true);
2239 }
2240 }
2241
Wale Ogunwale494009b82016-10-21 09:01:38 -07002242 boolean inputMethodClientHasFocus(IInputMethodClient client) {
2243 // The focus for the client is the window immediately below where we would place the input
2244 // method window.
2245 int idx = findDesiredInputMethodWindowIndex(false);
2246 if (idx <= 0) {
2247 return false;
2248 }
2249
2250 WindowState imFocus = mWindows.get(idx - 1);
2251 if (DEBUG_INPUT_METHOD) {
2252 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2253 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2254 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
2255 }
2256
2257 if (imFocus == null) {
2258 return false;
2259 }
2260
2261 // This may be a starting window, in which case we still want to count it as okay.
2262 if (imFocus.mAttrs.type == TYPE_APPLICATION_STARTING && imFocus.mAppToken != null) {
2263 // The client has definitely started, so it really should have a window in this app
2264 // token. Let's look for it.
2265 final WindowState w = imFocus.mAppToken.getFirstNonStartingWindow();
2266 if (w != null) {
2267 if (DEBUG_INPUT_METHOD) Slog.i(TAG_WM, "Switching to real app window: " + w);
2268 imFocus = w;
2269 }
2270 }
2271
2272 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2273
2274 if (DEBUG_INPUT_METHOD) {
2275 Slog.i(TAG_WM, "IM target client: " + imeClient);
2276 if (imeClient != null) {
2277 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2278 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2279 }
2280 }
2281
2282 return imeClient != null && imeClient.asBinder() == client.asBinder();
2283 }
2284
2285 boolean hasSecureWindowOnScreen() {
2286 for (int i = mWindows.size() - 1; i >= 0; --i) {
2287 final WindowState ws = mWindows.get(i);
2288 if (ws.isOnScreen() && (ws.mAttrs.flags & FLAG_SECURE) != 0) {
2289 return true;
2290 }
2291 }
2292 return false;
2293 }
2294
2295 void updateSystemUiVisibility(int visibility, int globalDiff) {
2296 for (int i = mWindows.size() - 1; i >= 0; --i) {
2297 final WindowState ws = mWindows.get(i);
2298 try {
2299 int curValue = ws.mSystemUiVisibility;
2300 int diff = (curValue ^ visibility) & globalDiff;
2301 int newValue = (curValue & ~diff) | (visibility & diff);
2302 if (newValue != curValue) {
2303 ws.mSeq++;
2304 ws.mSystemUiVisibility = newValue;
2305 }
2306 if (newValue != curValue || ws.mAttrs.hasSystemUiListeners) {
2307 ws.mClient.dispatchSystemUiVisibilityChanged(ws.mSeq,
2308 visibility, newValue, diff);
2309 }
2310 } catch (RemoteException e) {
2311 // so sorry
2312 }
2313 }
2314 }
2315
2316 void onWindowFreezeTimeout() {
2317 Slog.w(TAG_WM, "Window freeze timeout expired.");
2318 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
2319 for (int i = mWindows.size() - 1; i >= 0; --i) {
2320 final WindowState w = mWindows.get(i);
2321 if (!w.mOrientationChanging) {
2322 continue;
2323 }
2324 w.mOrientationChanging = false;
2325 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2326 - mService.mDisplayFreezeTime);
2327 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
2328 }
2329 mService.mWindowPlacerLocked.performSurfacePlacement();
2330 }
2331
2332 void waitForAllWindowsDrawn() {
2333 final WindowManagerPolicy policy = mService.mPolicy;
2334 for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) {
2335 final WindowState win = mWindows.get(winNdx);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002336 final boolean keyguard = policy.isKeyguardHostWindow(win.mAttrs);
Jorim Jaggife762342016-10-13 14:33:27 +02002337 if (win.isVisibleLw() && (win.mAppToken != null || keyguard)) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002338 win.mWinAnimator.mDrawState = DRAW_PENDING;
2339 // Force add to mResizingWindows.
2340 win.mLastContentInsets.set(-1, -1, -1, -1);
2341 mService.mWaitingForDrawn.add(win);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002342 }
2343 }
2344 }
2345
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002346 ReadOnlyWindowList getReadOnlyWindowList() {
2347 return mWindows.getReadOnly();
2348 }
2349
2350 void getWindows(WindowList output) {
2351 output.addAll(mWindows);
2352 }
2353
2354 // TODO: Super crazy long method that should be broken down...
2355 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2356
2357 boolean focusDisplayed = false;
2358 boolean displayHasContent = false;
2359 float preferredRefreshRate = 0;
2360 int preferredModeId = 0;
2361
2362
2363 final int dw = mDisplayInfo.logicalWidth;
2364 final int dh = mDisplayInfo.logicalHeight;
2365 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2366
2367 mTmpUpdateAllDrawn.clear();
2368
2369 int repeats = 0;
2370 do {
2371 repeats++;
2372 if (repeats > 6) {
2373 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2374 clearLayoutNeeded();
2375 break;
2376 }
2377
2378 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2379 pendingLayoutChanges);
2380
2381 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
2382 adjustWallpaperWindows();
2383 }
2384
2385 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2386 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2387 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2388 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002389 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002390 }
2391 }
2392
2393 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2394 setLayoutNeeded();
2395 }
2396
2397 // FIRST LOOP: Perform a layout, if needed.
2398 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2399 performLayout(repeats == 1, false /* updateInputWindows */);
2400 } else {
2401 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2402 }
2403
2404 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2405 pendingLayoutChanges = 0;
2406
2407 if (isDefaultDisplay) {
2408 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
2409 for (int i = mWindows.size() - 1; i >= 0; i--) {
2410 final WindowState w = mWindows.get(i);
Jorim Jaggife762342016-10-13 14:33:27 +02002411 mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
2412 mService.mInputMethodTarget);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002413 }
2414 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2415 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2416 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2417 }
2418 } while (pendingLayoutChanges != 0);
2419
2420 RootWindowContainer root = mService.mRoot;
2421 boolean obscured = false;
2422 boolean syswin = false;
2423 resetDimming();
2424
2425 // Only used if default window
2426 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
2427
2428 for (int i = mWindows.size() - 1; i >= 0; i--) {
2429 final WindowState w = mWindows.get(i);
2430 final Task task = w.getTask();
2431 final boolean obscuredChanged = w.mObscured != obscured;
2432
2433 // Update effect.
2434 w.mObscured = obscured;
2435 if (!obscured) {
2436 final boolean isDisplayed = w.isDisplayedLw();
2437
2438 if (isDisplayed && w.isObscuringFullscreen(mDisplayInfo)) {
2439 // This window completely covers everything behind it, so we want to leave all
2440 // of them as undimmed (for performance reasons).
2441 root.mObscuringWindow = w;
2442 obscured = true;
2443 }
2444
2445 displayHasContent |= root.handleNotObscuredLocked(w, obscured, syswin);
2446
2447 if (w.mHasSurface && isDisplayed) {
2448 final int type = w.mAttrs.type;
2449 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
2450 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
2451 syswin = true;
2452 }
2453 if (preferredRefreshRate == 0 && w.mAttrs.preferredRefreshRate != 0) {
2454 preferredRefreshRate = w.mAttrs.preferredRefreshRate;
2455 }
2456 if (preferredModeId == 0 && w.mAttrs.preferredDisplayModeId != 0) {
2457 preferredModeId = w.mAttrs.preferredDisplayModeId;
2458 }
2459 }
2460 }
2461
2462 w.applyDimLayerIfNeeded();
2463
2464 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
2465 && mWallpaperController.isWallpaperTarget(w)) {
2466 // This is the wallpaper target and its obscured state changed... make sure the
2467 // current wallpaper's visibility has been updated accordingly.
2468 mWallpaperController.updateWallpaperVisibility();
2469 }
2470
2471 w.handleWindowMovedIfNeeded();
2472
2473 final WindowStateAnimator winAnimator = w.mWinAnimator;
2474
2475 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
2476 w.mContentChanged = false;
2477
2478 // Moved from updateWindowsAndWallpaperLocked().
2479 if (w.mHasSurface) {
2480 // Take care of the window being ready to display.
2481 final boolean committed = winAnimator.commitFinishDrawingLocked();
2482 if (isDefaultDisplay && committed) {
2483 if (w.mAttrs.type == TYPE_DREAM) {
2484 // HACK: When a dream is shown, it may at that point hide the lock screen.
2485 // So we need to redo the layout to let the phone window manager make this
2486 // happen.
2487 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
2488 if (DEBUG_LAYOUT_REPEATS) {
2489 surfacePlacer.debugLayoutRepeats(
2490 "dream and commitFinishDrawingLocked true",
2491 pendingLayoutChanges);
2492 }
2493 }
2494 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
2495 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
2496 "First draw done in potential wallpaper target " + w);
2497 root.mWallpaperMayChange = true;
2498 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
2499 if (DEBUG_LAYOUT_REPEATS) {
2500 surfacePlacer.debugLayoutRepeats(
2501 "wallpaper and commitFinishDrawingLocked true",
2502 pendingLayoutChanges);
2503 }
2504 }
2505 }
2506 if (!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening()) {
2507 // Updates the shown frame before we set up the surface. This is needed
2508 // because the resizing could change the top-left position (in addition to
2509 // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to
2510 // position the surface.
2511 //
2512 // If an animation is being started, we can't call this method because the
2513 // animation hasn't processed its initial transformation yet, but in general
2514 // we do want to update the position if the window is animating.
2515 winAnimator.computeShownFrameLocked();
2516 }
2517 winAnimator.setSurfaceBoundariesLocked(recoveringMemory);
2518 }
2519
2520 final AppWindowToken atoken = w.mAppToken;
2521 if (atoken != null) {
2522 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
2523 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
2524 mTmpUpdateAllDrawn.add(atoken);
2525 }
2526 }
2527
2528 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
2529 && w.isDisplayedLw()) {
2530 focusDisplayed = true;
2531 }
2532
2533 w.updateResizingWindowIfNeeded();
2534 }
2535
2536 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
2537 displayHasContent,
2538 preferredRefreshRate,
2539 preferredModeId,
2540 true /* inTraversal, must call performTraversalInTrans... below */);
2541
2542 stopDimmingIfNeeded();
2543
2544 while (!mTmpUpdateAllDrawn.isEmpty()) {
2545 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2546 // See if any windows have been drawn, so they (and others associated with them)
2547 // can now be shown.
2548 atoken.updateAllDrawn(this);
2549 }
2550
2551 return focusDisplayed;
2552 }
2553
2554 void performLayout(boolean initial, boolean updateInputWindows) {
2555 if (!isLayoutNeeded()) {
2556 return;
2557 }
2558 clearLayoutNeeded();
2559
2560 final int dw = mDisplayInfo.logicalWidth;
2561 final int dh = mDisplayInfo.logicalHeight;
2562
2563 int i;
2564
2565 if (DEBUG_LAYOUT) {
2566 Slog.v(TAG, "-------------------------------------");
2567 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2568 }
2569
2570 mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mService.mRotation,
2571 getConfiguration().uiMode);
2572 if (isDefaultDisplay) {
2573 // Not needed on non-default displays.
2574 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2575 mService.mScreenRect.set(0, 0, dw, dh);
2576 }
2577
2578 mService.mPolicy.getContentRectLw(mContentRect);
2579
2580 int seq = mService.mLayoutSeq + 1;
2581 if (seq < 0) seq = 0;
2582 mService.mLayoutSeq = seq;
2583
2584 boolean behindDream = false;
2585
2586 // First perform layout of any root windows (not attached to another window).
2587 int topAttached = -1;
2588 for (i = mWindows.size() - 1; i >= 0; i--) {
2589 final WindowState win = mWindows.get(i);
2590
2591 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
2592 // wasting time and funky changes while a window is animating away.
Jorim Jaggife762342016-10-13 14:33:27 +02002593 final boolean gone = (behindDream && mService.mPolicy.canBeHiddenByKeyguardLw(win))
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002594 || win.isGoneForLayoutLw();
2595
2596 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
2597 Slog.v(TAG, "1ST PASS " + win + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
2598 + " mLayoutAttached=" + win.mLayoutAttached
2599 + " screen changed=" + win.isConfigChanged());
2600 final AppWindowToken atoken = win.mAppToken;
2601 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + win.mViewVisibility
2602 + " mRelayoutCalled=" + win.mRelayoutCalled + " hidden=" + win.mToken.hidden
2603 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
2604 + " parentHidden=" + win.isParentWindowHidden());
2605 else Slog.v(TAG, " VIS: mViewVisibility=" + win.mViewVisibility
2606 + " mRelayoutCalled=" + win.mRelayoutCalled + " hidden=" + win.mToken.hidden
2607 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
2608 + " parentHidden=" + win.isParentWindowHidden());
2609 }
2610
2611 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
2612 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
2613 // since that means "perform layout as normal, just don't display").
2614 if (!gone || !win.mHaveFrame || win.mLayoutNeeded
2615 || ((win.isConfigChanged() || win.setReportResizeHints())
2616 && !win.isGoneForLayoutLw() &&
2617 ((win.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
2618 (win.mHasSurface && win.mAppToken != null &&
2619 win.mAppToken.layoutConfigChanges)))) {
2620 if (!win.mLayoutAttached) {
2621 if (initial) {
2622 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
2623 win.mContentChanged = false;
2624 }
2625 if (win.mAttrs.type == TYPE_DREAM) {
2626 // Don't layout windows behind a dream, so that if it does stuff like hide
2627 // the status bar we won't get a bad transition when it goes away.
2628 behindDream = true;
2629 }
2630 win.mLayoutNeeded = false;
2631 win.prelayout();
2632 mService.mPolicy.layoutWindowLw(win, null);
2633 win.mLayoutSeq = seq;
2634
2635 // Window frames may have changed. Update dim layer with the new bounds.
2636 final Task task = win.getTask();
2637 if (task != null) {
2638 mDimLayerController.updateDimLayer(task);
2639 }
2640
2641 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + win.mFrame
2642 + " mContainingFrame=" + win.mContainingFrame
2643 + " mDisplayFrame=" + win.mDisplayFrame);
2644 } else {
2645 if (topAttached < 0) topAttached = i;
2646 }
2647 }
2648 }
2649
2650 boolean attachedBehindDream = false;
2651
2652 // Now perform layout of attached windows, which usually depend on the position of the
2653 // window they are attached to. XXX does not deal with windows that are attached to windows
2654 // that are themselves attached.
2655 for (i = topAttached; i >= 0; i--) {
2656 final WindowState win = mWindows.get(i);
2657
2658 if (win.mLayoutAttached) {
2659 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + win + " mHaveFrame=" + win.mHaveFrame
2660 + " mViewVisibility=" + win.mViewVisibility
2661 + " mRelayoutCalled=" + win.mRelayoutCalled);
2662 // If this view is GONE, then skip it -- keep the current frame, and let the caller
2663 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
2664 // windows, since that means "perform layout as normal, just don't display").
Jorim Jaggife762342016-10-13 14:33:27 +02002665 if (attachedBehindDream && mService.mPolicy.canBeHiddenByKeyguardLw(win)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002666 continue;
2667 }
2668 if ((win.mViewVisibility != GONE && win.mRelayoutCalled) || !win.mHaveFrame
2669 || win.mLayoutNeeded) {
2670 if (initial) {
2671 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
2672 win.mContentChanged = false;
2673 }
2674 win.mLayoutNeeded = false;
2675 win.prelayout();
2676 mService.mPolicy.layoutWindowLw(win, win.getParentWindow());
2677 win.mLayoutSeq = seq;
2678 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + win.mFrame
2679 + " mContainingFrame=" + win.mContainingFrame
2680 + " mDisplayFrame=" + win.mDisplayFrame);
2681 }
2682 } else if (win.mAttrs.type == TYPE_DREAM) {
2683 // Don't layout windows behind a dream, so that if it does stuff like hide the
2684 // status bar we won't get a bad transition when it goes away.
2685 attachedBehindDream = behindDream;
2686 }
2687 }
2688
2689 // Window frames may have changed. Tell the input dispatcher about it.
2690 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2691 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2692 if (updateInputWindows) {
2693 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2694 }
2695
2696 mService.mPolicy.finishLayoutLw();
2697 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2698 }
2699
2700 /**
2701 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2702 * In portrait mode, it grabs the full screenshot.
2703 *
2704 * @param width the width of the target bitmap
2705 * @param height the height of the target bitmap
2706 * @param includeFullDisplay true if the screen should not be cropped before capture
2707 * @param frameScale the scale to apply to the frame, only used when width = -1 and height = -1
2708 * @param config of the output bitmap
2709 * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
2710 */
2711 Bitmap screenshotApplications(IBinder appToken, int displayId, int width, int height,
2712 boolean includeFullDisplay, float frameScale, Bitmap.Config config,
2713 boolean wallpaperOnly) {
2714 int dw = mDisplayInfo.logicalWidth;
2715 int dh = mDisplayInfo.logicalHeight;
2716 if (dw == 0 || dh == 0) {
2717 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
2718 + ": returning null. logical widthxheight=" + dw + "x" + dh);
2719 return null;
2720 }
2721
2722 Bitmap bm = null;
2723
2724 int maxLayer = 0;
2725 final Rect frame = new Rect();
2726 final Rect stackBounds = new Rect();
2727
2728 boolean screenshotReady;
2729 int minLayer;
2730 if (appToken == null && !wallpaperOnly) {
2731 screenshotReady = true;
2732 minLayer = 0;
2733 } else {
2734 screenshotReady = false;
2735 minLayer = Integer.MAX_VALUE;
2736 }
2737
2738 WindowState appWin = null;
2739
2740 boolean includeImeInScreenshot;
2741 synchronized(mService.mWindowMap) {
2742 final AppWindowToken imeTargetAppToken = mService.mInputMethodTarget != null
2743 ? mService.mInputMethodTarget.mAppToken : null;
2744 // We only include the Ime in the screenshot if the app we are screenshoting is the IME
2745 // target and isn't in multi-window mode. We don't screenshot the IME in multi-window
2746 // mode because the frame of the IME might not overlap with that of the app.
2747 // E.g. IME target app at the top in split-screen mode and the IME at the bottom
2748 // overlapping with the bottom app.
2749 includeImeInScreenshot = imeTargetAppToken != null
2750 && imeTargetAppToken.appToken != null
2751 && imeTargetAppToken.appToken.asBinder() == appToken
2752 && !mService.mInputMethodTarget.isInMultiWindowMode();
2753 }
2754
2755 final int aboveAppLayer = (mService.mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) + 1)
2756 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
2757
2758 synchronized(mService.mWindowMap) {
2759 // Figure out the part of the screen that is actually the app.
2760 appWin = null;
2761 for (int i = mWindows.size() - 1; i >= 0; i--) {
2762 final WindowState ws = mWindows.get(i);
2763 if (!ws.mHasSurface) {
2764 continue;
2765 }
2766 if (ws.mLayer >= aboveAppLayer) {
2767 continue;
2768 }
2769 if (wallpaperOnly && !ws.mIsWallpaper) {
2770 continue;
2771 }
2772 if (ws.mIsImWindow) {
2773 if (!includeImeInScreenshot) {
2774 continue;
2775 }
2776 } else if (ws.mIsWallpaper) {
2777 // If this is the wallpaper layer and we're only looking for the wallpaper layer
2778 // then the target window state is this one.
2779 if (wallpaperOnly) {
2780 appWin = ws;
2781 }
2782
2783 if (appWin == null) {
2784 // We have not ran across the target window yet, so it is probably behind
2785 // the wallpaper. This can happen when the keyguard is up and all windows
2786 // are moved behind the wallpaper. We don't want to include the wallpaper
2787 // layer in the screenshot as it will cover-up the layer of the target
2788 // window.
2789 continue;
2790 }
2791 // Fall through. The target window is in front of the wallpaper. For this
2792 // case we want to include the wallpaper layer in the screenshot because
2793 // the target window might have some transparent areas.
2794 } else if (appToken != null) {
2795 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
2796 // This app window is of no interest if it is not associated with the
2797 // screenshot app.
2798 continue;
2799 }
2800 appWin = ws;
2801 }
2802
2803 // Include this window.
2804
2805 final WindowStateAnimator winAnim = ws.mWinAnimator;
2806 int layer = winAnim.mSurfaceController.getLayer();
2807 if (maxLayer < layer) {
2808 maxLayer = layer;
2809 }
2810 if (minLayer > layer) {
2811 minLayer = layer;
2812 }
2813
2814 // Don't include wallpaper in bounds calculation
2815 if (!includeFullDisplay && !ws.mIsWallpaper) {
2816 final Rect wf = ws.mFrame;
2817 final Rect cr = ws.mContentInsets;
2818 int left = wf.left + cr.left;
2819 int top = wf.top + cr.top;
2820 int right = wf.right - cr.right;
2821 int bottom = wf.bottom - cr.bottom;
2822 frame.union(left, top, right, bottom);
2823 ws.getVisibleBounds(stackBounds);
2824 if (!Rect.intersects(frame, stackBounds)) {
2825 // Set frame empty if there's no intersection.
2826 frame.setEmpty();
2827 }
2828 }
2829
2830 final boolean foundTargetWs =
2831 (ws.mAppToken != null && ws.mAppToken.token == appToken)
2832 || (appWin != null && wallpaperOnly);
2833 if (foundTargetWs && ws.isDisplayedLw() && winAnim.getShown()) {
2834 screenshotReady = true;
2835 }
2836
2837 if (ws.isObscuringFullscreen(mDisplayInfo)){
2838 break;
2839 }
2840 }
2841
2842 if (appToken != null && appWin == null) {
2843 // Can't find a window to snapshot.
2844 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM,
2845 "Screenshot: Couldn't find a surface matching " + appToken);
2846 return null;
2847 }
2848
2849 if (!screenshotReady) {
2850 Slog.i(TAG_WM, "Failed to capture screenshot of " + appToken +
2851 " appWin=" + (appWin == null ? "null" : (appWin + " drawState=" +
2852 appWin.mWinAnimator.mDrawState)));
2853 return null;
2854 }
2855
2856 // Screenshot is ready to be taken. Everything from here below will continue
2857 // through the bottom of the loop and return a value. We only stay in the loop
2858 // because we don't want to release the mWindowMap lock until the screenshot is
2859 // taken.
2860
2861 if (maxLayer == 0) {
2862 if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken
2863 + ": returning null maxLayer=" + maxLayer);
2864 return null;
2865 }
2866
2867 if (!includeFullDisplay) {
2868 // Constrain frame to the screen size.
2869 if (!frame.intersect(0, 0, dw, dh)) {
2870 frame.setEmpty();
2871 }
2872 } else {
2873 // Caller just wants entire display.
2874 frame.set(0, 0, dw, dh);
2875 }
2876 if (frame.isEmpty()) {
2877 return null;
2878 }
2879
2880 if (width < 0) {
2881 width = (int) (frame.width() * frameScale);
2882 }
2883 if (height < 0) {
2884 height = (int) (frame.height() * frameScale);
2885 }
2886
2887 // Tell surface flinger what part of the image to crop. Take the top
2888 // right part of the application, and crop the larger dimension to fit.
2889 Rect crop = new Rect(frame);
2890 if (width / (float) frame.width() < height / (float) frame.height()) {
2891 int cropWidth = (int)((float)width / (float)height * frame.height());
2892 crop.right = crop.left + cropWidth;
2893 } else {
2894 int cropHeight = (int)((float)height / (float)width * frame.width());
2895 crop.bottom = crop.top + cropHeight;
2896 }
2897
2898 // The screenshot API does not apply the current screen rotation.
2899 int rot = mDisplay.getRotation();
2900
2901 if (rot == ROTATION_90 || rot == ROTATION_270) {
2902 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
2903 }
2904
2905 // Surfaceflinger is not aware of orientation, so convert our logical
2906 // crop to surfaceflinger's portrait orientation.
2907 convertCropForSurfaceFlinger(crop, rot, dw, dh);
2908
2909 if (DEBUG_SCREENSHOT) {
2910 Slog.i(TAG_WM, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to "
2911 + maxLayer + " appToken=" + appToken);
2912 for (int i = 0; i < mWindows.size(); i++) {
2913 final WindowState win = mWindows.get(i);
2914 final WindowSurfaceController controller = win.mWinAnimator.mSurfaceController;
2915 Slog.i(TAG_WM, win + ": " + win.mLayer
2916 + " animLayer=" + win.mWinAnimator.mAnimLayer
2917 + " surfaceLayer=" + ((controller == null)
2918 ? "null" : controller.getLayer()));
2919 }
2920 }
2921
2922 final ScreenRotationAnimation screenRotationAnimation =
2923 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
2924 final boolean inRotation = screenRotationAnimation != null &&
2925 screenRotationAnimation.isAnimating();
2926 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM,
2927 "Taking screenshot while rotating");
2928
2929 // We force pending transactions to flush before taking
2930 // the screenshot by pushing an empty synchronous transaction.
2931 SurfaceControl.openTransaction();
2932 SurfaceControl.closeTransactionSync();
2933
2934 bm = SurfaceControl.screenshot(crop, width, height, minLayer, maxLayer,
2935 inRotation, rot);
2936 if (bm == null) {
2937 Slog.w(TAG_WM, "Screenshot failure taking screenshot for (" + dw + "x" + dh
2938 + ") to layer " + maxLayer);
2939 return null;
2940 }
2941 }
2942
2943 if (DEBUG_SCREENSHOT) {
2944 // TEST IF IT's ALL BLACK
2945 int[] buffer = new int[bm.getWidth() * bm.getHeight()];
2946 bm.getPixels(buffer, 0, bm.getWidth(), 0, 0, bm.getWidth(), bm.getHeight());
2947 boolean allBlack = true;
2948 final int firstColor = buffer[0];
2949 for (int i = 0; i < buffer.length; i++) {
2950 if (buffer[i] != firstColor) {
2951 allBlack = false;
2952 break;
2953 }
2954 }
2955 if (allBlack) {
2956 Slog.i(TAG_WM, "Screenshot " + appWin + " was monochrome(" +
2957 Integer.toHexString(firstColor) + ")! mSurfaceLayer=" +
2958 (appWin != null ?
2959 appWin.mWinAnimator.mSurfaceController.getLayer() : "null") +
2960 " minLayer=" + minLayer + " maxLayer=" + maxLayer);
2961 }
2962 }
2963
2964 // Create a copy of the screenshot that is immutable and backed in ashmem.
2965 // This greatly reduces the overhead of passing the bitmap between processes.
2966 Bitmap ret = bm.createAshmemBitmap(config);
2967 bm.recycle();
2968 return ret;
2969 }
2970
2971 // TODO: Can this use createRotationMatrix()?
2972 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
2973 if (rot == Surface.ROTATION_90) {
2974 final int tmp = crop.top;
2975 crop.top = dw - crop.right;
2976 crop.right = crop.bottom;
2977 crop.bottom = dw - crop.left;
2978 crop.left = tmp;
2979 } else if (rot == Surface.ROTATION_180) {
2980 int tmp = crop.top;
2981 crop.top = dh - crop.bottom;
2982 crop.bottom = dh - tmp;
2983 tmp = crop.right;
2984 crop.right = dw - crop.left;
2985 crop.left = dw - tmp;
2986 } else if (rot == Surface.ROTATION_270) {
2987 final int tmp = crop.top;
2988 crop.top = crop.left;
2989 crop.left = dh - crop.bottom;
2990 crop.bottom = crop.right;
2991 crop.right = dh - tmp;
2992 }
2993 }
2994
2995 void onSeamlessRotationTimeout() {
2996 boolean layoutNeeded = false;
2997 for (int i = mWindows.size() - 1; i >= 0; i--) {
2998 final WindowState w = mWindows.get(i);
2999 if (!w.mSeamlesslyRotated) {
3000 continue;
3001 }
3002 layoutNeeded = true;
3003 w.setDisplayLayoutNeeded();
3004 mService.markForSeamlessRotation(w, false);
3005 }
3006
3007 if (layoutNeeded) {
3008 mService.mWindowPlacerLocked.performSurfacePlacement();
3009 }
3010 }
3011
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003012 static final class GetWindowOnDisplaySearchResult {
Wale Ogunwaleec731152016-09-08 20:18:57 -07003013 boolean reachedToken;
3014 WindowState foundWindow;
3015
3016 void reset() {
3017 reachedToken = false;
3018 foundWindow = null;
3019 }
3020 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003021
3022 static final class TaskForResizePointSearchResult {
3023 boolean searchDone;
3024 Task taskForResize;
3025
3026 void reset() {
3027 searchDone = false;
3028 taskForResize = null;
3029 }
3030 }
Robert Carr3b716242016-08-16 16:02:21 -07003031
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003032 /**
3033 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3034 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3035 * homogeneous children type which is currently required by sub-classes of
3036 * {@link WindowContainer} class.
3037 */
3038 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3039
3040 int size() {
3041 return mChildren.size();
3042 }
3043
3044 E get(int index) {
3045 return mChildren.get(index);
3046 }
3047
3048 @Override
3049 boolean fillsParent() {
3050 return true;
3051 }
3052
3053 @Override
3054 boolean isVisible() {
3055 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003056 }
3057 }
3058
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003059 /**
3060 * Window container class that contains all containers on this display relating to Apps.
3061 * I.e Activities.
3062 */
3063 private class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
3064
3065 void attachStack(TaskStack stack, boolean onTop) {
3066 if (stack.mStackId == HOME_STACK_ID) {
3067 if (mHomeStack != null) {
3068 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
3069 }
3070 mHomeStack = stack;
3071 }
3072 addChild(stack, onTop);
3073 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003074 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003075
3076 void moveStack(TaskStack stack, boolean toTop) {
3077 if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
3078 // This stack is always-on-top silly...
3079 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
3080 return;
3081 }
3082
3083 if (!mChildren.contains(stack)) {
3084 Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
3085 }
3086 removeChild(stack);
3087 addChild(stack, toTop);
3088 }
3089
3090 private void addChild(TaskStack stack, boolean toTop) {
3091 int addIndex = toTop ? mChildren.size() : 0;
3092
3093 if (toTop
3094 && mService.isStackVisibleLocked(PINNED_STACK_ID)
3095 && stack.mStackId != PINNED_STACK_ID) {
3096 // The pinned stack is always the top most stack (always-on-top) when it is visible.
3097 // So, stack is moved just below the pinned stack.
3098 addIndex--;
3099 TaskStack topStack = mChildren.get(addIndex);
3100 if (topStack.mStackId != PINNED_STACK_ID) {
3101 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3102 }
3103 }
3104 addChild(stack, addIndex);
3105 setLayoutNeeded();
3106 }
3107
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003108 @Override
3109 int getOrientation() {
3110 if (mService.isStackVisibleLocked(DOCKED_STACK_ID)
3111 || mService.isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID)) {
3112 // Apps and their containers are not allowed to specify an orientation while the
3113 // docked or freeform stack is visible...except for the home stack/task if the
3114 // docked stack is minimized and it actually set something.
3115 if (mHomeStack != null && mHomeStack.isVisible()
3116 && mDividerControllerLocked.isMinimizedDock()) {
3117 final int orientation = mHomeStack.getOrientation();
3118 if (orientation != SCREEN_ORIENTATION_UNSET) {
3119 return orientation;
3120 }
3121 }
3122 return SCREEN_ORIENTATION_UNSPECIFIED;
3123 }
3124
3125 final int orientation = super.getOrientation();
3126 if (orientation != SCREEN_ORIENTATION_UNSET
3127 && orientation != SCREEN_ORIENTATION_BEHIND) {
3128 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3129 "App is requesting an orientation, return " + orientation);
3130 return orientation;
3131 }
3132
3133 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3134 "No app is requesting an orientation, return " + mService.mLastOrientation);
3135 // The next app has not been requested to be visible, so we keep the current orientation
3136 // to prevent freezing/unfreezing the display too early.
3137 return mService.mLastOrientation;
3138 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003139 }
3140
3141 /**
3142 * Window container class that contains all containers on this display that are not related to
3143 * Apps. E.g. status bar.
3144 */
3145 private static class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
3146
Robert Carr3b716242016-08-16 16:02:21 -07003147 }
Craig Mautner59c00972012-07-30 12:10:24 -07003148}