Optimize traversal methods from DisplayArea

There are dozen of display areas won't contain activity or task.
So if a traversal method for task/activity is called on a display
or root, it can be skipped directly. This can save 200+ times to
go through the areas during an activity launch.

Also simplify AR#getDisplayId a bit: no need to use root task.
If the activity is detached, its task will be null. And if the
task is detached, its display will be null.

Bug: 159103089
Test: CtsWindowManagerDeviceTestCases
Change-Id: Iacd20f14bf8681d9ef156721d056bbe5e5a0c3c8
This commit is contained in:
Riddle Hsu
2022-11-11 18:17:26 +08:00
parent fc103b26e0
commit 29ae5b4e56
2 changed files with 51 additions and 5 deletions

View File

@@ -6912,11 +6912,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
* {@link android.view.Display#INVALID_DISPLAY} if not attached.
*/
int getDisplayId() {
final Task rootTask = getRootTask();
if (rootTask == null) {
return INVALID_DISPLAY;
}
return rootTask.getDisplayId();
return task != null && task.mDisplayContent != null
? task.mDisplayContent.mDisplayId : INVALID_DISPLAY;
}
final boolean isDestroyable() {

View File

@@ -368,6 +368,55 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
return null;
}
@Override
ActivityRecord getActivity(Predicate<ActivityRecord> callback, boolean traverseTopToBottom,
ActivityRecord boundary) {
if (mType == Type.ABOVE_TASKS || mType == Type.BELOW_TASKS) {
return null;
}
return super.getActivity(callback, traverseTopToBottom, boundary);
}
@Override
Task getTask(Predicate<Task> callback, boolean traverseTopToBottom) {
if (mType == Type.ABOVE_TASKS || mType == Type.BELOW_TASKS) {
return null;
}
return super.getTask(callback, traverseTopToBottom);
}
@Override
boolean forAllActivities(Predicate<ActivityRecord> callback, boolean traverseTopToBottom) {
if (mType == Type.ABOVE_TASKS || mType == Type.BELOW_TASKS) {
return false;
}
return super.forAllActivities(callback, traverseTopToBottom);
}
@Override
boolean forAllRootTasks(Predicate<Task> callback, boolean traverseTopToBottom) {
if (mType == Type.ABOVE_TASKS || mType == Type.BELOW_TASKS) {
return false;
}
return super.forAllRootTasks(callback, traverseTopToBottom);
}
@Override
boolean forAllTasks(Predicate<Task> callback) {
if (mType == Type.ABOVE_TASKS || mType == Type.BELOW_TASKS) {
return false;
}
return super.forAllTasks(callback);
}
@Override
boolean forAllLeafTasks(Predicate<Task> callback) {
if (mType == Type.ABOVE_TASKS || mType == Type.BELOW_TASKS) {
return false;
}
return super.forAllLeafTasks(callback);
}
@Override
void forAllDisplayAreas(Consumer<DisplayArea> callback) {
super.forAllDisplayAreas(callback);