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

Commit 7b51c95c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use baseIntent to obtain package name" into main

parents 8c94e02d a8bcec8a
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);