Debian Codegraph @

core/java/android/window/TaskOrganizer.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 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 android.window;
18
19 import android.annotation.BinderThread;
20 import android.annotation.CallSuper;
21 import android.annotation.NonNull;
22 import android.annotation.Nullable;
23 import android.annotation.RequiresPermission;
24 import android.annotation.SuppressLint;
25 import android.annotation.TestApi;
26 import android.app.ActivityManager;
27 import android.app.TaskInfo.CameraCompatControlState;
28 import android.os.IBinder;
29 import android.os.RemoteException;
30 import android.view.SurfaceControl;
31
32 import com.android.internal.annotations.VisibleForTesting;
33
34 import java.util.List;
35 import java.util.concurrent.Executor;
36
37 /**
38 * Interface for ActivityTaskManager/WindowManager to delegate control of tasks.
39 * @hide
40 */
41 @TestApi
42 public class TaskOrganizer extends WindowOrganizer {
43
44 private final ITaskOrganizerController mTaskOrganizerController;
45 // Callbacks WM Core are posted on this executor if it isn't null, otherwise direct calls are
46 // made on the incoming binder call.
47 private final Executor mExecutor;
48
49 public TaskOrganizer() {
50 this(null /*taskOrganizerController*/, null /*executor*/);
51 }
52
53 /** @hide */
54 @VisibleForTesting
55 public TaskOrganizer(ITaskOrganizerController taskOrganizerController, Executor executor) {
56 mExecutor = executor != null ? executor : Runnable::run;
57 mTaskOrganizerController = taskOrganizerController != null
58 ? taskOrganizerController : getController();
59 }
60
61 /**
62 * Register a TaskOrganizer to manage tasks as they enter a supported windowing mode.
63 *
64 * @return a list of the tasks that should be managed by the organizer, not including tasks
65 * created via {@link #createRootTask}.
66 */
67 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
68 @CallSuper
69 @NonNull
70 public List<TaskAppearedInfo> registerOrganizer() {
71 try {
72 return mTaskOrganizerController.registerTaskOrganizer(mInterface).getList();
73 } catch (RemoteException e) {
74 throw e.rethrowFromSystemServer();
75 }
76 }
77
78 /** Unregisters a previously registered task organizer. */
79 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
80 @CallSuper
81 public void unregisterOrganizer() {
82 try {
83 mTaskOrganizerController.unregisterTaskOrganizer(mInterface);
84 } catch (RemoteException e) {
85 throw e.rethrowFromSystemServer();
86 }
87 }
88
89 /**
90 * Called when a Task is starting and the system would like to show a UI to indicate that an
91 * application is starting. The client is responsible to add/remove the starting window if it
92 * has create a starting window for the Task.
93 *
94 * @param info The information about the Task that's available
95 * @param appToken Token of the application being started.
96 * context to for resources
97 * @hide
98 */
99 @BinderThread
100 public void addStartingWindow(@NonNull StartingWindowInfo info,
101 @NonNull IBinder appToken) {}
102
103 /**
104 * Called when the Task want to remove the starting window.
105 * @param removalInfo The information used to remove the starting window.
106 * @hide
107 */
108 @BinderThread
109 public void removeStartingWindow(@NonNull StartingWindowRemovalInfo removalInfo) {}
110
111 /**
112 * Called when the Task want to copy the splash screen.
113 */
114 @BinderThread
115 public void copySplashScreenView(int taskId) {}
116
117 /**
118 * Notify the shell ({@link com.android.wm.shell.ShellTaskOrganizer} that the client has
119 * removed the splash screen view.
120 * @see com.android.wm.shell.ShellTaskOrganizer#onAppSplashScreenViewRemoved(int)
121 * @see SplashScreenView#remove()
122 */
123 @BinderThread
124 public void onAppSplashScreenViewRemoved(int taskId) {
125 }
126
127 /**
128 * Called when a task with the registered windowing mode can be controlled by this task
129 * organizer. For non-root tasks, the leash may initially be hidden so it is up to the organizer
130 * to show this task.
131 */
132 @BinderThread
133 public void onTaskAppeared(@NonNull ActivityManager.RunningTaskInfo taskInfo,
134 @NonNull SurfaceControl leash) {}
135
136 @BinderThread
137 public void onTaskVanished(@NonNull ActivityManager.RunningTaskInfo taskInfo) {}
138
139 @BinderThread
140 public void onTaskInfoChanged(@NonNull ActivityManager.RunningTaskInfo taskInfo) {}
141
142 @BinderThread
143 public void onBackPressedOnTaskRoot(@NonNull ActivityManager.RunningTaskInfo taskInfo) {}
144
145 /** @hide */
146 @BinderThread
147 public void onImeDrawnOnTask(int taskId) {}
148
149 /**
150 * Creates a persistent root task in WM for a particular windowing-mode.
151 * @param displayId The display to create the root task on.
152 * @param windowingMode Windowing mode to put the root task in.
153 * @param launchCookie Launch cookie to associate with the task so that is can be identified
154 * when the {@link ITaskOrganizer#onTaskAppeared} callback is called.
155 */
156 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
157 @Nullable
158 public void createRootTask(int displayId, int windowingMode, @Nullable IBinder launchCookie) {
159 try {
160 mTaskOrganizerController.createRootTask(displayId, windowingMode, launchCookie);
161 } catch (RemoteException e) {
162 throw e.rethrowFromSystemServer();
163 }
164 }
165
166 /** Deletes a persistent root task in WM */
167 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
168 public boolean deleteRootTask(@NonNull WindowContainerToken task) {
169 try {
170 return mTaskOrganizerController.deleteRootTask(task);
171 } catch (RemoteException e) {
172 throw e.rethrowFromSystemServer();
173 }
174 }
175
176 /** Gets direct child tasks (ordered from top-to-bottom) */
177 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
178 @Nullable
179 @SuppressLint("NullableCollection")
180 public List<ActivityManager.RunningTaskInfo> getChildTasks(
181 @NonNull WindowContainerToken parent, @NonNull int[] activityTypes) {
182 try {
183 return mTaskOrganizerController.getChildTasks(parent, activityTypes);
184 } catch (RemoteException e) {
185 throw e.rethrowFromSystemServer();
186 }
187 }
188
189 /** Gets all root tasks on a display (ordered from top-to-bottom) */
190 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
191 @Nullable
192 @SuppressLint("NullableCollection")
193 public List<ActivityManager.RunningTaskInfo> getRootTasks(
194 int displayId, @NonNull int[] activityTypes) {
195 try {
196 return mTaskOrganizerController.getRootTasks(displayId, activityTypes);
197 } catch (RemoteException e) {
198 throw e.rethrowFromSystemServer();
199 }
200 }
201
202 /** Get the {@link WindowContainerToken} of the task which contains the current ime target */
203 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
204 @Nullable
205 public WindowContainerToken getImeTarget(int display) {
206 try {
207 return mTaskOrganizerController.getImeTarget(display);
208 } catch (RemoteException e) {
209 throw e.rethrowFromSystemServer();
210 }
211 }
212
213 /**
214 * Requests that the given task organizer is notified when back is pressed on the root activity
215 * of one of its controlled tasks.
216 */
217 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
218 public void setInterceptBackPressedOnTaskRoot(@NonNull WindowContainerToken task,
219 boolean interceptBackPressed) {
220 try {
221 mTaskOrganizerController.setInterceptBackPressedOnTaskRoot(task, interceptBackPressed);
222 } catch (RemoteException e) {
223 throw e.rethrowFromSystemServer();
224 }
225 }
226
227
228 /**
229 * Restarts the top activity in the given task by killing its process if it is visible.
230 * @hide
231 */
232 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
233 public void restartTaskTopActivityProcessIfVisible(@NonNull WindowContainerToken task) {
234 try {
235 mTaskOrganizerController.restartTaskTopActivityProcessIfVisible(task);
236 } catch (RemoteException e) {
237 throw e.rethrowFromSystemServer();
238 }
239 }
240
241 /**
242 * Updates a state of camera compat control for stretched issues in the viewfinder.
243 * @hide
244 */
245 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
246 public void updateCameraCompatControlState(@NonNull WindowContainerToken task,
247 @CameraCompatControlState int state) {
248 try {
249 mTaskOrganizerController.updateCameraCompatControlState(task, state);
250 } catch (RemoteException e) {
251 throw e.rethrowFromSystemServer();
252 }
253 }
254
255 /**
256 * Controls whether ignore orientation request logic in {@link
257 * com.android.server.wm.DisplayArea} is disabled at runtime.
258 *
259 * @param isDisabled when {@code true}, the system always ignores the value of {@link
260 * com.android.server.wm.DisplayArea#getIgnoreOrientationRequest} and app
261 * requested orientation is respected.
262 * @hide
263 */
264 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
265 public void setIsIgnoreOrientationRequestDisabled(boolean isDisabled) {
266 try {
267 mTaskOrganizerController.setIsIgnoreOrientationRequestDisabled(isDisabled);
268 } catch (RemoteException e) {
269 throw e.rethrowFromSystemServer();
270 }
271 }
272
273 /**
274 * Gets the executor to run callbacks on.
275 * @hide
276 */
277 @NonNull
278 public Executor getExecutor() {
279 return mExecutor;
280 }
281
282 private final ITaskOrganizer mInterface = new ITaskOrganizer.Stub() {
283 @Override
284 public void addStartingWindow(StartingWindowInfo windowInfo,
285 IBinder appToken) {
286 mExecutor.execute(() -> TaskOrganizer.this.addStartingWindow(windowInfo, appToken));
287 }
288
289 @Override
290 public void removeStartingWindow(StartingWindowRemovalInfo removalInfo) {
291 mExecutor.execute(() -> TaskOrganizer.this.removeStartingWindow(removalInfo));
292 }
293
294 @Override
295 public void copySplashScreenView(int taskId) {
296 mExecutor.execute(() -> TaskOrganizer.this.copySplashScreenView(taskId));
297 }
298
299 @Override
300 public void onAppSplashScreenViewRemoved(int taskId) {
301 mExecutor.execute(() -> TaskOrganizer.this.onAppSplashScreenViewRemoved(taskId));
302 }
303
304 @Override
305 public void onTaskAppeared(ActivityManager.RunningTaskInfo taskInfo, SurfaceControl leash) {
306 mExecutor.execute(() -> TaskOrganizer.this.onTaskAppeared(taskInfo, leash));
307 }
308
309 @Override
310 public void onTaskVanished(ActivityManager.RunningTaskInfo taskInfo) {
311 mExecutor.execute(() -> TaskOrganizer.this.onTaskVanished(taskInfo));
312 }
313
314 @Override
315 public void onTaskInfoChanged(ActivityManager.RunningTaskInfo info) {
316 mExecutor.execute(() -> TaskOrganizer.this.onTaskInfoChanged(info));
317 }
318
319 @Override
320 public void onBackPressedOnTaskRoot(ActivityManager.RunningTaskInfo info) {
321 mExecutor.execute(() -> TaskOrganizer.this.onBackPressedOnTaskRoot(info));
322 }
323
324 @Override
325 public void onImeDrawnOnTask(int taskId) {
326 mExecutor.execute(() -> TaskOrganizer.this.onImeDrawnOnTask(taskId));
327 }
328 };
329
330 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
331 private ITaskOrganizerController getController() {
332 try {
333 return getWindowOrganizerController().getTaskOrganizerController();
334 } catch (RemoteException e) {
335 return null;
336 }
337 }
338 }