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