blob: bbc9ed2ef332793f9d55a44a82f4a599c8f78713 [file] [log] [blame]
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -08001/*
2 * Copyright (C) 2016 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
Jorim Jaggie2c77f92016-12-29 14:57:22 +010019import android.app.ActivityManager.TaskSnapshot;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080020import android.content.res.Configuration;
21import android.graphics.Rect;
22import android.util.EventLog;
23import android.util.Slog;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080024import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080025
26import static com.android.server.EventLogTags.WM_TASK_CREATED;
27import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
28import static com.android.server.wm.WindowContainer.POSITION_BOTTOM;
29import static com.android.server.wm.WindowContainer.POSITION_TOP;
30import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
31import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
32
33/**
34 * Controller for the task container. This is created by activity manager to link task records to
35 * the task container they use in window manager.
36 *
37 * Test class: {@link TaskWindowContainerControllerTests}
38 */
39public class TaskWindowContainerController
40 extends WindowContainerController<Task, WindowContainerListener> {
41
42 private final int mTaskId;
43
44 public TaskWindowContainerController(int taskId, int stackId, int userId, Rect bounds,
45 Configuration overrideConfig, int resizeMode, boolean homeTask, boolean isOnTopLauncher,
46 boolean toTop, boolean showForAllUsers) {
47 super(null, WindowManagerService.getInstance());
48 mTaskId = taskId;
49
50 synchronized(mWindowMap) {
51 if (DEBUG_STACK) Slog.i(TAG_WM, "TaskWindowContainerController: taskId=" + taskId
52 + " stackId=" + stackId + " bounds=" + bounds);
53
54 // TODO: Pass controller for the stack to get the container object when stack is
55 // switched to use controller.
56 final TaskStack stack = mService.mStackIdToStack.get(stackId);
57 if (stack == null) {
58 throw new IllegalArgumentException("TaskWindowContainerController: invalid stackId="
59 + stackId);
60 }
61 EventLog.writeEvent(WM_TASK_CREATED, taskId, stackId);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080062 final Task task = createTask(taskId, stack, userId, bounds, overrideConfig, resizeMode,
63 homeTask, isOnTopLauncher);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080064 final int position = toTop ? POSITION_TOP : POSITION_BOTTOM;
65 stack.addTask(task, position, showForAllUsers, true /* moveParents */);
66 }
67 }
68
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080069 @VisibleForTesting
70 Task createTask(int taskId, TaskStack stack, int userId, Rect bounds,
71 Configuration overrideConfig, int resizeMode, boolean homeTask,
72 boolean isOnTopLauncher) {
73 return new Task(taskId, stack, userId, mService, bounds, overrideConfig, isOnTopLauncher,
74 resizeMode, homeTask, this);
75 }
76
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080077 @Override
78 public void removeContainer() {
79 synchronized(mWindowMap) {
80 if (mContainer == null) {
81 if (DEBUG_STACK) Slog.i(TAG_WM, "removeTask: could not find taskId=" + mTaskId);
82 return;
83 }
84 mContainer.removeIfPossible();
85 super.removeContainer();
86 }
87 }
88
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080089 public void positionChildAt(AppWindowContainerController childController, int position) {
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080090 synchronized(mService.mWindowMap) {
91 final AppWindowToken aToken = childController.mContainer;
92 if (aToken == null) {
93 Slog.w(TAG_WM,
94 "Attempted to position of non-existing app : " + childController);
95 return;
96 }
97
98 final Task task = mContainer;
99 if (task == null) {
100 throw new IllegalArgumentException("positionChildAt: invalid task=" + this);
101 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800102 task.positionChildAt(position, aToken, false /* includeParents */);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800103 }
104 }
105
106 public void reparent(int stackId, int position) {
107 synchronized (mWindowMap) {
108 if (DEBUG_STACK) Slog.i(TAG_WM, "reparent: moving taskId=" + mTaskId
109 + " to stackId=" + stackId + " at " + position);
110 if (mContainer == null) {
111 if (DEBUG_STACK) Slog.i(TAG_WM,
112 "reparent: could not find taskId=" + mTaskId);
113 return;
114 }
115 final TaskStack stack = mService.mStackIdToStack.get(stackId);
116 if (stack == null) {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800117 throw new IllegalArgumentException("reparent: could not find stackId=" + stackId);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800118 }
119 mContainer.reparent(stack, position);
120 final DisplayContent displayContent = stack.getDisplayContent();
121 displayContent.setLayoutNeeded();
122 mService.mWindowPlacerLocked.performSurfacePlacement();
123 }
124 }
125
126 public void setResizeable(int resizeMode) {
127 synchronized (mWindowMap) {
128 if (mContainer != null) {
129 mContainer.setResizeable(resizeMode);
130 }
131 }
132 }
133
134 public void resize(Rect bounds, Configuration overrideConfig, boolean relayout,
135 boolean forced) {
136 synchronized (mWindowMap) {
137 if (mContainer == null) {
138 throw new IllegalArgumentException("resizeTask: taskId " + mTaskId + " not found.");
139 }
140
141 if (mContainer.resizeLocked(bounds, overrideConfig, forced) && relayout) {
142 mContainer.getDisplayContent().setLayoutNeeded();
143 mService.mWindowPlacerLocked.performSurfacePlacement();
144 }
145 }
146 }
147
148 // TODO: Move to positionChildAt() in stack controller once we have a stack controller.
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800149 public void positionAt(int position, Rect bounds, Configuration overrideConfig) {
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800150 synchronized (mWindowMap) {
151 if (DEBUG_STACK) Slog.i(TAG_WM, "positionChildAt: positioning taskId=" + mTaskId
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800152 + " at " + position);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800153 if (mContainer == null) {
154 if (DEBUG_STACK) Slog.i(TAG_WM,
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800155 "positionAt: could not find taskId=" + mTaskId);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800156 return;
157 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800158 final TaskStack stack = mContainer.mStack;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800159 if (stack == null) {
160 if (DEBUG_STACK) Slog.i(TAG_WM,
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800161 "positionAt: could not find stack for task=" + mContainer);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800162 return;
163 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800164 mContainer.positionAt(position, bounds, overrideConfig);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800165 final DisplayContent displayContent = stack.getDisplayContent();
166 displayContent.setLayoutNeeded();
167 mService.mWindowPlacerLocked.performSurfacePlacement();
168 }
169 }
170
171 // TODO: Replace with moveChildToTop in stack controller?
172 public void moveToTop(boolean includingParents) {
173 synchronized(mWindowMap) {
174 if (mContainer == null) {
175 Slog.e(TAG_WM, "moveToTop: taskId=" + mTaskId + " not found");
176 return;
177 }
178 final TaskStack stack = mContainer.mStack;
179 stack.positionChildAt(POSITION_TOP, mContainer, includingParents);
180
181 if (mService.mAppTransition.isTransitionSet()) {
182 mContainer.setSendingToBottom(false);
183 }
184 stack.getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
185 }
186 }
187
188 // TODO: Replace with moveChildToBottom in stack controller?
189 public void moveToBottom() {
190 synchronized(mWindowMap) {
191 if (mContainer == null) {
192 Slog.e(TAG_WM, "moveTaskToBottom: taskId=" + mTaskId + " not found");
193 return;
194 }
195 final TaskStack stack = mContainer.mStack;
196 stack.positionChildAt(POSITION_BOTTOM, mContainer, false /* includingParents */);
197 if (mService.mAppTransition.isTransitionSet()) {
198 mContainer.setSendingToBottom(true);
199 }
200 stack.getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
201 }
202 }
203
204 public void getBounds(Rect bounds) {
205 synchronized (mWindowMap) {
206 if (mContainer != null) {
207 mContainer.getBounds(bounds);
208 return;
209 }
210 bounds.setEmpty();
211 }
212 }
213
214 /**
215 * Puts this task into docked drag resizing mode. See {@link DragResizeMode}.
216 *
217 * @param resizing Whether to put the task into drag resize mode.
218 */
219 public void setTaskDockedResizing(boolean resizing) {
220 synchronized (mWindowMap) {
221 if (mContainer == null) {
222 Slog.w(TAG_WM, "setTaskDockedResizing: taskId " + mTaskId + " not found.");
223 return;
224 }
225 mContainer.setDragResizing(resizing, DRAG_RESIZE_MODE_DOCKED_DIVIDER);
226 }
227 }
228
229 public void cancelWindowTransition() {
230 synchronized (mWindowMap) {
231 if (mContainer == null) {
232 Slog.w(TAG_WM, "cancelWindowTransition: taskId " + mTaskId + " not found.");
233 return;
234 }
235 mContainer.cancelTaskWindowTransition();
236 }
237 }
238
239 public void cancelThumbnailTransition() {
240 synchronized (mWindowMap) {
241 if (mContainer == null) {
242 Slog.w(TAG_WM, "cancelThumbnailTransition: taskId " + mTaskId + " not found.");
243 return;
244 }
245 mContainer.cancelTaskThumbnailTransition();
246 }
247 }
248
Jorim Jaggi02886a82016-12-06 09:10:06 -0800249 /**
250 * @return a graphic buffer representing a screenshot of a task
251 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +0100252 public TaskSnapshot getSnapshot() {
Jorim Jaggi02886a82016-12-06 09:10:06 -0800253 synchronized (mWindowMap) {
254 if (mContainer == null) {
255 Slog.w(TAG_WM, "getSnapshot: taskId " + mTaskId + " not found.");
256 return null;
257 }
258 return mService.mTaskSnapshotController.getSnapshot(mContainer);
259 }
260 }
261
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800262 @Override
263 public String toString() {
264 return "{TaskWindowContainerController taskId=" + mTaskId + "}";
265 }
266}