blob: 9c303f811590e9ed08d229e347fb65baadf89591 [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
19import android.content.res.Configuration;
20import android.graphics.Rect;
21import android.util.EventLog;
22import android.util.Slog;
23
24import static com.android.server.EventLogTags.WM_TASK_CREATED;
25import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
26import static com.android.server.wm.WindowContainer.POSITION_BOTTOM;
27import static com.android.server.wm.WindowContainer.POSITION_TOP;
28import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
29import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
30
31/**
32 * Controller for the task container. This is created by activity manager to link task records to
33 * the task container they use in window manager.
34 *
35 * Test class: {@link TaskWindowContainerControllerTests}
36 */
37public class TaskWindowContainerController
38 extends WindowContainerController<Task, WindowContainerListener> {
39
40 private final int mTaskId;
41
42 public TaskWindowContainerController(int taskId, int stackId, int userId, Rect bounds,
43 Configuration overrideConfig, int resizeMode, boolean homeTask, boolean isOnTopLauncher,
44 boolean toTop, boolean showForAllUsers) {
45 super(null, WindowManagerService.getInstance());
46 mTaskId = taskId;
47
48 synchronized(mWindowMap) {
49 if (DEBUG_STACK) Slog.i(TAG_WM, "TaskWindowContainerController: taskId=" + taskId
50 + " stackId=" + stackId + " bounds=" + bounds);
51
52 // TODO: Pass controller for the stack to get the container object when stack is
53 // switched to use controller.
54 final TaskStack stack = mService.mStackIdToStack.get(stackId);
55 if (stack == null) {
56 throw new IllegalArgumentException("TaskWindowContainerController: invalid stackId="
57 + stackId);
58 }
59 EventLog.writeEvent(WM_TASK_CREATED, taskId, stackId);
60 final Task task = new Task(taskId, stack, userId, mService, bounds, overrideConfig,
61 isOnTopLauncher, resizeMode, homeTask, this);
62 final int position = toTop ? POSITION_TOP : POSITION_BOTTOM;
63 stack.addTask(task, position, showForAllUsers, true /* moveParents */);
64 }
65 }
66
67 @Override
68 public void removeContainer() {
69 synchronized(mWindowMap) {
70 if (mContainer == null) {
71 if (DEBUG_STACK) Slog.i(TAG_WM, "removeTask: could not find taskId=" + mTaskId);
72 return;
73 }
74 mContainer.removeIfPossible();
75 super.removeContainer();
76 }
77 }
78
79 public void positionChildAt(AppWindowContainerController childController, int index) {
80 synchronized(mService.mWindowMap) {
81 final AppWindowToken aToken = childController.mContainer;
82 if (aToken == null) {
83 Slog.w(TAG_WM,
84 "Attempted to position of non-existing app : " + childController);
85 return;
86 }
87
88 final Task task = mContainer;
89 if (task == null) {
90 throw new IllegalArgumentException("positionChildAt: invalid task=" + this);
91 }
92 task.addChild(aToken, index);
93 }
94 }
95
96 public void reparent(int stackId, int position) {
97 synchronized (mWindowMap) {
98 if (DEBUG_STACK) Slog.i(TAG_WM, "reparent: moving taskId=" + mTaskId
99 + " to stackId=" + stackId + " at " + position);
100 if (mContainer == null) {
101 if (DEBUG_STACK) Slog.i(TAG_WM,
102 "reparent: could not find taskId=" + mTaskId);
103 return;
104 }
105 final TaskStack stack = mService.mStackIdToStack.get(stackId);
106 if (stack == null) {
107 if (DEBUG_STACK) Slog.i(TAG_WM,
108 "reparent: could not find stackId=" + stackId);
109 return;
110 }
111 mContainer.reparent(stack, position);
112 final DisplayContent displayContent = stack.getDisplayContent();
113 displayContent.setLayoutNeeded();
114 mService.mWindowPlacerLocked.performSurfacePlacement();
115 }
116 }
117
118 public void setResizeable(int resizeMode) {
119 synchronized (mWindowMap) {
120 if (mContainer != null) {
121 mContainer.setResizeable(resizeMode);
122 }
123 }
124 }
125
126 public void resize(Rect bounds, Configuration overrideConfig, boolean relayout,
127 boolean forced) {
128 synchronized (mWindowMap) {
129 if (mContainer == null) {
130 throw new IllegalArgumentException("resizeTask: taskId " + mTaskId + " not found.");
131 }
132
133 if (mContainer.resizeLocked(bounds, overrideConfig, forced) && relayout) {
134 mContainer.getDisplayContent().setLayoutNeeded();
135 mService.mWindowPlacerLocked.performSurfacePlacement();
136 }
137 }
138 }
139
140 // TODO: Move to positionChildAt() in stack controller once we have a stack controller.
141 public void positionAt(int stackId, int index, Rect bounds, Configuration overrideConfig) {
142 synchronized (mWindowMap) {
143 if (DEBUG_STACK) Slog.i(TAG_WM, "positionChildAt: positioning taskId=" + mTaskId
144 + " in stackId=" + stackId + " at " + index);
145 if (mContainer == null) {
146 if (DEBUG_STACK) Slog.i(TAG_WM,
147 "positionTaskInStack: could not find taskId=" + mTaskId);
148 return;
149 }
150 final TaskStack stack = mService.mStackIdToStack.get(stackId);
151 if (stack == null) {
152 if (DEBUG_STACK) Slog.i(TAG_WM,
153 "positionTaskInStack: could not find stackId=" + stackId);
154 return;
155 }
156 mContainer.positionTaskInStack(stack, index, bounds, overrideConfig);
157 final DisplayContent displayContent = stack.getDisplayContent();
158 displayContent.setLayoutNeeded();
159 mService.mWindowPlacerLocked.performSurfacePlacement();
160 }
161 }
162
163 // TODO: Replace with moveChildToTop in stack controller?
164 public void moveToTop(boolean includingParents) {
165 synchronized(mWindowMap) {
166 if (mContainer == null) {
167 Slog.e(TAG_WM, "moveToTop: taskId=" + mTaskId + " not found");
168 return;
169 }
170 final TaskStack stack = mContainer.mStack;
171 stack.positionChildAt(POSITION_TOP, mContainer, includingParents);
172
173 if (mService.mAppTransition.isTransitionSet()) {
174 mContainer.setSendingToBottom(false);
175 }
176 stack.getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
177 }
178 }
179
180 // TODO: Replace with moveChildToBottom in stack controller?
181 public void moveToBottom() {
182 synchronized(mWindowMap) {
183 if (mContainer == null) {
184 Slog.e(TAG_WM, "moveTaskToBottom: taskId=" + mTaskId + " not found");
185 return;
186 }
187 final TaskStack stack = mContainer.mStack;
188 stack.positionChildAt(POSITION_BOTTOM, mContainer, false /* includingParents */);
189 if (mService.mAppTransition.isTransitionSet()) {
190 mContainer.setSendingToBottom(true);
191 }
192 stack.getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
193 }
194 }
195
196 public void getBounds(Rect bounds) {
197 synchronized (mWindowMap) {
198 if (mContainer != null) {
199 mContainer.getBounds(bounds);
200 return;
201 }
202 bounds.setEmpty();
203 }
204 }
205
206 /**
207 * Puts this task into docked drag resizing mode. See {@link DragResizeMode}.
208 *
209 * @param resizing Whether to put the task into drag resize mode.
210 */
211 public void setTaskDockedResizing(boolean resizing) {
212 synchronized (mWindowMap) {
213 if (mContainer == null) {
214 Slog.w(TAG_WM, "setTaskDockedResizing: taskId " + mTaskId + " not found.");
215 return;
216 }
217 mContainer.setDragResizing(resizing, DRAG_RESIZE_MODE_DOCKED_DIVIDER);
218 }
219 }
220
221 public void cancelWindowTransition() {
222 synchronized (mWindowMap) {
223 if (mContainer == null) {
224 Slog.w(TAG_WM, "cancelWindowTransition: taskId " + mTaskId + " not found.");
225 return;
226 }
227 mContainer.cancelTaskWindowTransition();
228 }
229 }
230
231 public void cancelThumbnailTransition() {
232 synchronized (mWindowMap) {
233 if (mContainer == null) {
234 Slog.w(TAG_WM, "cancelThumbnailTransition: taskId " + mTaskId + " not found.");
235 return;
236 }
237 mContainer.cancelTaskThumbnailTransition();
238 }
239 }
240
241 @Override
242 public String toString() {
243 return "{TaskWindowContainerController taskId=" + mTaskId + "}";
244 }
245}