summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-01-15 13:50:09 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-01-15 13:50:09 -0800
commit7b51c95ca7007029c23ea3efee890da7907b86ea (patch)
treeea5091f69e1f24955fb05f05ab3d8c5485d5a661
parent8c94e02daf94d325b34a772c3a865fc885c9731c (diff)
parenta8bcec8a4c18459717096e1cc4ff8f9d5b16306a (diff)
Merge "Use baseIntent to obtain package name" into main
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/common/ComponentUtils.kt9
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java18
2 files changed, 20 insertions, 7 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/ComponentUtils.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/common/ComponentUtils.kt
index 67592e60e954..0d0bc9be72b3 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/ComponentUtils.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/ComponentUtils.kt
@@ -16,6 +16,7 @@
package com.android.wm.shell.common
import android.app.PendingIntent
+import android.app.TaskInfo
import android.content.ComponentName
import android.content.Intent
import com.android.wm.shell.ShellTaskOrganizer
@@ -34,7 +35,11 @@ object ComponentUtils {
/** Retrieves the package name from a [taskId]. */
@JvmStatic
fun getPackageName(taskId: Int, taskOrganizer: ShellTaskOrganizer): String? {
- val taskInfo = taskOrganizer.getRunningTaskInfo(taskId)
- return getPackageName(taskInfo?.baseIntent)
+ val taskInfo = taskOrganizer.getRunningTaskInfo(taskId) ?: return null
+ return getPackageName(taskInfo)
}
+
+ /** Retrieves the package name from a [TaskInfo]. */
+ @JvmStatic
+ fun getPackageName(taskInfo: TaskInfo): String? = getPackageName(taskInfo.baseIntent)
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
index 055bc8f5f092..d6d393f2500c 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
@@ -99,6 +99,7 @@ import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.apptoweb.AppToWebGenericLinksParser;
import com.android.wm.shell.apptoweb.AssistContentRequester;
+import com.android.wm.shell.common.ComponentUtils;
import com.android.wm.shell.common.DisplayChangeController;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.DisplayInsetsController;
@@ -1926,14 +1927,21 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
// instances, then refer to the list's size and reuse the list for Manage Windows menu.
final IActivityTaskManager activityTaskManager = ActivityTaskManager.getService();
try {
+ // TODO(b/389184897): Move the following into a helper method of
+ // RecentsTasksController, similar to #findTaskInBackground.
+ final String packageName = ComponentUtils.getPackageName(info);
return activityTaskManager.getRecentTasks(Integer.MAX_VALUE,
ActivityManager.RECENT_WITH_EXCLUDED,
info.userId).getList().stream().filter(
- recentTaskInfo -> (recentTaskInfo.taskId != info.taskId
- && recentTaskInfo.baseActivity != null
- && recentTaskInfo.baseActivity.getPackageName()
- .equals(info.baseActivity.getPackageName())
- )
+ recentTaskInfo -> {
+ if (recentTaskInfo.taskId == info.taskId) {
+ return false;
+ }
+ final String recentTaskPackageName =
+ ComponentUtils.getPackageName(recentTaskInfo);
+ return packageName != null
+ && packageName.equals(recentTaskPackageName);
+ }
).toList().size();
} catch (RemoteException e) {
throw new RuntimeException(e);