Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8bcec8a authored by Jorge Gil's avatar Jorge Gil
Browse files

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
parent 54eb7e64
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -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)
}
+13 −5
Original line number Diff line number Diff line
@@ -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);