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

Commit 872ee1fe authored by Nick Chameyev's avatar Nick Chameyev Committed by Automerger Merge Worker
Browse files

Merge "[Partial Screensharing] Implement loading of recent tasks, thumbnails...

Merge "[Partial Screensharing] Implement loading of recent tasks, thumbnails and icons" into tm-qpr-dev am: 8504f8c8 am: 86951ca5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20024785



Change-Id: I73138306061dad6f7ba054634aa312f96777cac1
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 194b82f4 86951ca5
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -484,12 +484,14 @@ public abstract class WMShellBaseModule {
            ShellInit shellInit,
            ShellCommandHandler shellCommandHandler,
            TaskStackListenerImpl taskStackListener,
            ActivityTaskManager activityTaskManager,
            Optional<DesktopModeTaskRepository> desktopModeTaskRepository,
            @ShellMainThread ShellExecutor mainExecutor
    ) {
        return Optional.ofNullable(
                RecentTasksController.create(context, shellInit, shellCommandHandler,
                        taskStackListener, desktopModeTaskRepository, mainExecutor));
                        taskStackListener, activityTaskManager, desktopModeTaskRepository,
                        mainExecutor));
    }

    //
+12 −0
Original line number Diff line number Diff line
@@ -17,6 +17,11 @@
package com.android.wm.shell.recents;

import com.android.wm.shell.common.annotations.ExternalThread;
import com.android.wm.shell.util.GroupedRecentTaskInfo;

import java.util.List;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

/**
 * Interface for interacting with the recent tasks.
@@ -29,4 +34,11 @@ public interface RecentTasks {
    default IRecentTasks createExternalInterface() {
        return null;
    }

    /**
     * Gets the set of recent tasks.
     */
    default void getRecentTasks(int maxNum, int flags, int userId, Executor callbackExecutor,
            Consumer<List<GroupedRecentTaskInfo>> callback) {
    }
}
+22 −10
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

