blob: 885eb500cdb20e245180906ffcdd985b48c95daa [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);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800120 mService.mWindowPlacerLocked.performSurfacePlacement();
121 }
122 }
123
124 public void setResizeable(int resizeMode) {
125 synchronized (mWindowMap) {
126 if (mContainer != null) {
127 mContainer.setResizeable(resizeMode);
128 }
129 }
130 }
131
132 public void resize(Rect bounds, Configuration overrideConfig, boolean relayout,
133 boolean forced) {
134 synchronized (mWindowMap) {
135 if (mContainer == null) {
136 throw new IllegalArgumentException("resizeTask: taskId " + mTaskId + " not found.");
137 }
138
139 if (mContainer.resizeLocked(bounds, overrideConfig, forced) && relayout) {
140 mContainer.getDisplayContent().setLayoutNeeded();
141 mService.mWindowPlacerLocked.performSurfacePlacement();
142 }
143 }
144 }
145
146 // TODO: Move to positionChildAt() in stack controller once we have a stack controller.
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800147 public void positionAt(int position, Rect bounds, Configuration overrideConfig) {
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800148 synchronized (mWindowMap) {
149 if (DEBUG_STACK) Slog.i(TAG_WM, "positionChildAt: positioning taskId=" + mTaskId
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800150 + " at " + position);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800151 if (mContainer == null) {
152 if (DEBUG_STACK) Slog.i(TAG_WM,
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800153 "positionAt: could not find taskId=" + mTaskId);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800154 return;
155 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800156 final TaskStack stack = mContainer.mStack;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800157 if (stack == null) {
158 if (DEBUG_STACK) Slog.i(TAG_WM,
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800159 "positionAt: could not find stack for task=" + mContainer);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800160 return;
161 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800162 mContainer.positionAt(position, bounds, overrideConfig);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800163 final DisplayContent displayContent = stack.getDisplayContent();
164 displayContent.setLayoutNeeded();
165 mService.mWindowPlacerLocked.performSurfacePlacement();
166 }
167 }
168
169 // TODO: Replace with moveChildToTop in stack controller?
170 public void moveToTop(boolean includingParents) {
171 synchronized(mWindowMap) {
172 if (mContainer == null) {
173 Slog.e(TAG_WM, "moveToTop: taskId=" + mTaskId + " not found");
174 return;
175 }
176 final TaskStack stack = mContainer.mStack;
177 stack.positionChildAt(POSITION_TOP, mContainer, includingParents);
178
179 if (mService.mAppTransition.isTransitionSet()) {
180 mContainer.setSendingToBottom(false);
181 }
182 stack.getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
183 }
184 }
185
186 // TODO: Replace with moveChildToBottom in stack controller?
187 public void moveToBottom() {
188 synchronized(mWindowMap) {
189 if (mContainer == null) {
190 Slog.e(TAG_WM, "moveTaskToBottom: taskId=" + mTaskId + " not found");
191 return;
192 }
193 final TaskStack stack = mContainer.mStack;
194 stack.positionChildAt(POSITION_BOTTOM, mContainer, false /* includingParents */);
195 if (mService.mAppTransition.isTransitionSet()) {
196 mContainer.setSendingToBottom(true);
197 }
198 stack.getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
199 }
200 }
201
202 public void getBounds(Rect bounds) {
203 synchronized (mWindowMap) {
204 if (mContainer != null) {
205 mContainer.getBounds(bounds);
206 return;
207 }
208 bounds.setEmpty();
209 }
210 }
211
212 /**
213 * Puts this task into docked drag resizing mode. See {@link DragResizeMode}.
214 *
215 * @param resizing Whether to put the task into drag resize mode.
216 */
217 public void setTaskDockedResizing(boolean resizing) {
218 synchronized (mWindowMap) {
219 if (mContainer == null) {
220 Slog.w(TAG_WM, "setTaskDockedResizing: taskId " + mTaskId + " not found.");
221 return;
222 }
223 mContainer.setDragResizing(resizing, DRAG_RESIZE_MODE_DOCKED_DIVIDER);
224 }
225 }
226
227 public void cancelWindowTransition() {
228 synchronized (mWindowMap) {
229 if (mContainer == null) {
230 Slog.w(TAG_WM, "cancelWindowTransition: taskId " + mTaskId + " not found.");
231 return;
232 }
233 mContainer.cancelTaskWindowTransition();
234 }
235 }
236
237 public void cancelThumbnailTransition() {
238 synchronized (mWindowMap) {
239 if (mContainer == null) {
240 Slog.w(TAG_WM, "cancelThumbnailTransition: taskId " + mTaskId + " not found.");
241 return;
242 }
243 mContainer.cancelTaskThumbnailTransition();
244 }
245 }
246
Jorim Jaggi02886a82016-12-06 09:10:06 -0800247 /**
248 * @return a graphic buffer representing a screenshot of a task
249 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +0100250 public TaskSnapshot getSnapshot() {
Jorim Jaggi02886a82016-12-06 09:10:06 -0800251 synchronized (mWindowMap) {
252 if (mContainer == null) {
253 Slog.w(TAG_WM, "getSnapshot: taskId " + mTaskId + " not found.");
254 return null;
255 }
256 return mService.mTaskSnapshotController.getSnapshot(mContainer);
257 }
258 }
259
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800260 @Override
261 public String toString() {
262 return "{TaskWindowContainerController taskId=" + mTaskId + "}";
263 }
264}