From a8bcec8a4c18459717096e1cc4ff8f9d5b16306a Mon Sep 17 00:00:00 2001 From: Jorge Gil Date: Fri, 10 Jan 2025 19:38:37 +0000 Subject: Use baseIntent to obtain package name baseIntent's component is more often non-null than baseActivity's, so use that when obtaining the number of other instances. Flag: com.android.window.flags.enable_desktop_windowing_multi_instance_features Fix: 387552315 Test: atest WMShellUnitTests Change-Id: I1b01b1ec8b265b9df0dd1435a4656cf3b7f72ba0 --- .../src/com/android/wm/shell/common/ComponentUtils.kt | 9 +++++++-- .../windowdecor/DesktopModeWindowDecorViewModel.java | 18 +++++++++++++----- 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 429e0564dd2c..a90c6fbdae1d 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); -- cgit v1.2.3-59-g8ed1b