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

Commit a556959b authored by Matt Sziklay's avatar Matt Sziklay Committed by Android (Google) Code Review
Browse files

Merge "Create handle menu on background thread." into main

parents 1cf16f51 efdd59a3
Loading
Loading
Loading
Loading
+25 −10
Original line number Diff line number Diff line
@@ -588,8 +588,16 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,

    private void openHandleMenu(int taskId) {
        final DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(taskId);
        decoration.createHandleMenu(checkNumberOfOtherInstances(decoration.mTaskInfo)
                >= MANAGE_WINDOWS_MINIMUM_INSTANCES);
        // TODO(b/379873022): Run the instance check and the AssistContent request in
        //  createHandleMenu on the same bg thread dispatch.
        mBgExecutor.execute(() -> {
            final int numOfInstances = checkNumberOfOtherInstances(decoration.mTaskInfo);
            mMainExecutor.execute(() -> {
                decoration.createHandleMenu(
                        numOfInstances >= MANAGE_WINDOWS_MINIMUM_INSTANCES
                );
            });
        });
    }

    private void onToggleSizeInteraction(
@@ -763,11 +771,19 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
            return;
        }
        decoration.closeHandleMenu();
        decoration.createManageWindowsMenu(getTaskSnapshots(decoration.mTaskInfo),
        mBgExecutor.execute(() -> {
            final ArrayList<Pair<Integer, TaskSnapshot>> snapshotList =
                    getTaskSnapshots(decoration.mTaskInfo);
            mMainExecutor.execute(() -> decoration.createManageWindowsMenu(
                    snapshotList,
                    /* onIconClickListener= */ (Integer requestedTaskId) -> {
                        decoration.closeManageWindowsMenu();
                    mDesktopTasksController.openInstance(decoration.mTaskInfo, requestedTaskId);
                        mDesktopTasksController.openInstance(decoration.mTaskInfo,
                                requestedTaskId);
                        return Unit.INSTANCE;
                    }
                )
            );
        });
    }

@@ -1814,11 +1830,10 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
        // TODO(b/336289597): Rather than returning number of instances, return a list of valid
        //  instances, then refer to the list's size and reuse the list for Manage Windows menu.
        final IActivityTaskManager activityTaskManager = ActivityTaskManager.getService();
        final IActivityManager activityManager = ActivityManager.getService();
        try {
            return activityTaskManager.getRecentTasks(Integer.MAX_VALUE,
                    ActivityManager.RECENT_WITH_EXCLUDED,
                    activityManager.getCurrentUserId()).getList().stream().filter(
                    info.userId).getList().stream().filter(
                            recentTaskInfo -> (recentTaskInfo.taskId != info.taskId
                                    && recentTaskInfo.baseActivity != null
                                    && recentTaskInfo.baseActivity.getPackageName()
+2 −0
Original line number Diff line number Diff line
@@ -125,6 +125,8 @@ class DesktopModeWindowDecorViewModelAppHandleOnlyTest :
            times(1)
        ).setAppHandleEducationTooltipCallbacks(openHandleMenuCallbackCaptor.capture(), any())
        openHandleMenuCallbackCaptor.lastValue.invoke(task.taskId)
        bgExecutor.flushAll()
        testShellExecutor.flushAll()

        verify(decor, times(1)).createHandleMenu(anyBoolean())
    }
+2 −0
Original line number Diff line number Diff line
@@ -780,6 +780,8 @@ class DesktopModeWindowDecorViewModelTests : DesktopModeWindowDecorViewModelTest
            times(1)
        ).setAppHandleEducationTooltipCallbacks(openHandleMenuCallbackCaptor.capture(), any())
        openHandleMenuCallbackCaptor.lastValue.invoke(task.taskId)
        bgExecutor.flushAll()
        testShellExecutor.flushAll()

        verify(decor, times(1)).createHandleMenu(anyBoolean())
    }
+1 −0
Original line number Diff line number Diff line
@@ -286,6 +286,7 @@ open class DesktopModeWindowDecorViewModelTestsBase : ShellTestCase() {
                } else {
                    statusBars()
                }
                userId = context.userId
            }
    }