/**
 * Manages the recent task list from the system, caching it as necessary.
@@ -72,6 +74,7 @@ public class RecentTasksController implements TaskStackListenerCallback,
    private final ShellExecutor mMainExecutor;
    private final TaskStackListenerImpl mTaskStackListener;
    private final RecentTasks mImpl = new RecentTasksImpl();
    private final ActivityTaskManager mActivityTaskManager;
    private IRecentTasksListener mListener;
    private final boolean mIsDesktopMode;

@@ -96,6 +99,7 @@ public class RecentTasksController implements TaskStackListenerCallback,
            ShellInit shellInit,
            ShellCommandHandler shellCommandHandler,
            TaskStackListenerImpl taskStackListener,
            ActivityTaskManager activityTaskManager,
            Optional<DesktopModeTaskRepository> desktopModeTaskRepository,
            @ShellMainThread ShellExecutor mainExecutor
    ) {
@@ -103,17 +107,19 @@ public class RecentTasksController implements TaskStackListenerCallback,
            return null;
        }
        return new RecentTasksController(context, shellInit, shellCommandHandler, taskStackListener,
                desktopModeTaskRepository, mainExecutor);
                activityTaskManager, desktopModeTaskRepository, mainExecutor);
    }

    RecentTasksController(Context context,
            ShellInit shellInit,
            ShellCommandHandler shellCommandHandler,
            TaskStackListenerImpl taskStackListener,
            ActivityTaskManager activityTaskManager,
            Optional<DesktopModeTaskRepository> desktopModeTaskRepository,
            ShellExecutor mainExecutor) {
        mContext = context;
        mShellCommandHandler = shellCommandHandler;
        mActivityTaskManager = activityTaskManager;
        mIsDesktopMode = mContext.getPackageManager().hasSystemFeature(FEATURE_PC);
        mTaskStackListener = taskStackListener;
        mDesktopModeTaskRepository = desktopModeTaskRepository;
@@ -269,16 +275,11 @@ public class RecentTasksController implements TaskStackListenerCallback,
        mListener = null;
    }

    @VisibleForTesting
    List<ActivityManager.RecentTaskInfo> getRawRecentTasks(int maxNum, int flags, int userId) {
        return ActivityTaskManager.getInstance().getRecentTasks(maxNum, flags, userId);
    }

    @VisibleForTesting
    ArrayList<GroupedRecentTaskInfo> getRecentTasks(int maxNum, int flags, int userId) {
        // Note: the returned task list is from the most-recent to least-recent order
        final List<ActivityManager.RecentTaskInfo> rawList = getRawRecentTasks(maxNum, flags,
                userId);
        final List<ActivityManager.RecentTaskInfo> rawList = mActivityTaskManager.getRecentTasks(
                maxNum, flags, userId);

        // Make a mapping of task id -> task info
        final SparseArray<ActivityManager.RecentTaskInfo> rawMapping = new SparseArray<>();
@@ -335,8 +336,9 @@ public class RecentTasksController implements TaskStackListenerCallback,
        if (componentName == null) {
            return null;
        }
        List<ActivityManager.RecentTaskInfo> tasks = getRawRecentTasks(Integer.MAX_VALUE,
                ActivityManager.RECENT_IGNORE_UNAVAILABLE, ActivityManager.getCurrentUser());
        List<ActivityManager.RecentTaskInfo> tasks = mActivityTaskManager.getRecentTasks(
                Integer.MAX_VALUE, ActivityManager.RECENT_IGNORE_UNAVAILABLE,
                ActivityManager.getCurrentUser());
        for (int i = 0; i < tasks.size(); i++) {
            final ActivityManager.RecentTaskInfo task = tasks.get(i);
            if (task.isVisible) {
@@ -374,6 +376,16 @@ public class RecentTasksController implements TaskStackListenerCallback,
            mIRecentTasks = new IRecentTasksImpl(RecentTasksController.this);
            return mIRecentTasks;
        }

        @Override
        public void getRecentTasks(int maxNum, int flags, int userId, Executor executor,
                Consumer<List<GroupedRecentTaskInfo>> callback) {
            mMainExecutor.execute(() -> {
                List<GroupedRecentTaskInfo> tasks =
                        RecentTasksController.this.getRecentTasks(maxNum, flags, userId);
                executor.execute(() -> callback.accept(tasks));
            });
        }
    }


+41 −6
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import static org.mockito.Mockito.when;
import static java.lang.Integer.MAX_VALUE;

import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Rect;
@@ -52,7 +53,6 @@ import com.android.dx.mockito.inline.extended.StaticMockitoSession;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.TestShellExecutor;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.TaskStackListenerImpl;
import com.android.wm.shell.desktopmode.DesktopModeStatus;
import com.android.wm.shell.desktopmode.DesktopModeTaskRepository;
@@ -68,7 +68,9 @@ import org.mockito.Mock;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

/**
 * Tests for {@link RecentTasksController}.
@@ -85,11 +87,13 @@ public class RecentTasksControllerTest extends ShellTestCase {
    private ShellCommandHandler mShellCommandHandler;
    @Mock
    private DesktopModeTaskRepository mDesktopModeTaskRepository;
    @Mock
    private ActivityTaskManager mActivityTaskManager;

    private ShellTaskOrganizer mShellTaskOrganizer;
    private RecentTasksController mRecentTasksController;
    private ShellInit mShellInit;
    private ShellExecutor mMainExecutor;
    private TestShellExecutor mMainExecutor;

    @Before
    public void setUp() {
@@ -97,8 +101,8 @@ public class RecentTasksControllerTest extends ShellTestCase {
        when(mContext.getPackageManager()).thenReturn(mock(PackageManager.class));
        mShellInit = spy(new ShellInit(mMainExecutor));
        mRecentTasksController = spy(new RecentTasksController(mContext, mShellInit,
                mShellCommandHandler, mTaskStackListener, Optional.of(mDesktopModeTaskRepository),
                mMainExecutor));
                mShellCommandHandler, mTaskStackListener, mActivityTaskManager,
                Optional.of(mDesktopModeTaskRepository), mMainExecutor));
        mShellTaskOrganizer = new ShellTaskOrganizer(mShellInit, mShellCommandHandler,
                null /* sizeCompatUI */, Optional.empty(), Optional.of(mRecentTasksController),
                mMainExecutor);
