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

Commit 98452ad0 authored by Kazuki Takise's avatar Kazuki Takise Committed by Android (Google) Code Review
Browse files

Merge "Choose focused task by default with moveToNextDisplay" into main

parents 77346784 099de090
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -802,6 +802,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,
@@ -217,7 +219,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
@@ -423,6 +425,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            recentTasksController,
            mockInteractionJankMonitor,
            mockHandler,
            focusTransitionObserver,
            desktopModeEventLogger,
            desktopModeUiEventLogger,
            desktopWallpaperActivityTokenProvider,