Remove use of TaskTile
We just have the TaskOrganizer create root task directly
Test: Existing tests pass
Bug: 133381284
Bug: 149429752
Change-Id: Id884cbe8e7d2fdd93e729fcb2793fad4afd59b21
diff --git a/services/core/java/com/android/server/wm/TaskOrganizerController.java b/services/core/java/com/android/server/wm/TaskOrganizerController.java
index 5523678..05b721b 100644
--- a/services/core/java/com/android/server/wm/TaskOrganizerController.java
+++ b/services/core/java/com/android/server/wm/TaskOrganizerController.java
@@ -17,6 +17,7 @@
package com.android.server.wm;
import static android.Manifest.permission.MANAGE_ACTIVITY_STACKS;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
@@ -27,13 +28,14 @@
import android.annotation.Nullable;
import android.app.ActivityManager.RunningTaskInfo;
+import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Slog;
-import android.window.ITaskOrganizerController;
import android.window.ITaskOrganizer;
+import android.window.ITaskOrganizerController;
import android.window.IWindowContainer;
import com.android.internal.util.ArrayUtils;
@@ -255,11 +257,12 @@
if (display == null) {
return null;
}
- final int nextId = display.getNextStackId();
- TaskTile tile = new TaskTile(mService, nextId, windowingMode);
- display.addTile(tile);
- RunningTaskInfo out = tile.getTaskInfo();
- mLastSentTaskInfos.put(tile, out);
+
+ final Task task = display.getOrCreateStack(windowingMode, ACTIVITY_TYPE_UNDEFINED,
+ false /* onTop */, new Intent(), null /* candidateTask */,
+ true /* createdByOrganizer */);
+ RunningTaskInfo out = task.getTaskInfo();
+ mLastSentTaskInfos.put(task, out);
return out;
}
} finally {
@@ -273,11 +276,13 @@
final long origId = Binder.clearCallingIdentity();
try {
synchronized (mGlobalLock) {
- TaskTile tile = TaskTile.forToken(token.asBinder());
- if (tile == null) {
- return false;
+ final Task task = WindowContainer.fromBinder(token.asBinder()).asTask();
+ if (task == null) return false;
+ if (!task.mCreatedByOrganizer) {
+ throw new IllegalArgumentException(
+ "Attempt to delete task not created by organizer task=" + task);
}
- tile.removeImmediately();
+ task.removeImmediately();
return true;
}
} finally {
@@ -358,12 +363,7 @@
if (task == null) {
return null;
}
- ActivityStack rootTask = (ActivityStack) task.getRootTask();
- final TaskTile tile = rootTask.getTile();
- if (tile != null) {
- rootTask = tile;
- }
- return rootTask.mRemoteToken;
+ return task.getRootTask().mRemoteToken;
}
} finally {
Binder.restoreCallingIdentity(origId);
@@ -371,7 +371,7 @@
}
@Override
- public void setLaunchRoot(int displayId, @Nullable IWindowContainer tile) {
+ public void setLaunchRoot(int displayId, @Nullable IWindowContainer token) {
enforceStackPermission("setLaunchRoot()");
final long origId = Binder.clearCallingIdentity();
try {
@@ -380,16 +380,21 @@
if (display == null) {
return;
}
- TaskTile taskTile = tile == null ? null : TaskTile.forToken(tile.asBinder());
- if (taskTile == null) {
- display.mLaunchTile = null;
+ Task task = token == null
+ ? null : WindowContainer.fromBinder(token.asBinder()).asTask();
+ if (task == null) {
+ display.mLaunchRootTask = null;
return;
}
- if (taskTile.getDisplay() != display) {
- throw new RuntimeException("Can't set launch root for display " + displayId
- + " to task on display " + taskTile.getDisplay().getDisplayId());
+ if (!task.mCreatedByOrganizer) {
+ throw new IllegalArgumentException("Attempt to set task not created by "
+ + "organizer as launch root task=" + task);
}
- display.mLaunchTile = taskTile;
+ if (task.getDisplayContent() != display) {
+ throw new RuntimeException("Can't set launch root for display " + displayId
+ + " to task on display " + task.getDisplayContent().getDisplayId());
+ }
+ display.mLaunchRootTask = task;
}
} finally {
Binder.restoreCallingIdentity(origId);
@@ -411,25 +416,25 @@
Slog.e(TAG, "Can't get children of " + parent + " because it is not valid.");
return null;
}
- // For now, only support returning children of persistent root tasks (of which the
- // only current implementation is TaskTile).
- if (!(container instanceof TaskTile)) {
+ final Task task = container.asTask();
+ if (task == null) {
+ Slog.e(TAG, container + " is not a task...");
+ return null;
+ }
+ // For now, only support returning children of tasks created by the organizer.
+ if (!task.mCreatedByOrganizer) {
Slog.w(TAG, "Can only get children of root tasks created via createRootTask");
return null;
}
ArrayList<RunningTaskInfo> out = new ArrayList<>();
- // Tiles aren't real parents, so we need to go through stacks on the display to
- // ensure correct ordering.
- final DisplayContent dc = container.getDisplayContent();
- for (int i = dc.getStackCount() - 1; i >= 0; --i) {
- final ActivityStack as = dc.getStackAt(i);
- if (as.getTile() == container) {
- if (activityTypes != null
- && !ArrayUtils.contains(activityTypes, as.getActivityType())) {
- continue;
- }
- out.add(as.getTaskInfo());
+ for (int i = task.getChildCount() - 1; i >= 0; --i) {
+ final Task child = task.getChildAt(i).asTask();
+ if (child == null) continue;
+ if (activityTypes != null
+ && !ArrayUtils.contains(activityTypes, child.getActivityType())) {
+ continue;
}
+ out.add(child.getTaskInfo());
}
return out;
}
@@ -451,12 +456,7 @@
}
ArrayList<RunningTaskInfo> out = new ArrayList<>();
for (int i = dc.getStackCount() - 1; i >= 0; --i) {
- final ActivityStack task = dc.getStackAt(i);
- if (task.getTile() != null) {
- // a tile is supposed to look like a parent, so don't include their
- // "children" here. They can be accessed via getChildTasks()
- continue;
- }
+ final Task task = dc.getStackAt(i);
if (activityTypes != null
&& !ArrayUtils.contains(activityTypes, task.getActivityType())) {
continue;