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

Commit 099de090 authored by Kazuki Takise's avatar Kazuki Takise
Browse files

Choose focused task by default with moveToNextDisplay

Flag: EXEMPT adb command change
Bug: 398984693
Test: adb shell dumpsys activity service SystemUIService WMShell desktopmode moveToNextDisplay
Change-Id: I23bce9d53af079580480e08c1350d0f066443800
parent badfb594
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -800,6 +800,7 @@ public abstract class WMShellModule {
                recentTasksController.orElse(null),
                interactionJankMonitor,
                mainHandler,
                focusTransitionObserver,
                desktopModeEventLogger,
                desktopModeUiEventLogger,
                desktopWallpaperActivityTokenProvider,
+15 −10
Original line number Diff line number Diff line
@@ -16,14 +16,18 @@

package com.android.wm.shell.desktopmode

import android.app.ActivityTaskManager.INVALID_TASK_ID
import android.window.DesktopExperienceFlags
import com.android.wm.shell.shared.desktopmode.DesktopModeTransitionSource.UNKNOWN
import com.android.wm.shell.sysui.ShellCommandHandler
import com.android.wm.shell.transition.FocusTransitionObserver
import java.io.PrintWriter

/** Handles the shell commands for the DesktopTasksController. */
class DesktopModeShellCommandHandler(private val controller: DesktopTasksController) :
    ShellCommandHandler.ShellCommandActionHandler {
class DesktopModeShellCommandHandler(
    private val controller: DesktopTasksController,
    private val focusTransitionObserver: FocusTransitionObserver,
) : ShellCommandHandler.ShellCommandActionHandler {

    override fun onShellCommand(args: Array<String>, pw: PrintWriter): Boolean =
        when (args[0]) {
@@ -76,20 +80,21 @@ class DesktopModeShellCommandHandler(private val controller: DesktopTasksControl
    }

    private fun runMoveToNextDisplay(args: Array<String>, pw: PrintWriter): Boolean {
        var taskId = INVALID_TASK_ID
        if (args.size < 2) {
            // First argument is the action name.
            pw.println("Error: task id should be provided as arguments")
            return false
        }

        val taskId =
            taskId = focusTransitionObserver.globallyFocusedTaskId
        } else {
            try {
                args[1].toInt()
                taskId = args[1].toInt()
            } catch (e: NumberFormatException) {
                pw.println("Error: task id should be an integer")
                return false
            }

        }
        if (taskId == INVALID_TASK_ID) {
            pw.println("Error: no appropriate task found")
            return false
        }
        controller.moveToNextDisplay(taskId)
        return true
    }
+3 −1
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ import com.android.wm.shell.sysui.ShellCommandHandler
import com.android.wm.shell.sysui.ShellController
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.sysui.UserChangeListener
import com.android.wm.shell.transition.FocusTransitionObserver
import com.android.wm.shell.transition.OneShotRemoteHandler
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.transition.Transitions.TransitionFinishCallback
@@ -196,6 +197,7 @@ class DesktopTasksController(
    private val recentTasksController: RecentTasksController?,
    private val interactionJankMonitor: InteractionJankMonitor,
    @ShellMainThread private val handler: Handler,
    private val focusTransitionObserver: FocusTransitionObserver,
    private val desktopModeEventLogger: DesktopModeEventLogger,
    private val desktopModeUiEventLogger: DesktopModeUiEventLogger,
    private val desktopWallpaperActivityTokenProvider: DesktopWallpaperActivityTokenProvider,
@@ -216,7 +218,7 @@ class DesktopTasksController(
    private var visualIndicator: DesktopModeVisualIndicator? = null
    private var userId: Int
    private val desktopModeShellCommandHandler: DesktopModeShellCommandHandler =
        DesktopModeShellCommandHandler(this)
        DesktopModeShellCommandHandler(this, focusTransitionObserver)

    private val mOnAnimationFinishedCallback = { releaseVisualIndicator() }
    private lateinit var snapEventHandler: SnapEventHandler
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.wm.shell.transition;

import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.TRANSIT_CHANGE;
@@ -215,6 +216,17 @@ public class FocusTransitionObserver {
        return focusedTaskOnDisplay != null && focusedTaskOnDisplay.taskId == task.taskId;
    }

    /**
     * Gets the globally focused task ID.
     */
    public int getGloballyFocusedTaskId() {
        if (!enableDisplayFocusInShellTransitions() || mFocusedDisplayId == INVALID_DISPLAY) {
            return INVALID_TASK_ID;
        }
        final RunningTaskInfo globallyFocusedTask = mFocusedTaskOnDisplay.get(mFocusedDisplayId);
        return globallyFocusedTask != null ? globallyFocusedTask.taskId : INVALID_TASK_ID;
    }

    /**
     * Checks whether the given task has focused globally on the system.
     * (Note {@link RunningTaskInfo#isFocused} represents per-display focus.)
+3 −0
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ import com.android.wm.shell.splitscreen.SplitScreenController
import com.android.wm.shell.sysui.ShellCommandHandler
import com.android.wm.shell.sysui.ShellController
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.transition.FocusTransitionObserver
import com.android.wm.shell.transition.OneShotRemoteHandler
import com.android.wm.shell.transition.TestRemoteTransition
import com.android.wm.shell.transition.Transitions
@@ -239,6 +240,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
    @Mock private lateinit var taskbarDesktopTaskListener: TaskbarDesktopTaskListener
    @Mock private lateinit var freeformTaskTransitionStarter: FreeformTaskTransitionStarter
    @Mock private lateinit var mockHandler: Handler
    @Mock private lateinit var focusTransitionObserver: FocusTransitionObserver
    @Mock private lateinit var desktopModeEventLogger: DesktopModeEventLogger
    @Mock private lateinit var desktopModeUiEventLogger: DesktopModeUiEventLogger
    @Mock lateinit var persistentRepository: DesktopPersistentRepository
@@ -422,6 +424,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            recentTasksController,
            mockInteractionJankMonitor,
            mockHandler,
            focusTransitionObserver,
            desktopModeEventLogger,
            desktopModeUiEventLogger,
            desktopWallpaperActivityTokenProvider,