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

Commit fe70c992 authored by Orhan Uysal's avatar Orhan Uysal Committed by Android (Google) Code Review
Browse files

Merge "Create a shell API to remove desktop" into main

parents 874b0f4a f3dcd3ad
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -80,6 +80,14 @@ class DesktopRepository (
            freeformTasksInZOrder = ArrayList(freeformTasksInZOrder),
            fullImmersiveTaskId = fullImmersiveTaskId
        )
        fun clear() {
            activeTasks.clear()
            visibleTasks.clear()
            minimizedTasks.clear()
            closingTasks.clear()
            freeformTasksInZOrder.clear()
            fullImmersiveTaskId = null
        }
    }

    /* Current wallpaper activity token to remove wallpaper activity when last task is removed. */
@@ -413,6 +421,19 @@ class DesktopRepository (
        }
    }

    /**
     * Removes the desktop for the given [displayId] and returns the active tasks on that desktop.
     */
    fun removeDesktop(displayId: Int): ArraySet<Int> {
        if (!desktopTaskDataByDisplayId.contains(displayId)) {
            logW("Could not find desktop to remove: displayId=%d", displayId)
            return ArraySet()
        }
        val activeTasks = ArraySet(desktopTaskDataByDisplayId[displayId].activeTasks)
        desktopTaskDataByDisplayId[displayId].clear()
        return activeTasks
    }

    /**
     * Updates active desktop gesture exclusion regions.
     *
+28 −5
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package com.android.wm.shell.desktopmode

import android.app.ActivityManager.RunningTaskInfo
import android.app.ActivityManager
import android.app.ActivityManager.RunningTaskInfo
import android.app.ActivityOptions
import android.app.KeyguardManager
import android.app.PendingIntent
@@ -44,6 +44,7 @@ import android.view.Display.DEFAULT_DISPLAY
import android.view.DragEvent
import android.view.SurfaceControl
import android.view.WindowManager.TRANSIT_CHANGE
import android.view.WindowManager.TRANSIT_CLOSE
import android.view.WindowManager.TRANSIT_NONE
import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_TO_FRONT
@@ -51,6 +52,10 @@ import android.window.RemoteTransition
import android.window.TransitionInfo
import android.window.TransitionRequestInfo
import android.window.WindowContainerTransaction
import android.window.flags.DesktopModeFlags
import android.window.flags.DesktopModeFlags.DISABLE_NON_RESIZABLE_APP_SNAP_RESIZE
import android.window.flags.DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY
import android.window.flags.DesktopModeFlags.ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS
import androidx.annotation.BinderThread
import com.android.internal.annotations.VisibleForTesting
import com.android.internal.jank.Cuj.CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_HOLD
@@ -86,10 +91,6 @@ import com.android.wm.shell.shared.ShellSharedConstants
import com.android.wm.shell.shared.TransitionUtil
import com.android.wm.shell.shared.annotations.ExternalThread
import com.android.wm.shell.shared.annotations.ShellMainThread
import android.window.flags.DesktopModeFlags
import android.window.flags.DesktopModeFlags.DISABLE_NON_RESIZABLE_APP_SNAP_RESIZE
import android.window.flags.DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY
import android.window.flags.DesktopModeFlags.ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus.DESKTOP_DENSITY_OVERRIDE
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus.useDesktopOverrideDensity
@@ -1473,6 +1474,22 @@ class DesktopTasksController(
        }
    }

    fun removeDesktop(displayId: Int) {
        if (!DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue()) return

        val tasksToRemove = taskRepository.removeDesktop(displayId)
        val wct = WindowContainerTransaction()
        tasksToRemove.forEach {
            val task = shellTaskOrganizer.getRunningTaskInfo(it)
            if (task != null) {
                wct.removeTask(task.token)
            } else {
                recentTasksController?.removeBackgroundTask(it)
            }
        }
        if (!wct.isEmpty) transitions.startTransition(TRANSIT_CLOSE, wct, null)
    }

    /** Enter split by using the focused desktop task in given `displayId`. */
    fun enterSplit(displayId: Int, leftOrTop: Boolean) {
        getFocusedFreeformTask(displayId)?.let { requestSplit(it, leftOrTop) }
@@ -2000,6 +2017,12 @@ class DesktopTasksController(
                c.moveTaskToDesktop(taskId, transitionSource = transitionSource)
            }
        }

        override fun removeDesktop(displayId: Int) {
            executeRemoteCallWithTaskPermission(controller, "removeDesktop") { c ->
                c.removeDesktop(displayId)
            }
        }
    }

    private fun logV(msg: String, vararg arguments: Any?) {
+3 −0
Original line number Diff line number Diff line
@@ -49,4 +49,7 @@ interface IDesktopMode {

    /** Move a task with given `taskId` to desktop */
    void moveToDesktop(int taskId, in DesktopModeTransitionSource transitionSource);

    /** Remove desktop on the given display */
    void removeDesktop(int displayId);
}
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
@@ -540,6 +540,14 @@ public class RecentTasksController implements TaskStackListenerCallback,
        return null;
    }

    /**
     * Remove the background task that match the given taskId. This will remove the task regardless
     * of whether it's active or recent.
     */
    public boolean removeBackgroundTask(int taskId) {
        return mActivityTaskManager.removeTask(taskId);
    }

    public void dump(@NonNull PrintWriter pw, String prefix) {
        final String innerPrefix = prefix + "  ";
        pw.println(prefix + TAG);
+17 −0
Original line number Diff line number Diff line
@@ -940,6 +940,23 @@ class DesktopRepositoryTest : ShellTestCase() {
        assertThat(repo.isTaskInFullImmersiveState(taskId = 2)).isTrue()
    }

    @Test
    fun removeDesktop_multipleTasks_removesAll() {
        repo.addActiveTask(displayId = DEFAULT_DISPLAY, taskId = 1)
        repo.addActiveTask(displayId = DEFAULT_DISPLAY, taskId = 2)
        repo.addActiveTask(displayId = DEFAULT_DISPLAY, taskId = 3)
        // The front-most task will be the one added last through `addOrMoveFreeformTaskToTop`
        repo.addOrMoveFreeformTaskToTop(displayId = DEFAULT_DISPLAY, taskId = 3)
        repo.addOrMoveFreeformTaskToTop(displayId = DEFAULT_DISPLAY, taskId = 2)
        repo.addOrMoveFreeformTaskToTop(displayId = DEFAULT_DISPLAY, taskId = 1)
        repo.minimizeTask(displayId = DEFAULT_DISPLAY, taskId = 2)

        val tasksBeforeRemoval = repo.removeDesktop(displayId = DEFAULT_DISPLAY)

        assertThat(tasksBeforeRemoval).containsExactly(1, 2, 3).inOrder()
        assertThat(repo.getActiveTasks(displayId = DEFAULT_DISPLAY)).isEmpty()
    }

    class TestListener : DesktopRepository.ActiveTasksListener {
        var activeChangesOnDefaultDisplay = 0
        var activeChangesOnSecondaryDisplay = 0
Loading