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