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 | |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 19 | import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 20 | import static com.android.server.wm.WindowManagerService.DEBUG_STACK; |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 21 | import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 22 | import static com.android.server.wm.WindowManagerService.TAG; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 23 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 24 | import android.app.ActivityManager.StackBoxInfo; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 25 | import android.graphics.Rect; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 26 | import android.graphics.Region; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 27 | import android.util.Slog; |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 28 | import android.util.SparseArray; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 29 | import android.view.Display; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 30 | import android.view.DisplayInfo; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 31 | import android.view.InputChannel; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 32 | |
| 33 | import java.io.PrintWriter; |
| 34 | import java.util.ArrayList; |
| 35 | |
| 36 | class DisplayContentList extends ArrayList<DisplayContent> { |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 41 | * particular Display. |
| 42 | * |
| 43 | * IMPORTANT: No method from this class should ever be used without holding |
| 44 | * WindowManagerService.mWindowMap. |
| 45 | */ |
| 46 | class DisplayContent { |
| 47 | |
| 48 | /** Unique identifier of this stack. */ |
| 49 | private final int mDisplayId; |
| 50 | |
| 51 | /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element |
| 52 | * from mDisplayWindows; */ |
| 53 | private WindowList mWindows = new WindowList(); |
| 54 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 55 | // This protects the following display size properties, so that |
| 56 | // getDisplaySize() doesn't need to acquire the global lock. This is |
| 57 | // needed because the window manager sometimes needs to use ActivityThread |
| 58 | // while it has its global state locked (for example to load animation |
| 59 | // resources), but the ActivityThread also needs get the current display |
| 60 | // size sometimes when it has its package lock held. |
| 61 | // |
| 62 | // These will only be modified with both mWindowMap and mDisplaySizeLock |
| 63 | // held (in that order) so the window manager doesn't need to acquire this |
| 64 | // lock when needing these values in its normal operation. |
| 65 | final Object mDisplaySizeLock = new Object(); |
| 66 | int mInitialDisplayWidth = 0; |
| 67 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 68 | int mInitialDisplayDensity = 0; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 69 | int mBaseDisplayWidth = 0; |
| 70 | int mBaseDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 71 | int mBaseDisplayDensity = 0; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 72 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 73 | private final Display mDisplay; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 74 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 75 | Rect mBaseDisplayRect = new Rect(); |
| 76 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 77 | // Accessed directly by all users. |
| 78 | boolean layoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 79 | int pendingLayoutChanges; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 80 | final boolean isDefaultDisplay; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 81 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 82 | /** |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 83 | * Window tokens that are in the process of exiting, but still |
| 84 | * on screen for animations. |
| 85 | */ |
| 86 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 87 | |
| 88 | /** |
| 89 | * Application tokens that are in the process of exiting, but still |
| 90 | * on screen for animations. |
| 91 | */ |
| 92 | final AppTokenList mExitingAppTokens = new AppTokenList(); |
| 93 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 94 | /** Array containing the home StackBox and possibly one more which would contain apps. Array |
| 95 | * is stored in display order with the current bottom stack at 0. */ |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 96 | private ArrayList<StackBox> mStackBoxes = new ArrayList<StackBox>(); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 97 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 98 | /** True when the home StackBox is at the top of mStackBoxes, false otherwise. */ |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 99 | private TaskStack mHomeStack = null; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 100 | |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 101 | /** Sorted most recent at top, oldest at [0]. */ |
| 102 | ArrayList<TaskStack> mStackHistory = new ArrayList<TaskStack>(); |
| 103 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 104 | /** Forward motion events to mTapDetector. */ |
| 105 | InputChannel mTapInputChannel; |
| 106 | |
| 107 | /** Detect user tapping outside of current focused stack bounds .*/ |
| 108 | StackTapDetector mTapDetector; |
| 109 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 110 | /** Detect user tapping outside of current focused stack bounds .*/ |
| 111 | Region mTouchExcludeRegion = new Region(); |
| 112 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 113 | SparseArray<UserStacks> mUserStacks = new SparseArray<UserStacks>(); |
| 114 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 115 | /** Save allocating when retrieving tasks */ |
| 116 | ArrayList<Task> mTmpTasks = new ArrayList<Task>(); |
| 117 | |
| 118 | /** Save allocating when calculating rects */ |
| 119 | Rect mTmpRect = new Rect(); |
| 120 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 121 | /** |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 122 | * @param display May not be null. |
| 123 | */ |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 124 | DisplayContent(Display display) { |
| 125 | mDisplay = display; |
| 126 | mDisplayId = display.getDisplayId(); |
| 127 | display.getDisplayInfo(mDisplayInfo); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 128 | isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | int getDisplayId() { |
| 132 | return mDisplayId; |
| 133 | } |
| 134 | |
| 135 | WindowList getWindowList() { |
| 136 | return mWindows; |
| 137 | } |
| 138 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 139 | Display getDisplay() { |
| 140 | return mDisplay; |
| 141 | } |
| 142 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 143 | DisplayInfo getDisplayInfo() { |
| 144 | return mDisplayInfo; |
| 145 | } |
| 146 | |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 147 | boolean homeOnTop() { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 148 | return mStackBoxes.get(0).mStack != mHomeStack; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 151 | void moveStack(TaskStack stack, boolean toTop) { |
| 152 | mStackHistory.remove(stack); |
| 153 | mStackHistory.add(toTop ? mStackHistory.size() : 0, stack); |
| 154 | } |
| 155 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 156 | /** |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 157 | * Retrieve the tasks on this display in stack order from the bottommost TaskStack up. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 158 | * @return All the Tasks, in order, on this display. |
| 159 | */ |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 160 | ArrayList<Task> getTasks() { |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 161 | mTmpTasks.clear(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 162 | // First do the tasks belonging to other users. |
| 163 | final int numUserStacks = mUserStacks.size(); |
| 164 | for (int i = 0; i < numUserStacks; ++i) { |
| 165 | UserStacks userStacks = mUserStacks.valueAt(i); |
| 166 | ArrayList<TaskStack> stacks = userStacks.mSavedStackHistory; |
| 167 | final int numStacks = stacks.size(); |
| 168 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 169 | TaskStack stack = stacks.get(stackNdx); |
| 170 | if (stack != mHomeStack) { |
| 171 | if (WindowManagerService.DEBUG_LAYERS) Slog.i(TAG, "getTasks: mStackHistory=" + |
| 172 | mStackHistory); |
| 173 | mTmpTasks.addAll(stack.getTasks()); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | // Now do the current user's tasks. |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 178 | final int numStacks = mStackHistory.size(); |
| 179 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 180 | mTmpTasks.addAll(mStackHistory.get(stackNdx).getTasks()); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 181 | } |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 182 | if (WindowManagerService.DEBUG_LAYERS) Slog.i(TAG, "getTasks: mStackHistory=" + |
| 183 | mStackHistory); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 184 | return mTmpTasks; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 187 | TaskStack getHomeStack() { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 188 | return mHomeStack; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 191 | public void updateDisplayInfo() { |
| 192 | mDisplay.getDisplayInfo(mDisplayInfo); |
| 193 | } |
| 194 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 195 | /** @return The number of tokens in all of the Tasks on this display. */ |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 196 | int numTokens() { |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 197 | getTasks(); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 198 | int count = 0; |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 199 | for (int taskNdx = mTmpTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 200 | count += mTmpTasks.get(taskNdx).mAppTokens.size(); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 201 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 202 | return count; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 205 | /** Refer to {@link WindowManagerService#createStack(int, int, int, float)} */ |
Craig Mautner | 5a44915 | 2013-05-24 15:49:29 -0700 | [diff] [blame] | 206 | TaskStack createStack(WindowManagerService service, int stackId, int relativeStackBoxId, |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 207 | int position, float weight) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 208 | TaskStack newStack = null; |
Craig Mautner | 5a44915 | 2013-05-24 15:49:29 -0700 | [diff] [blame] | 209 | if (DEBUG_STACK) Slog.d(TAG, "createStack: stackId=" + stackId + " relativeStackBoxId=" |
| 210 | + relativeStackBoxId + " position=" + position + " weight=" + weight); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 211 | if (mStackBoxes.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 212 | if (stackId != HOME_STACK_ID) { |
| 213 | throw new IllegalArgumentException("createStack: First stackId not " |
| 214 | + HOME_STACK_ID); |
| 215 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 216 | StackBox newBox = new StackBox(service, this, null); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 217 | mStackBoxes.add(newBox); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 218 | newStack = new TaskStack(service, stackId, this); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 219 | newStack.mStackBox = newBox; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 220 | newBox.mStack = newStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 221 | mHomeStack = newStack; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 222 | } else { |
| 223 | int stackBoxNdx; |
| 224 | for (stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
| 225 | final StackBox box = mStackBoxes.get(stackBoxNdx); |
| 226 | if (position == StackBox.TASK_STACK_GOES_OVER |
| 227 | || position == StackBox.TASK_STACK_GOES_UNDER) { |
| 228 | // Position indicates a new box is added at top level only. |
Craig Mautner | 5a44915 | 2013-05-24 15:49:29 -0700 | [diff] [blame] | 229 | if (box.contains(relativeStackBoxId)) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 230 | StackBox newBox = new StackBox(service, this, null); |
| 231 | newStack = new TaskStack(service, stackId, this); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 232 | newStack.mStackBox = newBox; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 233 | newBox.mStack = newStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 234 | final int offset = position == StackBox.TASK_STACK_GOES_OVER ? 1 : 0; |
| 235 | if (DEBUG_STACK) Slog.d(TAG, "createStack: inserting stack at " + |
| 236 | (stackBoxNdx + offset)); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 237 | mStackBoxes.add(stackBoxNdx + offset, newBox); |
| 238 | break; |
| 239 | } |
| 240 | } else { |
| 241 | // Remaining position values indicate a box must be split. |
Craig Mautner | 5a44915 | 2013-05-24 15:49:29 -0700 | [diff] [blame] | 242 | newStack = box.split(stackId, relativeStackBoxId, position, weight); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 243 | if (newStack != null) { |
| 244 | break; |
| 245 | } |
| 246 | } |
| 247 | } |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 248 | if (stackBoxNdx < 0) { |
Craig Mautner | 5a44915 | 2013-05-24 15:49:29 -0700 | [diff] [blame] | 249 | throw new IllegalArgumentException("createStack: stackBoxId " + relativeStackBoxId |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 250 | + " not found."); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 251 | } |
| 252 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 253 | if (newStack != null) { |
| 254 | layoutNeeded = true; |
| 255 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 256 | return newStack; |
| 257 | } |
| 258 | |
Craig Mautner | 5a44915 | 2013-05-24 15:49:29 -0700 | [diff] [blame] | 259 | /** Refer to {@link WindowManagerService#resizeStackBox(int, float)} */ |
| 260 | boolean resizeStack(int stackBoxId, float weight) { |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 261 | for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 262 | final StackBox box = mStackBoxes.get(stackBoxNdx); |
Craig Mautner | 5a44915 | 2013-05-24 15:49:29 -0700 | [diff] [blame] | 263 | if (box.resize(stackBoxId, weight)) { |
| 264 | layoutNeeded = true; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 265 | return true; |
| 266 | } |
| 267 | } |
| 268 | return false; |
| 269 | } |
| 270 | |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 271 | void addStackBox(StackBox box, boolean toTop) { |
| 272 | if (mStackBoxes.size() >= 2) { |
| 273 | throw new RuntimeException("addStackBox: Too many toplevel StackBoxes!"); |
| 274 | } |
| 275 | mStackBoxes.add(toTop ? mStackBoxes.size() : 0, box); |
| 276 | } |
| 277 | |
Craig Mautner | 9e4f28c | 2013-04-03 10:53:23 -0700 | [diff] [blame] | 278 | void removeStackBox(StackBox box) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 279 | if (DEBUG_STACK) Slog.d(TAG, "removeStackBox: box=" + box); |
Craig Mautner | 9e4f28c | 2013-04-03 10:53:23 -0700 | [diff] [blame] | 280 | final TaskStack stack = box.mStack; |
| 281 | if (stack != null && stack.mStackId == HOME_STACK_ID) { |
| 282 | // Never delete the home stack, even if it is empty. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 283 | if (DEBUG_STACK) Slog.d(TAG, "removeStackBox: Not deleting home stack."); |
Craig Mautner | 9e4f28c | 2013-04-03 10:53:23 -0700 | [diff] [blame] | 284 | return; |
| 285 | } |
| 286 | mStackBoxes.remove(box); |
| 287 | } |
| 288 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 289 | StackBoxInfo getStackBoxInfo(StackBox box) { |
| 290 | StackBoxInfo info = new StackBoxInfo(); |
| 291 | info.stackBoxId = box.mStackBoxId; |
| 292 | info.weight = box.mWeight; |
| 293 | info.vertical = box.mVertical; |
| 294 | info.bounds = new Rect(box.mBounds); |
| 295 | if (box.mStack != null) { |
| 296 | info.stackId = box.mStack.mStackId; |
| 297 | // ActivityManagerService will fill in the StackInfo. |
| 298 | } else { |
| 299 | info.stackId = -1; |
| 300 | info.children = new StackBoxInfo[2]; |
| 301 | info.children[0] = getStackBoxInfo(box.mFirst); |
| 302 | info.children[1] = getStackBoxInfo(box.mSecond); |
| 303 | } |
| 304 | return info; |
| 305 | } |
| 306 | |
| 307 | ArrayList<StackBoxInfo> getStackBoxInfos() { |
| 308 | ArrayList<StackBoxInfo> list = new ArrayList<StackBoxInfo>(); |
| 309 | for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
| 310 | list.add(getStackBoxInfo(mStackBoxes.get(stackBoxNdx))); |
| 311 | } |
| 312 | return list; |
| 313 | } |
| 314 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 315 | /** |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 316 | * Move the home StackBox to the top or bottom of mStackBoxes. That is the only place |
| 317 | * it is allowed to be. This is a nop if the home StackBox is already in the correct position. |
| 318 | * @param toTop Move home to the top of mStackBoxes if true, to the bottom if false. |
| 319 | * @return true if a change was made, false otherwise. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 320 | */ |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 321 | boolean moveHomeStackBox(boolean toTop) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 322 | if (DEBUG_STACK) Slog.d(TAG, "moveHomeStackBox: toTop=" + toTop); |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 323 | switch (mStackBoxes.size()) { |
| 324 | case 0: throw new RuntimeException("moveHomeStackBox: No home StackBox!"); |
| 325 | case 1: return false; // Only the home StackBox exists. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 326 | case 2: |
| 327 | if (homeOnTop() ^ toTop) { |
| 328 | mStackBoxes.add(mStackBoxes.remove(0)); |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 329 | return true; |
| 330 | } |
| 331 | return false; |
| 332 | default: throw new RuntimeException("moveHomeStackBox: Too many toplevel StackBoxes!"); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 336 | /** |
| 337 | * Propagate the new bounds to all child stack boxes, applying weights as we move down. |
| 338 | * @param contentRect The bounds to apply at the top level. |
| 339 | */ |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 340 | boolean setStackBoxSize(Rect contentRect) { |
| 341 | boolean change = false; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 342 | for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 343 | change |= mStackBoxes.get(stackBoxNdx).setStackBoxSizes(contentRect); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 344 | } |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 345 | return change; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | Rect getStackBounds(int stackId) { |
| 349 | for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
| 350 | Rect bounds = mStackBoxes.get(stackBoxNdx).getStackBounds(stackId); |
| 351 | if (bounds != null) { |
| 352 | return bounds; |
| 353 | } |
| 354 | } |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 355 | // Not in the visible stacks, try the saved ones. |
| 356 | for (int userNdx = mUserStacks.size() - 1; userNdx >= 0; --userNdx) { |
| 357 | UserStacks userStacks = mUserStacks.valueAt(userNdx); |
| 358 | Rect bounds = userStacks.mSavedStackBox.getStackBounds(stackId); |
| 359 | if (bounds != null) { |
| 360 | return bounds; |
| 361 | } |
| 362 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 363 | return null; |
| 364 | } |
| 365 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 366 | int stackIdFromPoint(int x, int y) { |
| 367 | StackBox topBox = mStackBoxes.get(mStackBoxes.size() - 1); |
| 368 | return topBox.stackIdFromPoint(x, y); |
| 369 | } |
| 370 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 371 | void setTouchExcludeRegion(TaskStack focusedStack) { |
| 372 | mTouchExcludeRegion.set(mBaseDisplayRect); |
| 373 | WindowList windows = getWindowList(); |
| 374 | for (int i = windows.size() - 1; i >= 0; --i) { |
| 375 | final WindowState win = windows.get(i); |
| 376 | final TaskStack stack = win.getStack(); |
| 377 | if (win.isVisibleLw() && stack != null && stack != focusedStack) { |
| 378 | mTmpRect.set(win.mVisibleFrame); |
| 379 | mTmpRect.intersect(win.mVisibleInsets); |
| 380 | mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE); |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 385 | void switchUserStacks(int oldUserId, int newUserId) { |
| 386 | final WindowList windows = getWindowList(); |
| 387 | for (int i = 0; i < windows.size(); i++) { |
| 388 | final WindowState win = windows.get(i); |
| 389 | if (win.isHiddenFromUserLocked()) { |
| 390 | if (DEBUG_VISIBILITY) Slog.w(TAG, "user changing " + newUserId + " hiding " |
| 391 | + win + ", attrs=" + win.mAttrs.type + ", belonging to " |
| 392 | + win.mOwnerUid); |
| 393 | win.hideLw(false); |
| 394 | } |
| 395 | } |
| 396 | // Clear the old user's non-home StackBox |
| 397 | mUserStacks.put(oldUserId, new UserStacks()); |
| 398 | UserStacks userStacks = mUserStacks.get(newUserId); |
| 399 | if (userStacks != null) { |
| 400 | userStacks.restore(); |
| 401 | mUserStacks.delete(newUserId); |
| 402 | } |
| 403 | } |
| 404 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 405 | void resetAnimationBackgroundAnimator() { |
| 406 | for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
| 407 | mStackBoxes.get(stackBoxNdx).resetAnimationBackgroundAnimator(); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | boolean animateDimLayers() { |
| 412 | boolean result = false; |
| 413 | for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
| 414 | result |= mStackBoxes.get(stackBoxNdx).animateDimLayers(); |
| 415 | } |
| 416 | return result; |
| 417 | } |
| 418 | |
| 419 | void resetDimming() { |
| 420 | for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
| 421 | mStackBoxes.get(stackBoxNdx).resetDimming(); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | boolean isDimming() { |
| 426 | boolean result = false; |
| 427 | for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
| 428 | result |= mStackBoxes.get(stackBoxNdx).isDimming(); |
| 429 | } |
| 430 | return result; |
| 431 | } |
| 432 | |
| 433 | void stopDimmingIfNeeded() { |
| 434 | for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
| 435 | mStackBoxes.get(stackBoxNdx).stopDimmingIfNeeded(); |
| 436 | } |
| 437 | } |
| 438 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 439 | public void dump(String prefix, PrintWriter pw) { |
| 440 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 441 | final String subPrefix = " " + prefix; |
| 442 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 443 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 444 | pw.print("dpi"); |
| 445 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 446 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 447 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 448 | pw.print(" base="); |
| 449 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 450 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 451 | } |
| 452 | pw.print(" cur="); |
| 453 | pw.print(mDisplayInfo.logicalWidth); |
| 454 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 455 | pw.print(" app="); |
| 456 | pw.print(mDisplayInfo.appWidth); |
| 457 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 458 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 459 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 460 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 461 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 462 | pw.print(subPrefix); pw.print("layoutNeeded="); pw.println(layoutNeeded); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 463 | for (int boxNdx = 0; boxNdx < mStackBoxes.size(); ++boxNdx) { |
| 464 | pw.print(prefix); pw.print("StackBox #"); pw.println(boxNdx); |
| 465 | mStackBoxes.get(boxNdx).dump(prefix + " ", pw); |
| 466 | } |
| 467 | int ndx = numTokens(); |
| 468 | if (ndx > 0) { |
| 469 | pw.println(); |
| 470 | pw.println(" Application tokens in Z order:"); |
| 471 | getTasks(); |
| 472 | for (int taskNdx = mTmpTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 473 | AppTokenList tokens = mTmpTasks.get(taskNdx).mAppTokens; |
| 474 | for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 475 | final AppWindowToken wtoken = tokens.get(tokenNdx); |
| 476 | pw.print(" App #"); pw.print(ndx--); |
| 477 | pw.print(' '); pw.print(wtoken); pw.println(":"); |
| 478 | wtoken.dump(pw, " "); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 479 | } |
| 480 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 481 | } |
| 482 | if (mExitingTokens.size() > 0) { |
| 483 | pw.println(); |
| 484 | pw.println(" Exiting tokens:"); |
| 485 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 486 | WindowToken token = mExitingTokens.get(i); |
| 487 | pw.print(" Exiting #"); pw.print(i); |
| 488 | pw.print(' '); pw.print(token); |
| 489 | pw.println(':'); |
| 490 | token.dump(pw, " "); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 491 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 492 | } |
| 493 | if (mExitingAppTokens.size() > 0) { |
| 494 | pw.println(); |
| 495 | pw.println(" Exiting application tokens:"); |
| 496 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 497 | WindowToken token = mExitingAppTokens.get(i); |
| 498 | pw.print(" Exiting App #"); pw.print(i); |
| 499 | pw.print(' '); pw.print(token); |
| 500 | pw.println(':'); |
| 501 | token.dump(pw, " "); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 502 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 503 | } |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 504 | if (mUserStacks.size() > 0) { |
| 505 | pw.println(); |
| 506 | pw.println(" Saved user stacks:"); |
| 507 | for (int i = 0; i < mUserStacks.size(); ++i) { |
| 508 | UserStacks userStacks = mUserStacks.valueAt(i); |
| 509 | pw.print(" UserId="); pw.println(Integer.toHexString(mUserStacks.keyAt(i))); |
| 510 | pw.print(" StackHistory="); pw.println(userStacks.mSavedStackHistory); |
| 511 | pw.print(" StackBox="); userStacks.mSavedStackBox.dump(" ", pw); |
| 512 | } |
| 513 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 514 | pw.println(); |
| 515 | } |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 516 | |
| 517 | private final class UserStacks { |
| 518 | final ArrayList<TaskStack> mSavedStackHistory; |
| 519 | StackBox mSavedStackBox; |
| 520 | int mBoxNdx; |
| 521 | |
| 522 | public UserStacks() { |
| 523 | mSavedStackHistory = new ArrayList<TaskStack>(mStackHistory); |
| 524 | for (int stackNdx = mStackHistory.size() - 1; stackNdx >=0; --stackNdx) { |
| 525 | if (mStackHistory.get(stackNdx) != mHomeStack) { |
| 526 | mStackHistory.remove(stackNdx); |
| 527 | } |
| 528 | } |
| 529 | mSavedStackBox = null; |
| 530 | mBoxNdx = -1; |
| 531 | for (int boxNdx = mStackBoxes.size() - 1; boxNdx >= 0; --boxNdx) { |
| 532 | StackBox box = mStackBoxes.get(boxNdx); |
| 533 | if (box.mStack != mHomeStack) { |
| 534 | mSavedStackBox = box; |
| 535 | mBoxNdx = boxNdx; |
| 536 | mStackBoxes.remove(boxNdx); |
| 537 | break; |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | void restore() { |
| 543 | mStackHistory = mSavedStackHistory; |
| 544 | if (mBoxNdx >= 0) { |
| 545 | mStackBoxes.add(mBoxNdx, mSavedStackBox); |
| 546 | } |
| 547 | } |
| 548 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 549 | } |