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 | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame^] | 19 | import android.util.SparseArray; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 20 | import android.view.Display; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 21 | import android.view.DisplayInfo; |
| 22 | |
| 23 | import java.io.PrintWriter; |
| 24 | import java.util.ArrayList; |
| 25 | |
| 26 | class DisplayContentList extends ArrayList<DisplayContent> { |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 31 | * particular Display. |
| 32 | * |
| 33 | * IMPORTANT: No method from this class should ever be used without holding |
| 34 | * WindowManagerService.mWindowMap. |
| 35 | */ |
| 36 | class DisplayContent { |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame^] | 37 | // private final static String TAG = "DisplayContent"; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 38 | |
| 39 | /** Unique identifier of this stack. */ |
| 40 | private final int mDisplayId; |
| 41 | |
| 42 | /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element |
| 43 | * from mDisplayWindows; */ |
| 44 | private WindowList mWindows = new WindowList(); |
| 45 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 46 | // This protects the following display size properties, so that |
| 47 | // getDisplaySize() doesn't need to acquire the global lock. This is |
| 48 | // needed because the window manager sometimes needs to use ActivityThread |
| 49 | // while it has its global state locked (for example to load animation |
| 50 | // resources), but the ActivityThread also needs get the current display |
| 51 | // size sometimes when it has its package lock held. |
| 52 | // |
| 53 | // These will only be modified with both mWindowMap and mDisplaySizeLock |
| 54 | // held (in that order) so the window manager doesn't need to acquire this |
| 55 | // lock when needing these values in its normal operation. |
| 56 | final Object mDisplaySizeLock = new Object(); |
| 57 | int mInitialDisplayWidth = 0; |
| 58 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 59 | int mInitialDisplayDensity = 0; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 60 | int mBaseDisplayWidth = 0; |
| 61 | int mBaseDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 62 | int mBaseDisplayDensity = 0; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 63 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 64 | private final Display mDisplay; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 65 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 66 | // Accessed directly by all users. |
| 67 | boolean layoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 68 | int pendingLayoutChanges; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 69 | final boolean isDefaultDisplay; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 70 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 71 | /** |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame^] | 72 | * List controlling the ordering of windows in different applications which must |
| 73 | * be kept in sync with ActivityManager. |
| 74 | */ |
| 75 | final AppTokenList mAppTokens = new AppTokenList(); |
| 76 | |
| 77 | /** |
| 78 | * AppWindowTokens in the Z order they were in at the start of an animation. Between |
| 79 | * animations this list is maintained in the exact order of mAppTokens. If tokens |
| 80 | * are added to mAppTokens during an animation an attempt is made to insert them at the same |
| 81 | * logical location in this list. Note that this list is always in sync with mWindows. |
| 82 | */ |
| 83 | AppTokenList mAnimatingAppTokens = new AppTokenList(); |
| 84 | |
| 85 | /** |
| 86 | * Window tokens that are in the process of exiting, but still |
| 87 | * on screen for animations. |
| 88 | */ |
| 89 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 90 | |
| 91 | /** |
| 92 | * Application tokens that are in the process of exiting, but still |
| 93 | * on screen for animations. |
| 94 | */ |
| 95 | final AppTokenList mExitingAppTokens = new AppTokenList(); |
| 96 | |
| 97 | /** |
| 98 | * Sorted most recent at top, oldest at [0]. |
| 99 | */ |
| 100 | // ArrayList<TaskList> mTaskLists = new ArrayList<TaskList>(); |
| 101 | SparseArray<TaskList> mTaskIdToTaskList = new SparseArray<TaskList>(); |
| 102 | |
| 103 | /** |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 104 | * @param display May not be null. |
| 105 | */ |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 106 | DisplayContent(Display display) { |
| 107 | mDisplay = display; |
| 108 | mDisplayId = display.getDisplayId(); |
| 109 | display.getDisplayInfo(mDisplayInfo); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 110 | isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | int getDisplayId() { |
| 114 | return mDisplayId; |
| 115 | } |
| 116 | |
| 117 | WindowList getWindowList() { |
| 118 | return mWindows; |
| 119 | } |
| 120 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 121 | Display getDisplay() { |
| 122 | return mDisplay; |
| 123 | } |
| 124 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 125 | DisplayInfo getDisplayInfo() { |
| 126 | return mDisplayInfo; |
| 127 | } |
| 128 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 129 | public void updateDisplayInfo() { |
| 130 | mDisplay.getDisplayInfo(mDisplayInfo); |
| 131 | } |
| 132 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame^] | 133 | /** |
| 134 | * Find the location to insert a new AppWindowToken into the window-ordered app token list. |
| 135 | * @param addPos The location the token was inserted into in mAppTokens. |
| 136 | * @param atoken The token to insert. |
| 137 | */ |
| 138 | void addAppToken(final int addPos, final AppWindowToken atoken) { |
| 139 | mAppTokens.add(addPos, atoken); |
| 140 | |
| 141 | if (addPos == 0 || addPos == mAnimatingAppTokens.size()) { |
| 142 | // It was inserted into the beginning or end of mAppTokens. Honor that. |
| 143 | mAnimatingAppTokens.add(addPos, atoken); |
| 144 | } else { |
| 145 | // Find the item immediately above the mAppTokens insertion point and put the token |
| 146 | // immediately below that one in mAnimatingAppTokens. |
| 147 | final AppWindowToken aboveAnchor = mAppTokens.get(addPos + 1); |
| 148 | mAnimatingAppTokens.add(mAnimatingAppTokens.indexOf(aboveAnchor), atoken); |
| 149 | } |
| 150 | |
| 151 | TaskList task = mTaskIdToTaskList.get(atoken.groupId); |
| 152 | if (task == null) { |
| 153 | mTaskIdToTaskList.put(atoken.groupId, new TaskList(atoken)); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | void removeAppToken(final AppWindowToken wtoken) { |
| 158 | mAppTokens.remove(wtoken); |
| 159 | mAnimatingAppTokens.remove(wtoken); |
| 160 | final int taskId = wtoken.groupId; |
| 161 | final TaskList task = mTaskIdToTaskList.get(taskId); |
| 162 | if (task != null) { |
| 163 | AppTokenList appTokens = task.mAppTokens; |
| 164 | appTokens.remove(wtoken); |
| 165 | if (appTokens.size() == 0) { |
| 166 | mTaskIdToTaskList.delete(taskId); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void refillAnimatingAppTokens() { |
| 172 | mAnimatingAppTokens.clear(); |
| 173 | mAnimatingAppTokens.addAll(mAppTokens); |
| 174 | } |
| 175 | |
| 176 | void setAppTaskId(AppWindowToken wtoken, int newTaskId) { |
| 177 | final int taskId = wtoken.groupId; |
| 178 | TaskList task = mTaskIdToTaskList.get(taskId); |
| 179 | if (task != null) { |
| 180 | AppTokenList appTokens = task.mAppTokens; |
| 181 | appTokens.remove(wtoken); |
| 182 | if (appTokens.size() == 0) { |
| 183 | mTaskIdToTaskList.delete(taskId); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | task = mTaskIdToTaskList.get(newTaskId); |
| 188 | if (task == null) { |
| 189 | task = new TaskList(wtoken); |
| 190 | mTaskIdToTaskList.put(newTaskId, task); |
| 191 | } else { |
| 192 | task.mAppTokens.add(wtoken); |
| 193 | } |
| 194 | |
| 195 | wtoken.groupId = newTaskId; |
| 196 | } |
| 197 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 198 | public void dump(String prefix, PrintWriter pw) { |
| 199 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 200 | final String subPrefix = " " + prefix; |
| 201 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 202 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 203 | pw.print("dpi"); |
| 204 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 205 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 206 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 207 | pw.print(" base="); |
| 208 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 209 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 210 | } |
| 211 | pw.print(" cur="); |
| 212 | pw.print(mDisplayInfo.logicalWidth); |
| 213 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 214 | pw.print(" app="); |
| 215 | pw.print(mDisplayInfo.appWidth); |
| 216 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 217 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 218 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 219 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 220 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame^] | 221 | if (mAppTokens.size() > 0) { |
| 222 | pw.println(); |
| 223 | pw.println(" Application tokens in Z order:"); |
| 224 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| 225 | pw.print(" App #"); pw.print(i); |
| 226 | pw.print(' '); pw.print(mAppTokens.get(i)); pw.println(":"); |
| 227 | mAppTokens.get(i).dump(pw, " "); |
| 228 | } |
| 229 | } |
| 230 | if (mExitingTokens.size() > 0) { |
| 231 | pw.println(); |
| 232 | pw.println(" Exiting tokens:"); |
| 233 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 234 | WindowToken token = mExitingTokens.get(i); |
| 235 | pw.print(" Exiting #"); pw.print(i); |
| 236 | pw.print(' '); pw.print(token); |
| 237 | pw.println(':'); |
| 238 | token.dump(pw, " "); |
| 239 | } |
| 240 | } |
| 241 | if (mExitingAppTokens.size() > 0) { |
| 242 | pw.println(); |
| 243 | pw.println(" Exiting application tokens:"); |
| 244 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 245 | WindowToken token = mExitingAppTokens.get(i); |
| 246 | pw.print(" Exiting App #"); pw.print(i); |
| 247 | pw.print(' '); pw.print(token); |
| 248 | pw.println(':'); |
| 249 | token.dump(pw, " "); |
| 250 | } |
| 251 | } |
| 252 | if (mTaskIdToTaskList.size() > 0) { |
| 253 | pw.println(); |
| 254 | for (int i = 0; i < mTaskIdToTaskList.size(); ++i) { |
| 255 | pw.print(" TaskList #"); pw.print(i); |
| 256 | pw.print(" taskId="); pw.println(mTaskIdToTaskList.keyAt(i)); |
| 257 | pw.print(" mAppTokens="); |
| 258 | pw.println(mTaskIdToTaskList.valueAt(i).mAppTokens); |
| 259 | pw.println(); |
| 260 | } |
| 261 | } |
| 262 | pw.print(subPrefix); pw.print("layoutNeeded="); pw.println(layoutNeeded); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 263 | pw.println(); |
| 264 | } |
| 265 | } |