blob: 33b7a5d390fc9d41f5c953dd5f165e3a9243a477 [file] [log] [blame]
Craig Mautner59c00972012-07-30 12:10:24 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080019import android.util.SparseArray;
Craig Mautnerb47bbc32012-08-22 17:41:48 -070020import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -070021import android.view.DisplayInfo;
22
23import java.io.PrintWriter;
24import java.util.ArrayList;
25
26class 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 */
36class DisplayContent {
Craig Mautner496bdbb2013-02-14 09:32:55 -080037// private final static String TAG = "DisplayContent";
Craig Mautner59c00972012-07-30 12:10:24 -070038
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 Mautner59c00972012-07-30 12:10:24 -070046 // 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 Hackborndde331c2012-08-03 14:01:57 -070059 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -070060 int mBaseDisplayWidth = 0;
61 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070062 int mBaseDisplayDensity = 0;
Craig Mautner2d5618c2012-10-18 13:55:47 -070063 private final DisplayInfo mDisplayInfo = new DisplayInfo();
64 private final Display mDisplay;
Craig Mautner59c00972012-07-30 12:10:24 -070065
Craig Mautner39834192012-09-02 07:47:24 -070066 // Accessed directly by all users.
67 boolean layoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -070068 int pendingLayoutChanges;
Craig Mautner69b08182012-09-05 13:07:13 -070069 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -070070
Craig Mautner2d5618c2012-10-18 13:55:47 -070071 /**
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080072 * Window tokens that are in the process of exiting, but still
73 * on screen for animations.
74 */
75 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
76
77 /**
78 * Application tokens that are in the process of exiting, but still
79 * on screen for animations.
80 */
81 final AppTokenList mExitingAppTokens = new AppTokenList();
82
83 /**
84 * Sorted most recent at top, oldest at [0].
85 */
Craig Mautner05d6272ba2013-02-11 09:39:27 -080086 ArrayList<TaskList> mTaskLists = new ArrayList<TaskList>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080087 SparseArray<TaskList> mTaskIdToTaskList = new SparseArray<TaskList>();
88
89 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -070090 * @param display May not be null.
91 */
Craig Mautnerb47bbc32012-08-22 17:41:48 -070092 DisplayContent(Display display) {
93 mDisplay = display;
94 mDisplayId = display.getDisplayId();
95 display.getDisplayInfo(mDisplayInfo);
Craig Mautner69b08182012-09-05 13:07:13 -070096 isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
Craig Mautner59c00972012-07-30 12:10:24 -070097 }
98
99 int getDisplayId() {
100 return mDisplayId;
101 }
102
103 WindowList getWindowList() {
104 return mWindows;
105 }
106
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700107 Display getDisplay() {
108 return mDisplay;
109 }
110
Craig Mautner59c00972012-07-30 12:10:24 -0700111 DisplayInfo getDisplayInfo() {
112 return mDisplayInfo;
113 }
114
Craig Mautner722285e2012-09-07 13:55:58 -0700115 public void updateDisplayInfo() {
116 mDisplay.getDisplayInfo(mDisplayInfo);
117 }
118
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800119 /**
120 * Find the location to insert a new AppWindowToken into the window-ordered app token list.
121 * @param addPos The location the token was inserted into in mAppTokens.
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800122 * @param wtoken The token to insert.
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800123 */
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800124 void addAppToken(final int addPos, final AppWindowToken wtoken) {
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800125 TaskList task = mTaskIdToTaskList.get(wtoken.groupId);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800126 if (task == null) {
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800127 task = new TaskList(wtoken, this);
128 mTaskIdToTaskList.put(wtoken.groupId, task);
129 mTaskLists.add(task);
130 } else {
Craig Mautner11bf9a52013-02-19 14:08:51 -0800131 task.mAppTokens.add(addPos, wtoken);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800132 }
133 }
134
135 void removeAppToken(final AppWindowToken wtoken) {
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800136 final int taskId = wtoken.groupId;
137 final TaskList task = mTaskIdToTaskList.get(taskId);
138 if (task != null) {
139 AppTokenList appTokens = task.mAppTokens;
140 appTokens.remove(wtoken);
141 if (appTokens.size() == 0) {
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800142 mTaskLists.remove(task);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800143 mTaskIdToTaskList.delete(taskId);
144 }
145 }
146 }
147
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800148 void setAppTaskId(AppWindowToken wtoken, int newTaskId) {
149 final int taskId = wtoken.groupId;
150 TaskList task = mTaskIdToTaskList.get(taskId);
151 if (task != null) {
152 AppTokenList appTokens = task.mAppTokens;
153 appTokens.remove(wtoken);
154 if (appTokens.size() == 0) {
155 mTaskIdToTaskList.delete(taskId);
156 }
157 }
158
159 task = mTaskIdToTaskList.get(newTaskId);
160 if (task == null) {
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800161 task = new TaskList(wtoken, this);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800162 mTaskIdToTaskList.put(newTaskId, task);
163 } else {
164 task.mAppTokens.add(wtoken);
165 }
166
167 wtoken.groupId = newTaskId;
168 }
169
Craig Mautnerf81b90872013-02-26 13:02:43 -0800170 int numTokens() {
171 int count = 0;
172 for (int taskNdx = mTaskLists.size() - 1; taskNdx >= 0; --taskNdx) {
173 count += mTaskLists.get(taskNdx).mAppTokens.size();
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800174 }
Craig Mautnerf81b90872013-02-26 13:02:43 -0800175 return count;
Craig Mautner05d6272ba2013-02-11 09:39:27 -0800176 }
177
Craig Mautnera91f9e22012-09-14 16:22:08 -0700178 public void dump(String prefix, PrintWriter pw) {
179 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
180 final String subPrefix = " " + prefix;
181 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
182 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
183 pw.print("dpi");
184 if (mInitialDisplayWidth != mBaseDisplayWidth
185 || mInitialDisplayHeight != mBaseDisplayHeight
186 || mInitialDisplayDensity != mBaseDisplayDensity) {
187 pw.print(" base=");
188 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
189 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
190 }
191 pw.print(" cur=");
192 pw.print(mDisplayInfo.logicalWidth);
193 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
194 pw.print(" app=");
195 pw.print(mDisplayInfo.appWidth);
196 pw.print("x"); pw.print(mDisplayInfo.appHeight);
197 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
198 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
199 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
200 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Dianne Hackbornc652de82013-02-15 16:32:56 -0800201 pw.print(subPrefix); pw.print("layoutNeeded="); pw.println(layoutNeeded);
Craig Mautnerf81b90872013-02-26 13:02:43 -0800202 int ndx = numTokens();
203 if (ndx > 0) {
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800204 pw.println();
205 pw.println(" Application tokens in Z order:");
Craig Mautnerf81b90872013-02-26 13:02:43 -0800206 for (int taskNdx = mTaskLists.size() - 1; taskNdx >= 0; --taskNdx) {
207 AppTokenList tokens = mTaskLists.get(taskNdx).mAppTokens;
208 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
209 final AppWindowToken wtoken = tokens.get(tokenNdx);
210 pw.print(" App #"); pw.print(ndx--);
211 pw.print(' '); pw.print(wtoken); pw.println(":");
212 wtoken.dump(pw, " ");
213 }
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800214 }
215 }
216 if (mExitingTokens.size() > 0) {
217 pw.println();
218 pw.println(" Exiting tokens:");
219 for (int i=mExitingTokens.size()-1; i>=0; i--) {
220 WindowToken token = mExitingTokens.get(i);
221 pw.print(" Exiting #"); pw.print(i);
222 pw.print(' '); pw.print(token);
223 pw.println(':');
224 token.dump(pw, " ");
225 }
226 }
227 if (mExitingAppTokens.size() > 0) {
228 pw.println();
229 pw.println(" Exiting application tokens:");
230 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
231 WindowToken token = mExitingAppTokens.get(i);
232 pw.print(" Exiting App #"); pw.print(i);
233 pw.print(' '); pw.print(token);
234 pw.println(':');
235 token.dump(pw, " ");
236 }
237 }
238 if (mTaskIdToTaskList.size() > 0) {
239 pw.println();
240 for (int i = 0; i < mTaskIdToTaskList.size(); ++i) {
241 pw.print(" TaskList #"); pw.print(i);
242 pw.print(" taskId="); pw.println(mTaskIdToTaskList.keyAt(i));
243 pw.print(" mAppTokens=");
244 pw.println(mTaskIdToTaskList.valueAt(i).mAppTokens);
245 pw.println();
246 }
247 }
Craig Mautner59c00972012-07-30 12:10:24 -0700248 pw.println();
249 }
250}