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

Commit efdd59a3 authored by mattsziklay's avatar mattsziklay Committed by Matt Sziklay
Browse files

Create handle menu on background thread.

Moves handle menu creation to the background thread to reduce IPCs on the main thread.

Bug: 374485723
Test: ABTD
Flag: EXEMPT bugfix
Change-Id: I1e333e018662f3ab2194d4713f5b17572b49dcd8
parent fb51ac3c
Loading
Loading
Loading
Loading
+25 −10
Original line number Diff line number Diff line
@@ -580,8 +580,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(
@@ -755,11 +763,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;
                    }
                )
            );
        });
    }

@@ -1802,11 +1818,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
@@ -281,6 +281,7 @@ open class DesktopModeWindowDecorViewModelTestsBase : ShellTestCase() {
                } else {
                    statusBars()
                }
                userId = context.userId
            }
    }