From 29ae5b4e5697c7937fab28e70b16075cf094be13 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 11 Nov 2022 18:17:26 +0800 Subject: [PATCH] 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 --- .../com/android/server/wm/ActivityRecord.java | 7 +-- .../com/android/server/wm/DisplayArea.java | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 17a9a63a7f805..711d2296ba307 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -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() { diff --git a/services/core/java/com/android/server/wm/DisplayArea.java b/services/core/java/com/android/server/wm/DisplayArea.java index b84b2d8805dee..bedeabeb6141f 100644 --- a/services/core/java/com/android/server/wm/DisplayArea.java +++ b/services/core/java/com/android/server/wm/DisplayArea.java @@ -368,6 +368,55 @@ public class DisplayArea extends WindowContainer { return null; } + @Override + ActivityRecord getActivity(Predicate 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 callback, boolean traverseTopToBottom) { + if (mType == Type.ABOVE_TASKS || mType == Type.BELOW_TASKS) { + return null; + } + return super.getTask(callback, traverseTopToBottom); + } + + @Override + boolean forAllActivities(Predicate callback, boolean traverseTopToBottom) { + if (mType == Type.ABOVE_TASKS || mType == Type.BELOW_TASKS) { + return false; + } + return super.forAllActivities(callback, traverseTopToBottom); + } + + @Override + boolean forAllRootTasks(Predicate callback, boolean traverseTopToBottom) { + if (mType == Type.ABOVE_TASKS || mType == Type.BELOW_TASKS) { + return false; + } + return super.forAllRootTasks(callback, traverseTopToBottom); + } + + @Override + boolean forAllTasks(Predicate callback) { + if (mType == Type.ABOVE_TASKS || mType == Type.BELOW_TASKS) { + return false; + } + return super.forAllTasks(callback); + } + + @Override + boolean forAllLeafTasks(Predicate callback) { + if (mType == Type.ABOVE_TASKS || mType == Type.BELOW_TASKS) { + return false; + } + return super.forAllLeafTasks(callback); + } + @Override void forAllDisplayAreas(Consumer callback) { super.forAllDisplayAreas(callback);