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

Commit 0927efa8 authored by Ats Jenk's avatar Ats Jenk Committed by Android (Google) Code Review
Browse files

Merge "Add API to query number of visible desktop tasks" into tm-qpr-dev

parents 9ed2b6e4 01c616d3
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.ArraySet;
@@ -261,6 +262,11 @@ public class DesktopModeController implements RemoteCallable<DesktopModeControll
        }
    }

    /** Get number of tasks that are marked as visible */
    int getVisibleTaskCount() {
        return mDesktopModeTaskRepository.getVisibleTaskCount();
    }

    @NonNull
    private WindowContainerTransaction bringDesktopAppsToFront(boolean force) {
        final WindowContainerTransaction wct = new WindowContainerTransaction();
@@ -438,5 +444,15 @@ public class DesktopModeController implements RemoteCallable<DesktopModeControll
            executeRemoteCallWithTaskPermission(mController, "showDesktopApps",
                    DesktopModeController::showDesktopApps);
        }

        @Override
        public int getVisibleTaskCount() throws RemoteException {
            int[] result = new int[1];
            executeRemoteCallWithTaskPermission(mController, "getVisibleTaskCount",
                    controller -> result[0] = controller.getVisibleTaskCount(),
                    true /* blocking */
            );
            return result[0];
        }
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -142,6 +142,13 @@ class DesktopModeTaskRepository {
        }
    }

    /**
     * Get number of tasks that are marked as visible
     */
    fun getVisibleTaskCount(): Int {
        return visibleTasks.size
    }

    /**
     * Add (or move if it already exists) the task to the top of the ordered list.
     */
+16 −0
Original line number Diff line number Diff line
@@ -96,6 +96,11 @@ class DesktopTasksController(
        }
    }

    /** Get number of tasks that are marked as visible */
    fun getVisibleTaskCount(): Int {
        return desktopModeTaskRepository.getVisibleTaskCount()
    }

    /** Move a task with given `taskId` to desktop */
    fun moveToDesktop(taskId: Int) {
        shellTaskOrganizer.getRunningTaskInfo(taskId)?.let { task -> moveToDesktop(task) }
@@ -309,5 +314,16 @@ class DesktopTasksController(
                Consumer(DesktopTasksController::showDesktopApps)
            )
        }

        override fun getVisibleTaskCount(): Int {
            val result = IntArray(1)
            ExecutorUtils.executeRemoteCallWithTaskPermission(
                controller,
                "getVisibleTaskCount",
                { controller -> result[0] = controller.getVisibleTaskCount() },
                true /* blocking */
            )
            return result[0]
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -23,4 +23,7 @@ interface IDesktopMode {

    /** Show apps on the desktop */
    void showDesktopApps();

    /** Get count of visible desktop tasks */
    int getVisibleTaskCount();
}
 No newline at end of file
+35 −0
Original line number Diff line number Diff line
@@ -333,6 +333,41 @@ public class DesktopModeControllerTest extends ShellTestCase {
        assertThat(op2.getContainer()).isEqualTo(task2.token.asBinder());
    }

    @Test
    public void testGetVisibleTaskCount_noTasks_returnsZero() {
        assertThat(mController.getVisibleTaskCount()).isEqualTo(0);
    }

    @Test
    public void testGetVisibleTaskCount_twoTasks_bothVisible_returnsTwo() {
        RunningTaskInfo task1 = createFreeformTask();
        mDesktopModeTaskRepository.addActiveTask(task1.taskId);
        mDesktopModeTaskRepository.addOrMoveFreeformTaskToTop(task1.taskId);
        mDesktopModeTaskRepository.updateVisibleFreeformTasks(task1.taskId, true /* visible */);

        RunningTaskInfo task2 = createFreeformTask();
        mDesktopModeTaskRepository.addActiveTask(task2.taskId);
        mDesktopModeTaskRepository.addOrMoveFreeformTaskToTop(task2.taskId);
        mDesktopModeTaskRepository.updateVisibleFreeformTasks(task2.taskId, true /* visible */);

        assertThat(mController.getVisibleTaskCount()).isEqualTo(2);
    }

    @Test
    public void testGetVisibleTaskCount_twoTasks_oneVisible_returnsOne() {
        RunningTaskInfo task1 = createFreeformTask();
        mDesktopModeTaskRepository.addActiveTask(task1.taskId);
        mDesktopModeTaskRepository.addOrMoveFreeformTaskToTop(task1.taskId);
        mDesktopModeTaskRepository.updateVisibleFreeformTasks(task1.taskId, true /* visible */);

        RunningTaskInfo task2 = createFreeformTask();
        mDesktopModeTaskRepository.addActiveTask(task2.taskId);
        mDesktopModeTaskRepository.addOrMoveFreeformTaskToTop(task2.taskId);
        mDesktopModeTaskRepository.updateVisibleFreeformTasks(task2.taskId, false /* visible */);

        assertThat(mController.getVisibleTaskCount()).isEqualTo(1);
    }

    @Test
    public void testHandleTransitionRequest_desktopModeNotActive_returnsNull() {
        when(DesktopModeStatus.isActive(any())).thenReturn(false);
Loading