Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
| 22 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Wale Ogunwale | a77e146 | 2016-09-28 10:09:46 -0700 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 24 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
| 25 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 26 | import static android.view.Display.DEFAULT_DISPLAY; |
| 27 | import static android.view.Display.FLAG_PRIVATE; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 28 | import static android.view.Surface.ROTATION_0; |
| 29 | import static android.view.Surface.ROTATION_180; |
| 30 | import static android.view.Surface.ROTATION_270; |
| 31 | import static android.view.Surface.ROTATION_90; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 32 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 33 | import static android.view.WindowManager.DOCKED_INVALID; |
| 34 | import static android.view.WindowManager.DOCKED_TOP; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 36 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 37 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 38 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 39 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 40 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 41 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 42 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
| 43 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 44 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 45 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS; |
| 46 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 47 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 48 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 49 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 50 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 51 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 52 | import static com.android.server.wm.WindowManagerService.dipToPixel; |
| 53 | import static com.android.server.wm.WindowManagerService.localLOGV; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 54 | import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 55 | |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 56 | import android.annotation.NonNull; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 57 | import android.app.ActivityManager.StackId; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 58 | import android.content.res.Configuration; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 59 | import android.graphics.Matrix; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 60 | import android.graphics.Rect; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 61 | import android.graphics.RectF; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 62 | import android.graphics.Region; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 63 | import android.graphics.Region.Op; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 64 | import android.hardware.display.DisplayManagerInternal; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 65 | import android.os.Debug; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 66 | import android.os.IBinder; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 67 | import android.util.DisplayMetrics; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 68 | import android.util.Slog; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 69 | import android.view.Display; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 70 | import android.view.DisplayInfo; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 71 | import android.view.IWindow; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 72 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 73 | import com.android.internal.util.FastPrintWriter; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 74 | |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 75 | import java.io.FileDescriptor; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 76 | import java.io.PrintWriter; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 77 | import java.io.StringWriter; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 78 | import java.util.ArrayList; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 79 | import java.util.Arrays; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 80 | import java.util.Comparator; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 81 | import java.util.HashMap; |
| 82 | import java.util.Iterator; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 83 | import java.util.List; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 84 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 85 | /** |
| 86 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 87 | * particular Display. |
| 88 | * |
| 89 | * IMPORTANT: No method from this class should ever be used without holding |
| 90 | * WindowManagerService.mWindowMap. |
| 91 | */ |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 92 | class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 93 | |
| 94 | /** Unique identifier of this stack. */ |
| 95 | private final int mDisplayId; |
| 96 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 97 | // The display only has 2 child window containers. mTaskStackContainers which contains all |
| 98 | // window containers that are related to apps (Activities) and mNonAppWindowContainers which |
| 99 | // contains all window containers not related to apps (e.g. Status bar). |
| 100 | private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(); |
| 101 | private final NonAppWindowContainers mNonAppWindowContainers = new NonAppWindowContainers(); |
| 102 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 103 | /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element |
| 104 | * from mDisplayWindows; */ |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 105 | private final WindowList mWindows = new WindowList(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 106 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 107 | // Mapping from a token IBinder to a WindowToken object on this display. |
| 108 | private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap(); |
| 109 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 110 | int mInitialDisplayWidth = 0; |
| 111 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 112 | int mInitialDisplayDensity = 0; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 113 | int mBaseDisplayWidth = 0; |
| 114 | int mBaseDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 115 | int mBaseDisplayDensity = 0; |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 116 | boolean mDisplayScalingDisabled; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 117 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 118 | private final Display mDisplay; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 119 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 120 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 121 | Rect mBaseDisplayRect = new Rect(); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 122 | private Rect mContentRect = new Rect(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 123 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 124 | // Accessed directly by all users. |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 125 | private boolean mLayoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 126 | int pendingLayoutChanges; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 127 | final boolean isDefaultDisplay; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 128 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 129 | /** Window tokens that are in the process of exiting, but still on screen for animations. */ |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 130 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 131 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 132 | /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack |
| 133 | * (except a future lockscreen TaskStack) moves to the top. */ |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 134 | private TaskStack mHomeStack = null; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 135 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 136 | /** Detect user tapping outside of current focused task bounds .*/ |
| 137 | TaskTapPointerEventListener mTapDetector; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 138 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 139 | /** Detect user tapping outside of current focused stack bounds .*/ |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 140 | private Region mTouchExcludeRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 141 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 142 | /** Save allocating when calculating rects */ |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 143 | private final Rect mTmpRect = new Rect(); |
| 144 | private final Rect mTmpRect2 = new Rect(); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 145 | private final RectF mTmpRectF = new RectF(); |
| 146 | private final Matrix mTmpMatrix = new Matrix(); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 147 | private final Region mTmpRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 148 | |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 149 | final WindowManagerService mService; |
| 150 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 151 | /** Remove this display when animation on it has completed. */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 152 | private boolean mDeferredRemoval; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 153 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 154 | final DockedStackDividerController mDividerControllerLocked; |
| 155 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 156 | final DimLayerController mDimLayerController; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 157 | |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 158 | final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>(); |
| 159 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 160 | /** Used when rebuilding window list to keep track of windows that have been removed. */ |
| 161 | private WindowState[] mRebuildTmp = new WindowState[20]; |
| 162 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 163 | private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult = |
| 164 | new TaskForResizePointSearchResult(); |
| 165 | private final GetWindowOnDisplaySearchResult mTmpGetWindowOnDisplaySearchResult = |
| 166 | new GetWindowOnDisplaySearchResult(); |
| 167 | |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame^] | 168 | // True if this display is in the process of being removed. Used to determine if the removal of |
| 169 | // the display's direct children should be allowed. |
| 170 | private boolean mRemovingDisplay = false; |
| 171 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 172 | /** |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 173 | * @param display May not be null. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 174 | * @param service You know. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 175 | */ |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 176 | DisplayContent(Display display, WindowManagerService service) { |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 177 | mDisplay = display; |
| 178 | mDisplayId = display.getDisplayId(); |
| 179 | display.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 180 | display.getMetrics(mDisplayMetrics); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 181 | isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY; |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 182 | mService = service; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 183 | initializeDisplayBaseInfo(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 184 | mDividerControllerLocked = new DockedStackDividerController(service, this); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 185 | mDimLayerController = new DimLayerController(this); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 186 | |
| 187 | // These are the only direct children we should ever have and they are permanent. |
| 188 | super.addChild(mTaskStackContainers, null); |
| 189 | super.addChild(mNonAppWindowContainers, null); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | int getDisplayId() { |
| 193 | return mDisplayId; |
| 194 | } |
| 195 | |
| 196 | WindowList getWindowList() { |
| 197 | return mWindows; |
| 198 | } |
| 199 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 200 | WindowToken getWindowToken(IBinder binder) { |
| 201 | return mTokenMap.get(binder); |
| 202 | } |
| 203 | |
| 204 | AppWindowToken getAppWindowToken(IBinder binder) { |
| 205 | final WindowToken token = getWindowToken(binder); |
| 206 | if (token == null) { |
| 207 | return null; |
| 208 | } |
| 209 | return token.asAppWindowToken(); |
| 210 | } |
| 211 | |
| 212 | void setWindowToken(IBinder binder, WindowToken token) { |
| 213 | final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token); |
| 214 | if (dc != null) { |
| 215 | // We currently don't support adding a window token to the display if the display |
| 216 | // already has the binder mapped to another token. If there is a use case for supporting |
| 217 | // this moving forward we will either need to merge the WindowTokens some how or have |
| 218 | // the binder map to a list of window tokens. |
| 219 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" + this |
| 220 | + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap); |
| 221 | } |
| 222 | mTokenMap.put(binder, token); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 223 | |
| 224 | if (token.asAppWindowToken() == null) { |
| 225 | // Add non-app token to container hierarchy on the display. App tokens are added through |
| 226 | // the parent container managing them (e.g. Tasks). |
| 227 | mNonAppWindowContainers.addChild(token, null); |
| 228 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | WindowToken removeWindowToken(IBinder binder) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 232 | final WindowToken token = mTokenMap.remove(binder); |
| 233 | if (token != null && token.asAppWindowToken() == null) { |
| 234 | mNonAppWindowContainers.removeChild(token); |
| 235 | } |
| 236 | return token; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 239 | Display getDisplay() { |
| 240 | return mDisplay; |
| 241 | } |
| 242 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 243 | DisplayInfo getDisplayInfo() { |
| 244 | return mDisplayInfo; |
| 245 | } |
| 246 | |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 247 | DisplayMetrics getDisplayMetrics() { |
| 248 | return mDisplayMetrics; |
| 249 | } |
| 250 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 251 | DockedStackDividerController getDockedDividerController() { |
| 252 | return mDividerControllerLocked; |
| 253 | } |
| 254 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 255 | /** |
| 256 | * Returns true if the specified UID has access to this display. |
| 257 | */ |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 258 | boolean hasAccess(int uid) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 259 | return mDisplay.hasAccess(uid); |
| 260 | } |
| 261 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 262 | boolean isPrivate() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 263 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 266 | TaskStack getHomeStack() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 267 | if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 268 | Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 269 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 270 | return mHomeStack; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 273 | TaskStack getStackById(int stackId) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 274 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 275 | final TaskStack stack = mTaskStackContainers.get(i); |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 276 | if (stack.mStackId == stackId) { |
| 277 | return stack; |
| 278 | } |
| 279 | } |
| 280 | return null; |
| 281 | } |
| 282 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 283 | @Override |
| 284 | void onConfigurationChanged(Configuration newParentConfig) { |
| 285 | super.onConfigurationChanged(newParentConfig); |
| 286 | |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 287 | // The display size information is heavily dependent on the resources in the current |
| 288 | // configuration, so we need to reconfigure it every time the configuration changes. |
| 289 | // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh... |
| 290 | mService.reconfigureDisplayLocked(this); |
| 291 | |
| 292 | getDockedDividerController().onConfigurationChanged(); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 293 | } |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 294 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 295 | /** |
| 296 | * Callback used to trigger bounds update after configuration change and get ids of stacks whose |
| 297 | * bounds were updated. |
| 298 | */ |
| 299 | void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 300 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 301 | final TaskStack stack = mTaskStackContainers.get(i); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 302 | if (stack.updateBoundsAfterConfigChange()) { |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 303 | changedStackList.add(stack.mStackId); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 308 | void checkAppWindowsReadyToShow() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 309 | super.checkAppWindowsReadyToShow(mDisplayId); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 312 | void stepAppWindowsAnimation(long currentTime) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 313 | super.stepAppWindowsAnimation(currentTime, mDisplayId); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 316 | @Override |
| 317 | boolean fillsParent() { |
| 318 | return true; |
| 319 | } |
| 320 | |
| 321 | @Override |
| 322 | boolean isVisible() { |
| 323 | return true; |
| 324 | } |
| 325 | |
| 326 | @Override |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 327 | void onAppTransitionDone() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 328 | super.onAppTransitionDone(); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 329 | rebuildAppWindowList(); |
| 330 | } |
| 331 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 332 | @Override |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 333 | int getOrientation() { |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 334 | if (mService.isStackVisibleLocked(DOCKED_STACK_ID) |
| 335 | || mService.isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID)) { |
| 336 | // Apps and their containers are not allowed to specify an orientation while the docked |
| 337 | // or freeform stack is visible...except for the home stack/task if the docked stack is |
| 338 | // minimized and it actually set something. |
Andrii Kulian | 8072d11 | 2016-09-16 11:11:01 -0700 | [diff] [blame] | 339 | if (mHomeStack != null && mHomeStack.isVisible() |
| 340 | && mDividerControllerLocked.isMinimizedDock()) { |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 341 | final int orientation = mHomeStack.getOrientation(); |
| 342 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 343 | return orientation; |
| 344 | } |
| 345 | } |
| 346 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 347 | } |
| 348 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 349 | final int orientation = super.getOrientation(); |
Wale Ogunwale | a77e146 | 2016-09-28 10:09:46 -0700 | [diff] [blame] | 350 | if (orientation != SCREEN_ORIENTATION_UNSET && orientation != SCREEN_ORIENTATION_BEHIND) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 351 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 352 | "App is requesting an orientation, return " + orientation); |
| 353 | return orientation; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 357 | "No app is requesting an orientation, return " + mService.mLastOrientation); |
| 358 | // The next app has not been requested to be visible, so we keep the current orientation |
| 359 | // to prevent freezing/unfreezing the display too early. |
| 360 | return mService.mLastOrientation; |
| 361 | } |
| 362 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 363 | void updateDisplayInfo() { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 364 | mDisplay.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 365 | mDisplay.getMetrics(mDisplayMetrics); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 366 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 367 | mTaskStackContainers.get(i).updateDisplayInfo(null); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 368 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 371 | void initializeDisplayBaseInfo() { |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 372 | final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal; |
| 373 | if (displayManagerInternal != null) { |
| 374 | // Bootstrap the default logical display from the display manager. |
| 375 | final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId); |
| 376 | if (newDisplayInfo != null) { |
| 377 | mDisplayInfo.copyFrom(newDisplayInfo); |
| 378 | } |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 379 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 380 | |
Filip Gruszczynski | 608797e | 2015-11-12 19:08:20 -0800 | [diff] [blame] | 381 | mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth; |
| 382 | mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight; |
| 383 | mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi; |
| 384 | mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight); |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 387 | void getLogicalDisplayRect(Rect out) { |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 388 | // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 389 | final int orientation = mDisplayInfo.rotation; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 390 | boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 391 | final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 392 | final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 393 | int width = mDisplayInfo.logicalWidth; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 394 | int left = (physWidth - width) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 395 | int height = mDisplayInfo.logicalHeight; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 396 | int top = (physHeight - height) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 397 | out.set(left, top, left + width, top + height); |
| 398 | } |
| 399 | |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 400 | private void getLogicalDisplayRect(Rect out, int orientation) { |
| 401 | getLogicalDisplayRect(out); |
| 402 | |
| 403 | // Rotate the Rect if needed. |
| 404 | final int currentRotation = mDisplayInfo.rotation; |
| 405 | final int rotationDelta = deltaRotation(currentRotation, orientation); |
| 406 | if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) { |
| 407 | createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix); |
| 408 | mTmpRectF.set(out); |
| 409 | mTmpMatrix.mapRect(mTmpRectF); |
| 410 | mTmpRectF.round(out); |
| 411 | } |
| 412 | } |
| 413 | |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 414 | void getContentRect(Rect out) { |
| 415 | out.set(mContentRect); |
| 416 | } |
| 417 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 418 | /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */ |
| 419 | void attachStack(TaskStack stack, boolean onTop) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 420 | mTaskStackContainers.attachStack(stack, onTop); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 421 | } |
| 422 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 423 | void moveStack(TaskStack stack, boolean toTop) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 424 | mTaskStackContainers.moveStack(stack, toTop); |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 425 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 426 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 427 | @Override |
| 428 | protected void addChild(DisplayChildWindowContainer child, |
| 429 | Comparator<DisplayChildWindowContainer> comparator) { |
| 430 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 431 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 432 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 433 | @Override |
| 434 | protected void addChild(DisplayChildWindowContainer child, int index) { |
| 435 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | protected void removeChild(DisplayChildWindowContainer child) { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame^] | 440 | // Only allow removal of direct children from this display if the display is in the process |
| 441 | // of been removed. |
| 442 | if (mRemovingDisplay) { |
| 443 | super.removeChild(child); |
| 444 | return; |
| 445 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 446 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Propagate the new bounds to all child stacks. |
| 451 | * @param contentRect The bounds to apply at the top level. |
| 452 | */ |
| 453 | void resize(Rect contentRect) { |
| 454 | mContentRect.set(contentRect); |
| 455 | } |
| 456 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 457 | int taskIdFromPoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 458 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 459 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 460 | final int taskId = stack.taskIdFromPoint(x, y); |
| 461 | if (taskId != -1) { |
| 462 | return taskId; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 463 | } |
| 464 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 465 | return -1; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 468 | /** |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 469 | * Find the task whose outside touch area (for resizing) (x, y) falls within. |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 470 | * Returns null if the touch doesn't fall into a resizing area. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 471 | */ |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 472 | Task findTaskForResizePoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 473 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 474 | mTmpTaskForResizePointSearchResult.reset(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 475 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 476 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 477 | if (!StackId.isTaskResizeAllowed(stack.mStackId)) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 478 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 479 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 480 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 481 | stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult); |
| 482 | if (mTmpTaskForResizePointSearchResult.searchDone) { |
| 483 | return mTmpTaskForResizePointSearchResult.taskForResize; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 484 | } |
| 485 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 486 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 489 | void setTouchExcludeRegion(Task focusedTask) { |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 490 | mTouchExcludeRegion.set(mBaseDisplayRect); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 491 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 492 | mTmpRect2.setEmpty(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 493 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 494 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 495 | stack.setTouchExcludeRegion( |
| 496 | focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 497 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 498 | // If we removed the focused task above, add it back and only leave its |
| 499 | // outside touch area in the exclusion. TapDectector is not interested in |
| 500 | // any touch inside the focused task itself. |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 501 | if (!mTmpRect2.isEmpty()) { |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 502 | mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION); |
| 503 | } |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 504 | final WindowState inputMethod = mService.mInputMethodWindow; |
| 505 | if (inputMethod != null && inputMethod.isVisibleLw()) { |
| 506 | // If the input method is visible and the user is typing, we don't want these touch |
| 507 | // events to be intercepted and used to change focus. This would likely cause a |
| 508 | // disappearance of the input method. |
| 509 | inputMethod.getTouchableRegion(mTmpRegion); |
| 510 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 511 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 512 | for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) { |
| 513 | WindowState win = mTapExcludedWindows.get(i); |
| 514 | win.getTouchableRegion(mTmpRegion); |
| 515 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 516 | } |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 517 | if (getDockedStackVisibleForUserLocked() != null) { |
| 518 | mDividerControllerLocked.getTouchRegion(mTmpRect); |
Jorim Jaggi | 7f19cb8 | 2016-03-25 19:37:44 -0700 | [diff] [blame] | 519 | mTmpRegion.set(mTmpRect); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 520 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
| 521 | } |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 522 | if (mTapDetector != null) { |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 523 | mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion); |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 524 | } |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 527 | void switchUser() { |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 528 | final WindowList windows = getWindowList(); |
| 529 | for (int i = 0; i < windows.size(); i++) { |
| 530 | final WindowState win = windows.get(i); |
| 531 | if (win.isHiddenFromUserLocked()) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 532 | if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 533 | + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 534 | win.hideLw(false); |
| 535 | } |
| 536 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 537 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 538 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 539 | mTaskStackContainers.get(stackNdx).switchUser(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 540 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 541 | |
| 542 | rebuildAppWindowList(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 545 | void resetAnimationBackgroundAnimator() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 546 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 547 | mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
| 551 | boolean animateDimLayers() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 552 | return mDimLayerController.animateDimLayers(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | void resetDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 556 | mDimLayerController.resetDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | boolean isDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 560 | return mDimLayerController.isDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | void stopDimmingIfNeeded() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 564 | mDimLayerController.stopDimmingIfNeeded(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 567 | @Override |
| 568 | void removeIfPossible() { |
| 569 | if (isAnimating()) { |
| 570 | mDeferredRemoval = true; |
| 571 | return; |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 572 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 573 | removeImmediately(); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 576 | @Override |
| 577 | void removeImmediately() { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame^] | 578 | mRemovingDisplay = true; |
| 579 | try { |
| 580 | super.removeImmediately(); |
| 581 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); |
| 582 | mDimLayerController.close(); |
| 583 | if (mDisplayId == DEFAULT_DISPLAY) { |
| 584 | mService.unregisterPointerEventListener(mTapDetector); |
| 585 | mService.unregisterPointerEventListener(mService.mMousePositionTracker); |
| 586 | } |
| 587 | } finally { |
| 588 | mRemovingDisplay = false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 589 | } |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 592 | /** Returns true if a removal action is still being deferred. */ |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 593 | @Override |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 594 | boolean checkCompleteDeferredRemoval() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 595 | final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval(); |
| 596 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 597 | if (!stillDeferringRemoval && mDeferredRemoval) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 598 | removeImmediately(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 599 | mService.onDisplayRemoved(mDisplayId); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 600 | return false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 601 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 602 | return true; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 603 | } |
| 604 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 605 | boolean animateForIme(float interpolatedValue, float animationTarget, |
| 606 | float dividerAnimationTarget) { |
| 607 | boolean updated = false; |
| 608 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 609 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 610 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 611 | if (stack == null || !stack.isAdjustedForIme()) { |
| 612 | continue; |
| 613 | } |
| 614 | |
| 615 | if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) { |
| 616 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 617 | updated = true; |
| 618 | } else { |
| 619 | mDividerControllerLocked.mLastAnimationProgress = |
| 620 | mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue); |
| 621 | mDividerControllerLocked.mLastDividerProgress = |
| 622 | mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue); |
| 623 | updated |= stack.updateAdjustForIme( |
| 624 | mDividerControllerLocked.mLastAnimationProgress, |
| 625 | mDividerControllerLocked.mLastDividerProgress, |
| 626 | false /* force */); |
| 627 | } |
| 628 | if (interpolatedValue >= 1f) { |
| 629 | stack.endImeAdjustAnimation(); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | return updated; |
| 634 | } |
| 635 | |
| 636 | boolean clearImeAdjustAnimation() { |
| 637 | boolean changed = false; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 638 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 639 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 640 | if (stack != null && stack.isAdjustedForIme()) { |
| 641 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 642 | changed = true; |
| 643 | } |
| 644 | } |
| 645 | return changed; |
| 646 | } |
| 647 | |
| 648 | void beginImeAdjustAnimation() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 649 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 650 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 651 | if (stack.isVisible() && stack.isAdjustedForIme()) { |
| 652 | stack.beginImeAdjustAnimation(); |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | void adjustForImeIfNeeded() { |
| 658 | final WindowState imeWin = mService.mInputMethodWindow; |
| 659 | final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw() |
| 660 | && !mDividerControllerLocked.isImeHideRequested(); |
| 661 | final boolean dockVisible = mService.isStackVisibleLocked(DOCKED_STACK_ID); |
| 662 | final TaskStack imeTargetStack = mService.getImeFocusStackLocked(); |
| 663 | final int imeDockSide = (dockVisible && imeTargetStack != null) ? |
| 664 | imeTargetStack.getDockSide() : DOCKED_INVALID; |
| 665 | final boolean imeOnTop = (imeDockSide == DOCKED_TOP); |
| 666 | final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM); |
| 667 | final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock(); |
| 668 | final int imeHeight = mService.mPolicy.getInputMethodWindowVisibleHeightLw(); |
| 669 | final boolean imeHeightChanged = imeVisible && |
| 670 | imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor(); |
| 671 | |
| 672 | // The divider could be adjusted for IME position, or be thinner than usual, |
| 673 | // or both. There are three possible cases: |
| 674 | // - If IME is visible, and focus is on top, divider is not moved for IME but thinner. |
| 675 | // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner. |
| 676 | // - If IME is not visible, divider is not moved and is normal width. |
| 677 | |
| 678 | if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 679 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 680 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 681 | final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM; |
| 682 | if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)) { |
| 683 | stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged); |
| 684 | } else { |
| 685 | stack.resetAdjustedForIme(false); |
| 686 | } |
| 687 | } |
| 688 | mDividerControllerLocked.setAdjustedForIme( |
| 689 | imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight); |
| 690 | } else { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 691 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 692 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 693 | stack.resetAdjustedForIme(!dockVisible); |
| 694 | } |
| 695 | mDividerControllerLocked.setAdjustedForIme( |
| 696 | false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight); |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | void prepareFreezingTaskBounds() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 701 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 702 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 703 | stack.prepareFreezingTaskBounds(); |
| 704 | } |
| 705 | } |
| 706 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 707 | void rotateBounds(int oldRotation, int newRotation, Rect bounds) { |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 708 | getLogicalDisplayRect(mTmpRect, newRotation); |
| 709 | |
| 710 | // Compute a transform matrix to undo the coordinate space transformation, |
| 711 | // and present the window at the same physical position it previously occupied. |
| 712 | final int deltaRotation = deltaRotation(newRotation, oldRotation); |
| 713 | createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix); |
| 714 | |
| 715 | mTmpRectF.set(bounds); |
| 716 | mTmpMatrix.mapRect(mTmpRectF); |
| 717 | mTmpRectF.round(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 720 | static int deltaRotation(int oldRotation, int newRotation) { |
| 721 | int delta = newRotation - oldRotation; |
| 722 | if (delta < 0) delta += 4; |
| 723 | return delta; |
| 724 | } |
| 725 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 726 | private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight, |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 727 | Matrix outMatrix) { |
| 728 | // For rotations without Z-ordering we don't need the target rectangle's position. |
| 729 | createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth, |
| 730 | displayHeight, outMatrix); |
| 731 | } |
| 732 | |
| 733 | static void createRotationMatrix(int rotation, float rectLeft, float rectTop, |
| 734 | float displayWidth, float displayHeight, Matrix outMatrix) { |
| 735 | switch (rotation) { |
| 736 | case ROTATION_0: |
| 737 | outMatrix.reset(); |
| 738 | break; |
| 739 | case ROTATION_270: |
| 740 | outMatrix.setRotate(270, 0, 0); |
| 741 | outMatrix.postTranslate(0, displayHeight); |
| 742 | outMatrix.postTranslate(rectTop, 0); |
| 743 | break; |
| 744 | case ROTATION_180: |
| 745 | outMatrix.reset(); |
| 746 | break; |
| 747 | case ROTATION_90: |
| 748 | outMatrix.setRotate(90, 0, 0); |
| 749 | outMatrix.postTranslate(displayWidth, 0); |
| 750 | outMatrix.postTranslate(-rectTop, rectLeft); |
| 751 | break; |
| 752 | } |
| 753 | } |
| 754 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 755 | public void dump(String prefix, PrintWriter pw) { |
| 756 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 757 | final String subPrefix = " " + prefix; |
| 758 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 759 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 760 | pw.print("dpi"); |
| 761 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 762 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 763 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 764 | pw.print(" base="); |
| 765 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 766 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 767 | } |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 768 | if (mDisplayScalingDisabled) { |
| 769 | pw.println(" noscale"); |
| 770 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 771 | pw.print(" cur="); |
| 772 | pw.print(mDisplayInfo.logicalWidth); |
| 773 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 774 | pw.print(" app="); |
| 775 | pw.print(mDisplayInfo.appWidth); |
| 776 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 777 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 778 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 779 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 780 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 781 | pw.println(subPrefix + "deferred=" + mDeferredRemoval |
| 782 | + " mLayoutNeeded=" + mLayoutNeeded); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 783 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 784 | pw.println(); |
Craig Mautner | e8b85fd | 2014-10-22 09:23:25 -0700 | [diff] [blame] | 785 | pw.println(" Application tokens in top down Z order:"); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 786 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 787 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 788 | stack.dump(prefix + " ", pw); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 789 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 790 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 791 | pw.println(); |
| 792 | if (!mExitingTokens.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 793 | pw.println(); |
| 794 | pw.println(" Exiting tokens:"); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 795 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 796 | final WindowToken token = mExitingTokens.get(i); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 797 | pw.print(" Exiting #"); pw.print(i); |
| 798 | pw.print(' '); pw.print(token); |
| 799 | pw.println(':'); |
| 800 | token.dump(pw, " "); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 801 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 802 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 803 | pw.println(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 804 | mDimLayerController.dump(prefix + " ", pw); |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 805 | pw.println(); |
| 806 | mDividerControllerLocked.dump(prefix + " ", pw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 807 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 808 | |
| 809 | @Override |
| 810 | public String toString() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 811 | return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | String getName() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 815 | return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\""; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 816 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 817 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 818 | /** |
| 819 | * @return The docked stack, but only if it is visible, and {@code null} otherwise. |
| 820 | */ |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 821 | TaskStack getDockedStackLocked() { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 822 | final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 823 | return (stack != null && stack.isVisible()) ? stack : null; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 824 | } |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 825 | |
| 826 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 827 | * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not |
| 828 | * visible, as long as it's not hidden because the current user doesn't have any tasks there. |
| 829 | */ |
| 830 | TaskStack getDockedStackVisibleForUserLocked() { |
| 831 | final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 832 | return (stack != null && stack.isVisible(true /* ignoreKeyguard */)) ? stack : null; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 833 | } |
| 834 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 835 | /** Find the visible, touch-deliverable window under the given point */ |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 836 | WindowState getTouchableWinAtPointLocked(float xf, float yf) { |
| 837 | WindowState touchedWin = null; |
| 838 | final int x = (int) xf; |
| 839 | final int y = (int) yf; |
| 840 | |
| 841 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 842 | WindowState window = mWindows.get(i); |
| 843 | final int flags = window.mAttrs.flags; |
| 844 | if (!window.isVisibleLw()) { |
| 845 | continue; |
| 846 | } |
| 847 | if ((flags & FLAG_NOT_TOUCHABLE) != 0) { |
| 848 | continue; |
| 849 | } |
| 850 | |
| 851 | window.getVisibleBounds(mTmpRect); |
| 852 | if (!mTmpRect.contains(x, y)) { |
| 853 | continue; |
| 854 | } |
| 855 | |
| 856 | window.getTouchableRegion(mTmpRegion); |
| 857 | |
| 858 | final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL); |
| 859 | if (mTmpRegion.contains(x, y) || touchFlags == 0) { |
| 860 | touchedWin = window; |
| 861 | break; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | return touchedWin; |
| 866 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 867 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 868 | boolean canAddToastWindowForUid(int uid) { |
| 869 | // We allow one toast window per UID being shown at a time. |
| 870 | WindowList windows = getWindowList(); |
| 871 | final int windowCount = windows.size(); |
| 872 | for (int i = 0; i < windowCount; i++) { |
| 873 | WindowState window = windows.get(i); |
| 874 | if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == uid |
Svet Ganov | 62a40f8 | 2016-09-29 00:43:51 -0700 | [diff] [blame] | 875 | && !window.mPermanentlyHidden && !window.mAnimatingExit |
| 876 | && !window.mRemoveOnExit) { |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 877 | return false; |
| 878 | } |
| 879 | } |
| 880 | return true; |
| 881 | } |
| 882 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 883 | void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) { |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 884 | if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) { |
| 885 | return; |
| 886 | } |
| 887 | final int lostFocusUid = oldFocus.mOwnerUid; |
| 888 | WindowList windows = getWindowList(); |
| 889 | final int windowCount = windows.size(); |
| 890 | for (int i = 0; i < windowCount; i++) { |
| 891 | WindowState window = windows.get(i); |
| 892 | if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == lostFocusUid) { |
| 893 | if (!mService.mH.hasMessages(WindowManagerService.H.WINDOW_HIDE_TIMEOUT, window)) { |
| 894 | mService.mH.sendMessageDelayed( |
| 895 | mService.mH.obtainMessage( |
| 896 | WindowManagerService.H.WINDOW_HIDE_TIMEOUT, window), |
| 897 | window.mAttrs.hideTimeoutMilliseconds); |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 902 | |
| 903 | WindowState findFocusedWindow() { |
| 904 | final AppWindowToken focusedApp = mService.mFocusedApp; |
| 905 | |
| 906 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 907 | final WindowState win = mWindows.get(i); |
| 908 | |
| 909 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + i + " = " + win |
| 910 | + ", flags=" + win.mAttrs.flags + ", canReceive=" + win.canReceiveKeys()); |
| 911 | |
| 912 | if (!win.canReceiveKeys()) { |
| 913 | continue; |
| 914 | } |
| 915 | |
| 916 | final AppWindowToken wtoken = win.mAppToken; |
| 917 | |
| 918 | // If this window's application has been removed, just skip it. |
| 919 | if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) { |
| 920 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because " |
| 921 | + (wtoken.removed ? "removed" : "sendingToBottom")); |
| 922 | continue; |
| 923 | } |
| 924 | |
| 925 | if (focusedApp == null) { |
| 926 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null" |
| 927 | + " using new focus @ " + i + " = " + win); |
| 928 | return win; |
| 929 | } |
| 930 | |
| 931 | if (!focusedApp.windowsAreFocusable()) { |
| 932 | // Current focused app windows aren't focusable... |
| 933 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not" |
| 934 | + " focusable using new focus @ " + i + " = " + win); |
| 935 | return win; |
| 936 | } |
| 937 | |
| 938 | // Descend through all of the app tokens and find the first that either matches |
| 939 | // win.mAppToken (return win) or mFocusedApp (return null). |
| 940 | if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 941 | if (focusedApp.compareTo(wtoken) > 0) { |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 942 | // App stack below focused app stack. No focus for you!!! |
| 943 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, |
| 944 | "findFocusedWindow: Reached focused app=" + focusedApp); |
| 945 | return null; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " |
| 950 | + i + " = " + win); |
| 951 | return win; |
| 952 | } |
| 953 | |
| 954 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows."); |
| 955 | return null; |
| 956 | } |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 957 | |
| 958 | int addAppWindowToWindowList(final WindowState win) { |
| 959 | final IWindow client = win.mClient; |
| 960 | |
| 961 | WindowList tokenWindowList = getTokenWindowsOnDisplay(win.mToken); |
| 962 | if (!tokenWindowList.isEmpty()) { |
| 963 | return addAppWindowExisting(win, tokenWindowList); |
| 964 | } |
| 965 | |
| 966 | // No windows from this token on this display |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 967 | if (localLOGV) Slog.v(TAG_WM, "Figuring out where to add app window " |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 968 | + client.asBinder() + " (token=" + this + ")"); |
| 969 | |
| 970 | final WindowToken wToken = win.mToken; |
| 971 | |
| 972 | // Figure out where the window should go, based on the order of applications. |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 973 | mTmpGetWindowOnDisplaySearchResult.reset(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 974 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 975 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 976 | stack.getWindowOnDisplayBeforeToken(this, wToken, mTmpGetWindowOnDisplaySearchResult); |
| 977 | if (mTmpGetWindowOnDisplaySearchResult.reachedToken) { |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 978 | // We have reach the token we are interested in. End search. |
| 979 | break; |
| 980 | } |
| 981 | } |
| 982 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 983 | WindowState pos = mTmpGetWindowOnDisplaySearchResult.foundWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 984 | |
| 985 | // We now know the index into the apps. If we found an app window above, that gives us the |
| 986 | // position; else we need to look some more. |
| 987 | if (pos != null) { |
| 988 | // Move behind any windows attached to this one. |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 989 | final WindowToken atoken = getWindowToken(pos.mClient.asBinder()); |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 990 | if (atoken != null) { |
| 991 | tokenWindowList = getTokenWindowsOnDisplay(atoken); |
| 992 | final int NC = tokenWindowList.size(); |
| 993 | if (NC > 0) { |
| 994 | WindowState bottom = tokenWindowList.get(0); |
| 995 | if (bottom.mSubLayer < 0) { |
| 996 | pos = bottom; |
| 997 | } |
| 998 | } |
| 999 | } |
| 1000 | addWindowToListBefore(win, pos); |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
| 1004 | // Continue looking down until we find the first token that has windows on this display. |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1005 | mTmpGetWindowOnDisplaySearchResult.reset(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1006 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1007 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1008 | stack.getWindowOnDisplayAfterToken(this, wToken, mTmpGetWindowOnDisplaySearchResult); |
| 1009 | if (mTmpGetWindowOnDisplaySearchResult.foundWindow != null) { |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1010 | // We have found a window after the token. End search. |
| 1011 | break; |
| 1012 | } |
| 1013 | } |
| 1014 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1015 | pos = mTmpGetWindowOnDisplaySearchResult.foundWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1016 | |
| 1017 | if (pos != null) { |
| 1018 | // Move in front of any windows attached to this one. |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1019 | final WindowToken atoken = getWindowToken(pos.mClient.asBinder()); |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1020 | if (atoken != null) { |
| 1021 | final WindowState top = atoken.getTopWindow(); |
| 1022 | if (top != null && top.mSubLayer >= 0) { |
| 1023 | pos = top; |
| 1024 | } |
| 1025 | } |
| 1026 | addWindowToListAfter(win, pos); |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | // Just search for the start of this layer. |
| 1031 | final int myLayer = win.mBaseLayer; |
| 1032 | int i; |
| 1033 | for (i = mWindows.size() - 1; i >= 0; --i) { |
| 1034 | final WindowState w = mWindows.get(i); |
| 1035 | // Dock divider shares the base layer with application windows, but we want to always |
| 1036 | // keep it above the application windows. The sharing of the base layer is intended |
| 1037 | // for window animations, which need to be above the dock divider for the duration |
| 1038 | // of the animation. |
| 1039 | if (w.mBaseLayer <= myLayer && w.mAttrs.type != TYPE_DOCK_DIVIDER) { |
| 1040 | break; |
| 1041 | } |
| 1042 | } |
| 1043 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1044 | "Based on layer: Adding window " + win + " at " + (i + 1) + " of " |
| 1045 | + mWindows.size()); |
| 1046 | mWindows.add(i + 1, win); |
| 1047 | mService.mWindowsChanged = true; |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
| 1051 | /** Adds this non-app window to the window list. */ |
| 1052 | void addNonAppWindowToWindowList(WindowState win) { |
| 1053 | // Figure out where window should go, based on layer. |
| 1054 | int i; |
| 1055 | for (i = mWindows.size() - 1; i >= 0; i--) { |
| 1056 | final WindowState otherWin = mWindows.get(i); |
| 1057 | if (otherWin.getBaseType() != TYPE_WALLPAPER && otherWin.mBaseLayer <= win.mBaseLayer) { |
| 1058 | // Wallpaper wanders through the window list, for example to position itself |
| 1059 | // directly behind keyguard. Because of this it will break the ordering based on |
| 1060 | // WindowState.mBaseLayer. There might windows with higher mBaseLayer behind it and |
| 1061 | // we don't want the new window to appear above them. An example of this is adding |
| 1062 | // of the docked stack divider. Consider a scenario with the following ordering (top |
| 1063 | // to bottom): keyguard, wallpaper, assist preview, apps. We want the dock divider |
| 1064 | // to land below the assist preview, so the dock divider must ignore the wallpaper, |
| 1065 | // with which it shares the base layer. |
| 1066 | break; |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | i++; |
| 1071 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1072 | "Free window: Adding window " + this + " at " + i + " of " + mWindows.size()); |
| 1073 | mWindows.add(i, win); |
| 1074 | mService.mWindowsChanged = true; |
| 1075 | } |
| 1076 | |
Wale Ogunwale | b9a07c3 | 2016-10-12 14:55:56 -0700 | [diff] [blame] | 1077 | void addToWindowList(WindowState win, int index) { |
| 1078 | mWindows.add(index, win); |
| 1079 | } |
| 1080 | |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1081 | void addChildWindowToWindowList(WindowState win) { |
| 1082 | final WindowState parentWindow = win.getParentWindow(); |
| 1083 | |
| 1084 | WindowList windowsOnSameDisplay = getTokenWindowsOnDisplay(win.mToken); |
| 1085 | |
| 1086 | // Figure out this window's ordering relative to the parent window. |
| 1087 | final int wCount = windowsOnSameDisplay.size(); |
| 1088 | final int sublayer = win.mSubLayer; |
| 1089 | int largestSublayer = Integer.MIN_VALUE; |
| 1090 | WindowState windowWithLargestSublayer = null; |
| 1091 | int i; |
| 1092 | for (i = 0; i < wCount; i++) { |
| 1093 | WindowState w = windowsOnSameDisplay.get(i); |
| 1094 | final int wSublayer = w.mSubLayer; |
| 1095 | if (wSublayer >= largestSublayer) { |
| 1096 | largestSublayer = wSublayer; |
| 1097 | windowWithLargestSublayer = w; |
| 1098 | } |
| 1099 | if (sublayer < 0) { |
| 1100 | // For negative sublayers, we go below all windows in the same sublayer. |
| 1101 | if (wSublayer >= sublayer) { |
| 1102 | addWindowToListBefore(win, wSublayer >= 0 ? parentWindow : w); |
| 1103 | break; |
| 1104 | } |
| 1105 | } else { |
| 1106 | // For positive sublayers, we go above all windows in the same sublayer. |
| 1107 | if (wSublayer > sublayer) { |
| 1108 | addWindowToListBefore(win, w); |
| 1109 | break; |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | if (i >= wCount) { |
| 1114 | if (sublayer < 0) { |
| 1115 | addWindowToListBefore(win, parentWindow); |
| 1116 | } else { |
| 1117 | addWindowToListAfter(win, |
| 1118 | largestSublayer >= 0 ? windowWithLargestSublayer : parentWindow); |
| 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1123 | /** |
| 1124 | * Z-orders the display window list so that: |
| 1125 | * <ul> |
| 1126 | * <li>Any windows that are currently below the wallpaper window stay below the wallpaper |
| 1127 | * window. |
| 1128 | * <li>Exiting application windows are at the bottom, but above the wallpaper window. |
| 1129 | * <li>All other application windows are above the exiting application windows and ordered based |
| 1130 | * on the ordering of their stacks and tasks on the display. |
| 1131 | * <li>Non-application windows are at the very top. |
| 1132 | * </ul> |
| 1133 | * <p> |
| 1134 | * NOTE: This isn't a complete picture of what the user see. Further manipulation of the window |
| 1135 | * surface layering is done in {@link WindowLayersController}. |
| 1136 | */ |
| 1137 | void rebuildAppWindowList() { |
| 1138 | int count = mWindows.size(); |
| 1139 | int i; |
| 1140 | int lastBelow = -1; |
| 1141 | int numRemoved = 0; |
| 1142 | |
| 1143 | if (mRebuildTmp.length < count) { |
| 1144 | mRebuildTmp = new WindowState[count + 10]; |
| 1145 | } |
| 1146 | |
| 1147 | // First remove all existing app windows. |
| 1148 | i = 0; |
| 1149 | while (i < count) { |
| 1150 | final WindowState w = mWindows.get(i); |
| 1151 | if (w.mAppToken != null) { |
| 1152 | final WindowState win = mWindows.remove(i); |
| 1153 | win.mRebuilding = true; |
| 1154 | mRebuildTmp[numRemoved] = win; |
| 1155 | mService.mWindowsChanged = true; |
| 1156 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Rebuild removing window: " + win); |
| 1157 | count--; |
| 1158 | numRemoved++; |
| 1159 | continue; |
| 1160 | } else if (lastBelow == i-1) { |
| 1161 | if (w.mAttrs.type == TYPE_WALLPAPER) { |
| 1162 | lastBelow = i; |
| 1163 | } |
| 1164 | } |
| 1165 | i++; |
| 1166 | } |
| 1167 | |
| 1168 | // Keep whatever windows were below the app windows still below, by skipping them. |
| 1169 | lastBelow++; |
| 1170 | i = lastBelow; |
| 1171 | |
| 1172 | // First add all of the exiting app tokens... these are no longer in the main app list, |
| 1173 | // but still have windows shown. We put them in the back because now that the animation is |
| 1174 | // over we no longer will care about them. |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1175 | final int numStacks = mTaskStackContainers.size(); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1176 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1177 | AppTokenList exitingAppTokens = mTaskStackContainers.get(stackNdx).mExitingAppTokens; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1178 | int NT = exitingAppTokens.size(); |
| 1179 | for (int j = 0; j < NT; j++) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1180 | i = exitingAppTokens.get(j).rebuildWindowListUnchecked(i); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | // And add in the still active app tokens in Z order. |
| 1185 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1186 | i = mTaskStackContainers.get(stackNdx).rebuildWindowList(i); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | i -= lastBelow; |
| 1190 | if (i != numRemoved) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1191 | setLayoutNeeded(); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1192 | Slog.w(TAG_WM, "On display=" + mDisplayId + " Rebuild removed " + numRemoved |
| 1193 | + " windows but added " + i + " rebuildAppWindowListLocked() " |
| 1194 | + " callers=" + Debug.getCallers(10)); |
| 1195 | for (i = 0; i < numRemoved; i++) { |
| 1196 | WindowState ws = mRebuildTmp[i]; |
| 1197 | if (ws.mRebuilding) { |
| 1198 | StringWriter sw = new StringWriter(); |
| 1199 | PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 1200 | ws.dump(pw, "", true); |
| 1201 | pw.flush(); |
| 1202 | Slog.w(TAG_WM, "This window was lost: " + ws); |
| 1203 | Slog.w(TAG_WM, sw.toString()); |
| 1204 | ws.mWinAnimator.destroySurfaceLocked(); |
| 1205 | } |
| 1206 | } |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1207 | Slog.w(TAG_WM, "Current window hierarchy:"); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1208 | dumpChildrenNames(); |
| 1209 | Slog.w(TAG_WM, "Final window list:"); |
| 1210 | dumpWindows(); |
| 1211 | } |
| 1212 | Arrays.fill(mRebuildTmp, null); |
| 1213 | } |
| 1214 | |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1215 | /** Return the list of Windows on this display associated with the input token. */ |
| 1216 | WindowList getTokenWindowsOnDisplay(WindowToken token) { |
| 1217 | final WindowList windowList = new WindowList(); |
| 1218 | final int count = mWindows.size(); |
| 1219 | for (int i = 0; i < count; i++) { |
| 1220 | final WindowState win = mWindows.get(i); |
| 1221 | if (win.mToken == token) { |
| 1222 | windowList.add(win); |
| 1223 | } |
| 1224 | } |
| 1225 | return windowList; |
| 1226 | } |
| 1227 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1228 | void setLayoutNeeded() { |
| 1229 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 1230 | mLayoutNeeded = true; |
| 1231 | } |
| 1232 | |
| 1233 | void clearLayoutNeeded() { |
| 1234 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 1235 | mLayoutNeeded = false; |
| 1236 | } |
| 1237 | |
| 1238 | boolean isLayoutNeeded() { |
| 1239 | return mLayoutNeeded; |
| 1240 | } |
| 1241 | |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1242 | private int addAppWindowExisting(WindowState win, WindowList tokenWindowList) { |
| 1243 | |
| 1244 | int tokenWindowsPos; |
| 1245 | // If this application has existing windows, we simply place the new window on top of |
| 1246 | // them... but keep the starting window on top. |
| 1247 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1248 | // Base windows go behind everything else. |
| 1249 | final WindowState lowestWindow = tokenWindowList.get(0); |
| 1250 | addWindowToListBefore(win, lowestWindow); |
| 1251 | tokenWindowsPos = win.mToken.getWindowIndex(lowestWindow); |
| 1252 | } else { |
| 1253 | final AppWindowToken atoken = win.mAppToken; |
| 1254 | final int windowListPos = tokenWindowList.size(); |
| 1255 | final WindowState lastWindow = tokenWindowList.get(windowListPos - 1); |
| 1256 | if (atoken != null && lastWindow == atoken.startingWindow) { |
| 1257 | addWindowToListBefore(win, lastWindow); |
| 1258 | tokenWindowsPos = win.mToken.getWindowIndex(lastWindow); |
| 1259 | } else { |
| 1260 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1261 | // There is a window above this one associated with the same apptoken note that the |
| 1262 | // window could be a floating window that was created later or a window at the top |
| 1263 | // of the list of windows associated with this token. |
| 1264 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1265 | "not Base app: Adding window " + win + " at " + (newIdx + 1) + " of " |
| 1266 | + mWindows.size()); |
| 1267 | mWindows.add(newIdx + 1, win); |
| 1268 | if (newIdx < 0) { |
| 1269 | // No window from token found on win's display. |
| 1270 | tokenWindowsPos = 0; |
| 1271 | } else { |
| 1272 | tokenWindowsPos = win.mToken.getWindowIndex(mWindows.get(newIdx)) + 1; |
| 1273 | } |
| 1274 | mService.mWindowsChanged = true; |
| 1275 | } |
| 1276 | } |
| 1277 | return tokenWindowsPos; |
| 1278 | } |
| 1279 | |
| 1280 | /** Places the first input window after the second input window in the window list. */ |
| 1281 | private void addWindowToListAfter(WindowState first, WindowState second) { |
| 1282 | final int i = mWindows.indexOf(second); |
| 1283 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1284 | "Adding window " + this + " at " + (i + 1) + " of " + mWindows.size() |
| 1285 | + " (after " + second + ")"); |
| 1286 | mWindows.add(i + 1, first); |
| 1287 | mService.mWindowsChanged = true; |
| 1288 | } |
| 1289 | |
| 1290 | /** Places the first input window before the second input window in the window list. */ |
| 1291 | private void addWindowToListBefore(WindowState first, WindowState second) { |
| 1292 | int i = mWindows.indexOf(second); |
| 1293 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1294 | "Adding window " + this + " at " + i + " of " + mWindows.size() |
| 1295 | + " (before " + second + ")"); |
| 1296 | if (i < 0) { |
| 1297 | Slog.w(TAG_WM, "addWindowToListBefore: Unable to find " + second + " in " + mWindows); |
| 1298 | i = 0; |
| 1299 | } |
| 1300 | mWindows.add(i, first); |
| 1301 | mService.mWindowsChanged = true; |
| 1302 | } |
| 1303 | |
| 1304 | /** |
| 1305 | * This method finds out the index of a window that has the same app token as win. used for z |
| 1306 | * ordering the windows in mWindows |
| 1307 | */ |
| 1308 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1309 | for(int j = mWindows.size() - 1; j >= 0; j--) { |
| 1310 | final WindowState wentry = mWindows.get(j); |
| 1311 | if(wentry.mAppToken == win.mAppToken) { |
| 1312 | return j; |
| 1313 | } |
| 1314 | } |
| 1315 | return -1; |
| 1316 | } |
| 1317 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1318 | private void dumpChildrenNames() { |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1319 | StringBuilder output = new StringBuilder(); |
| 1320 | dumpChildrenNames(output, " "); |
| 1321 | Slog.v(TAG_WM, output.toString()); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1324 | private void dumpWindows() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1325 | Slog.v(TAG_WM, " Display #" + mDisplayId); |
| 1326 | final WindowList windows = getWindowList(); |
| 1327 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 1328 | Slog.v(TAG_WM, " #" + winNdx + ": " + windows.get(winNdx)); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1329 | } |
| 1330 | } |
| 1331 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1332 | void dumpTokens(PrintWriter pw, boolean dumpAll) { |
| 1333 | if (mTokenMap.isEmpty()) { |
| 1334 | return; |
| 1335 | } |
| 1336 | pw.println(" Display #" + mDisplayId); |
| 1337 | final Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 1338 | while (it.hasNext()) { |
| 1339 | final WindowToken token = it.next(); |
| 1340 | pw.print(" "); |
| 1341 | pw.print(token); |
| 1342 | if (dumpAll) { |
| 1343 | pw.println(':'); |
| 1344 | token.dump(pw, " "); |
| 1345 | } else { |
| 1346 | pw.println(); |
| 1347 | } |
| 1348 | } |
| 1349 | } |
| 1350 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1351 | void enableSurfaceTrace(FileDescriptor fd) { |
| 1352 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 1353 | final WindowState win = mWindows.get(i); |
| 1354 | win.mWinAnimator.enableSurfaceTrace(fd); |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | void disableSurfaceTrace() { |
| 1359 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 1360 | final WindowState win = mWindows.get(i); |
| 1361 | win.mWinAnimator.disableSurfaceTrace(); |
| 1362 | } |
| 1363 | } |
| 1364 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1365 | static final class GetWindowOnDisplaySearchResult { |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1366 | boolean reachedToken; |
| 1367 | WindowState foundWindow; |
| 1368 | |
| 1369 | void reset() { |
| 1370 | reachedToken = false; |
| 1371 | foundWindow = null; |
| 1372 | } |
| 1373 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1374 | |
| 1375 | static final class TaskForResizePointSearchResult { |
| 1376 | boolean searchDone; |
| 1377 | Task taskForResize; |
| 1378 | |
| 1379 | void reset() { |
| 1380 | searchDone = false; |
| 1381 | taskForResize = null; |
| 1382 | } |
| 1383 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 1384 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1385 | /** |
| 1386 | * Base class for any direct child window container of {@link #DisplayContent} need to inherit |
| 1387 | * from. This is mainly a pass through class that allows {@link #DisplayContent} to have |
| 1388 | * homogeneous children type which is currently required by sub-classes of |
| 1389 | * {@link WindowContainer} class. |
| 1390 | */ |
| 1391 | static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> { |
| 1392 | |
| 1393 | int size() { |
| 1394 | return mChildren.size(); |
| 1395 | } |
| 1396 | |
| 1397 | E get(int index) { |
| 1398 | return mChildren.get(index); |
| 1399 | } |
| 1400 | |
| 1401 | @Override |
| 1402 | boolean fillsParent() { |
| 1403 | return true; |
| 1404 | } |
| 1405 | |
| 1406 | @Override |
| 1407 | boolean isVisible() { |
| 1408 | return true; |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 1409 | } |
| 1410 | } |
| 1411 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1412 | /** |
| 1413 | * Window container class that contains all containers on this display relating to Apps. |
| 1414 | * I.e Activities. |
| 1415 | */ |
| 1416 | private class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> { |
| 1417 | |
| 1418 | void attachStack(TaskStack stack, boolean onTop) { |
| 1419 | if (stack.mStackId == HOME_STACK_ID) { |
| 1420 | if (mHomeStack != null) { |
| 1421 | throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first."); |
| 1422 | } |
| 1423 | mHomeStack = stack; |
| 1424 | } |
| 1425 | addChild(stack, onTop); |
| 1426 | stack.onDisplayChanged(DisplayContent.this); |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 1427 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1428 | |
| 1429 | void moveStack(TaskStack stack, boolean toTop) { |
| 1430 | if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) { |
| 1431 | // This stack is always-on-top silly... |
| 1432 | Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom"); |
| 1433 | return; |
| 1434 | } |
| 1435 | |
| 1436 | if (!mChildren.contains(stack)) { |
| 1437 | Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable()); |
| 1438 | } |
| 1439 | removeChild(stack); |
| 1440 | addChild(stack, toTop); |
| 1441 | } |
| 1442 | |
| 1443 | private void addChild(TaskStack stack, boolean toTop) { |
| 1444 | int addIndex = toTop ? mChildren.size() : 0; |
| 1445 | |
| 1446 | if (toTop |
| 1447 | && mService.isStackVisibleLocked(PINNED_STACK_ID) |
| 1448 | && stack.mStackId != PINNED_STACK_ID) { |
| 1449 | // The pinned stack is always the top most stack (always-on-top) when it is visible. |
| 1450 | // So, stack is moved just below the pinned stack. |
| 1451 | addIndex--; |
| 1452 | TaskStack topStack = mChildren.get(addIndex); |
| 1453 | if (topStack.mStackId != PINNED_STACK_ID) { |
| 1454 | throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren); |
| 1455 | } |
| 1456 | } |
| 1457 | addChild(stack, addIndex); |
| 1458 | setLayoutNeeded(); |
| 1459 | } |
| 1460 | |
| 1461 | } |
| 1462 | |
| 1463 | /** |
| 1464 | * Window container class that contains all containers on this display that are not related to |
| 1465 | * Apps. E.g. status bar. |
| 1466 | */ |
| 1467 | private static class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> { |
| 1468 | |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 1469 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1470 | } |