@@ -187,6 +191,37 @@ public class RecentTasksControllerTest extends ShellTestCase {
                t6.taskId, -1);
    }

    @Test
    public void testGetRecentTasks_ReturnsRecentTasksAsynchronously() {
        @SuppressWarnings("unchecked")
        final List<GroupedRecentTaskInfo>[] recentTasks = new List[1];
        Consumer<List<GroupedRecentTaskInfo>> consumer = argument -> recentTasks[0] = argument;
        ActivityManager.RecentTaskInfo t1 = makeTaskInfo(1);
        ActivityManager.RecentTaskInfo t2 = makeTaskInfo(2);
        ActivityManager.RecentTaskInfo t3 = makeTaskInfo(3);
        ActivityManager.RecentTaskInfo t4 = makeTaskInfo(4);
        ActivityManager.RecentTaskInfo t5 = makeTaskInfo(5);
        ActivityManager.RecentTaskInfo t6 = makeTaskInfo(6);
        setRawList(t1, t2, t3, t4, t5, t6);

        // Mark a couple pairs [t2, t4], [t3, t5]
        SplitBounds pair1Bounds = new SplitBounds(new Rect(), new Rect(), 2, 4);
        SplitBounds pair2Bounds = new SplitBounds(new Rect(), new Rect(), 3, 5);

        mRecentTasksController.addSplitPair(t2.taskId, t4.taskId, pair1Bounds);
        mRecentTasksController.addSplitPair(t3.taskId, t5.taskId, pair2Bounds);

        mRecentTasksController.asRecentTasks()
                .getRecentTasks(MAX_VALUE, RECENT_IGNORE_UNAVAILABLE, 0, Runnable::run, consumer);
        mMainExecutor.flushAll();

        assertGroupedTasksListEquals(recentTasks[0],
                t1.taskId, -1,
                t2.taskId, t4.taskId,
                t3.taskId, t5.taskId,
                t6.taskId, -1);
    }

    @Test
    public void testGetRecentTasks_groupActiveFreeformTasks() {
        StaticMockitoSession mockitoSession = mockitoSession().mockStatic(
@@ -296,7 +331,7 @@ public class RecentTasksControllerTest extends ShellTestCase {
        for (ActivityManager.RecentTaskInfo task : tasks) {
            rawList.add(task);
        }
        doReturn(rawList).when(mRecentTasksController).getRawRecentTasks(anyInt(), anyInt(),
        doReturn(rawList).when(mActivityTaskManager).getRecentTasks(anyInt(), anyInt(),
                anyInt());
        return rawList;
    }
@@ -307,7 +342,7 @@ public class RecentTasksControllerTest extends ShellTestCase {
     * @param expectedTaskIds list of task ids that map to the flattened task ids of the tasks in
     *                        the grouped task list
     */
    private void assertGroupedTasksListEquals(ArrayList<GroupedRecentTaskInfo> recentTasks,
    private void assertGroupedTasksListEquals(List<GroupedRecentTaskInfo> recentTasks,
            int... expectedTaskIds) {
        int[] flattenedTaskIds = new int[recentTasks.size() * 2];
        for (int i = 0; i < recentTasks.size(); i++) {
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ class MediaProjectionAppSelectorController(
    }

    private fun List<RecentTask>.sortTasks(): List<RecentTask> =
        asReversed().sortedBy {
        sortedBy {
            // Show normal tasks first and only then tasks with opened app selector
            it.topActivityComponent == appSelectorComponentName
        }
Loading