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

Commit 96e7d5d0 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas
Browse files

Update desktop mode flag checks to include device config check

Update `DesktopModeStatus.canEnterDesktopMode()` to include the desktop
windowing flag check. Replace all uses of
`DesktopModeStatus.isEnabled()` with
`DesktopModeStatus.canEnterDesktopMode()` to check both the state of the
flag and whether the device is compatible with desktop mode.

Flag: None
Bug: 339093954
Test: atest WMShellUnitTests:DesktopModeLoggerTransitionObserverTest
Test: atest WMShellUnitTests:DesktopTasksControllerTest
Test: atest WMShellUnitTests:FreeformTaskListenerTests
Test: atest WMShellUnitTests:RecentTasksControllerTest
Test: atest WMShellUnitTests:DesktopModeWindowDecorViewModelTests
Test: atest WMShellUnitTests:DesktopModeWindowDecorationTests

Change-Id: If0846062c2234f1d89fcde271150f3e613fd45cb
parent 09b0a7c5
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -891,13 +891,13 @@ public abstract class WMShellBaseModule {


    @WMSingleton
    @WMSingleton
    @Provides
    @Provides
    static Optional<DesktopTasksController> providesDesktopTasksController(
    static Optional<DesktopTasksController> providesDesktopTasksController(Context context,
            @DynamicOverride Optional<Lazy<DesktopTasksController>> desktopTasksController) {
            @DynamicOverride Optional<Lazy<DesktopTasksController>> desktopTasksController) {
        // Use optional-of-lazy for the dependency that this provider relies on.
        // Use optional-of-lazy for the dependency that this provider relies on.
        // Lazy ensures that this provider will not be the cause the dependency is created
        // Lazy ensures that this provider will not be the cause the dependency is created
        // when it will not be returned due to the condition below.
        // when it will not be returned due to the condition below.
        return desktopTasksController.flatMap((lazy)-> {
        return desktopTasksController.flatMap((lazy)-> {
            if (DesktopModeStatus.isEnabled()) {
            if (DesktopModeStatus.canEnterDesktopMode(context)) {
                return Optional.of(lazy.get());
                return Optional.of(lazy.get());
            }
            }
            return Optional.empty();
            return Optional.empty();
@@ -910,13 +910,13 @@ public abstract class WMShellBaseModule {


    @WMSingleton
    @WMSingleton
    @Provides
    @Provides
    static Optional<DesktopModeTaskRepository> provideDesktopTaskRepository(
    static Optional<DesktopModeTaskRepository> provideDesktopTaskRepository(Context context,
            @DynamicOverride Optional<Lazy<DesktopModeTaskRepository>> desktopModeTaskRepository) {
            @DynamicOverride Optional<Lazy<DesktopModeTaskRepository>> desktopModeTaskRepository) {
        // Use optional-of-lazy for the dependency that this provider relies on.
        // Use optional-of-lazy for the dependency that this provider relies on.
        // Lazy ensures that this provider will not be the cause the dependency is created
        // Lazy ensures that this provider will not be the cause the dependency is created
        // when it will not be returned due to the condition below.
        // when it will not be returned due to the condition below.
        return desktopModeTaskRepository.flatMap((lazy)-> {
        return desktopModeTaskRepository.flatMap((lazy)-> {
            if (DesktopModeStatus.isEnabled()) {
            if (DesktopModeStatus.canEnterDesktopMode(context)) {
                return Optional.of(lazy.get());
                return Optional.of(lazy.get());
            }
            }
            return Optional.empty();
            return Optional.empty();
+11 −6
Original line number Original line Diff line number Diff line
@@ -221,7 +221,7 @@ public abstract class WMShellModule {
            Transitions transitions,
            Transitions transitions,
            Optional<DesktopTasksController> desktopTasksController,
            Optional<DesktopTasksController> desktopTasksController,
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer) {
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer) {
        if (DesktopModeStatus.isEnabled()) {
        if (DesktopModeStatus.canEnterDesktopMode(context)) {
            return new DesktopModeWindowDecorViewModel(
            return new DesktopModeWindowDecorViewModel(
                    context,
                    context,
                    mainExecutor,
                    mainExecutor,
@@ -278,8 +278,8 @@ public abstract class WMShellModule {
        ShellInit init = FreeformComponents.isFreeformEnabled(context)
        ShellInit init = FreeformComponents.isFreeformEnabled(context)
                ? shellInit
                ? shellInit
                : null;
                : null;
        return new FreeformTaskListener(init, shellTaskOrganizer, desktopModeTaskRepository,
        return new FreeformTaskListener(context, init, shellTaskOrganizer,
                windowDecorViewModel);
                desktopModeTaskRepository, windowDecorViewModel);
    }
    }


    @WMSingleton
    @WMSingleton
@@ -535,10 +535,12 @@ public abstract class WMShellModule {
    @WMSingleton
    @WMSingleton
    @Provides
    @Provides
    static Optional<DesktopTasksLimiter> provideDesktopTasksLimiter(
    static Optional<DesktopTasksLimiter> provideDesktopTasksLimiter(
            Context context,
            Transitions transitions,
            Transitions transitions,
            @DynamicOverride DesktopModeTaskRepository desktopModeTaskRepository,
            @DynamicOverride DesktopModeTaskRepository desktopModeTaskRepository,
            ShellTaskOrganizer shellTaskOrganizer) {
            ShellTaskOrganizer shellTaskOrganizer) {
        if (!DesktopModeStatus.isEnabled() || !Flags.enableDesktopWindowingTaskLimit()) {
        if (!DesktopModeStatus.canEnterDesktopMode(context)
                || !Flags.enableDesktopWindowingTaskLimit()) {
            return Optional.empty();
            return Optional.empty();
        }
        }
        return Optional.of(
        return Optional.of(
@@ -592,23 +594,26 @@ public abstract class WMShellModule {
    @WMSingleton
    @WMSingleton
    @Provides
    @Provides
    static Optional<DesktopTasksTransitionObserver> provideDesktopTasksTransitionObserver(
    static Optional<DesktopTasksTransitionObserver> provideDesktopTasksTransitionObserver(
            Context context,
            Optional<DesktopModeTaskRepository> desktopModeTaskRepository,
            Optional<DesktopModeTaskRepository> desktopModeTaskRepository,
            Transitions transitions,
            Transitions transitions,
            ShellInit shellInit
            ShellInit shellInit
    ) {
    ) {
        return desktopModeTaskRepository.flatMap(repository ->
        return desktopModeTaskRepository.flatMap(repository ->
                Optional.of(new DesktopTasksTransitionObserver(repository, transitions, shellInit))
                Optional.of(new DesktopTasksTransitionObserver(
                        context, repository, transitions, shellInit))
        );
        );
    }
    }


    @WMSingleton
    @WMSingleton
    @Provides
    @Provides
    static DesktopModeLoggerTransitionObserver provideDesktopModeLoggerTransitionObserver(
    static DesktopModeLoggerTransitionObserver provideDesktopModeLoggerTransitionObserver(
            Context context,
            ShellInit shellInit,
            ShellInit shellInit,
            Transitions transitions,
            Transitions transitions,
            DesktopModeEventLogger desktopModeEventLogger) {
            DesktopModeEventLogger desktopModeEventLogger) {
        return new DesktopModeLoggerTransitionObserver(
        return new DesktopModeLoggerTransitionObserver(
                shellInit, transitions, desktopModeEventLogger);
                context, shellInit, transitions, desktopModeEventLogger);
    }
    }


    @WMSingleton
    @WMSingleton
+4 −1
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.ActivityManager.RunningTaskInfo
import android.app.ActivityTaskManager.INVALID_TASK_ID
import android.app.ActivityTaskManager.INVALID_TASK_ID
import android.app.TaskInfo
import android.app.TaskInfo
import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
import android.content.Context
import android.os.IBinder
import android.os.IBinder
import android.util.SparseArray
import android.util.SparseArray
import android.view.SurfaceControl
import android.view.SurfaceControl
@@ -49,6 +50,7 @@ import com.android.wm.shell.util.KtProtoLog
 * and other transitions that originate both within and outside shell.
 * and other transitions that originate both within and outside shell.
 */
 */
class DesktopModeLoggerTransitionObserver(
class DesktopModeLoggerTransitionObserver(
    context: Context,
    shellInit: ShellInit,
    shellInit: ShellInit,
    private val transitions: Transitions,
    private val transitions: Transitions,
    private val desktopModeEventLogger: DesktopModeEventLogger
    private val desktopModeEventLogger: DesktopModeEventLogger
@@ -57,7 +59,8 @@ class DesktopModeLoggerTransitionObserver(
    private val idSequence: InstanceIdSequence by lazy { InstanceIdSequence(Int.MAX_VALUE) }
    private val idSequence: InstanceIdSequence by lazy { InstanceIdSequence(Int.MAX_VALUE) }


    init {
    init {
        if (Transitions.ENABLE_SHELL_TRANSITIONS && DesktopModeStatus.isEnabled()) {
        if (Transitions.ENABLE_SHELL_TRANSITIONS &&
            DesktopModeStatus.canEnterDesktopMode(context)) {
            shellInit.addInitCallback(this::onInit, this)
            shellInit.addInitCallback(this::onInit, this)
        }
        }
    }
    }
+5 −3
Original line number Original line Diff line number Diff line
@@ -93,8 +93,10 @@ public class DesktopModeStatus {
            "persist.wm.debug.desktop_max_task_limit", DEFAULT_MAX_TASK_LIMIT);
            "persist.wm.debug.desktop_max_task_limit", DEFAULT_MAX_TASK_LIMIT);


    /**
    /**
     * Return {@code true} if desktop windowing is enabled
     * Return {@code true} if desktop windowing is enabled. Only to be used for testing. Callers
     * should use {@link #canEnterDesktopMode(Context)} to query the state of desktop windowing.
     */
     */
    @VisibleForTesting
    public static boolean isEnabled() {
    public static boolean isEnabled() {
        return Flags.enableDesktopWindowingMode();
        return Flags.enableDesktopWindowingMode();
    }
    }
@@ -155,9 +157,9 @@ public class DesktopModeStatus {
    }
    }


    /**
    /**
     * Return {@code true} if desktop mode can be entered on the current device.
     * Return {@code true} if desktop mode is enabled and can be entered on the current device.
     */
     */
    public static boolean canEnterDesktopMode(@NonNull Context context) {
    public static boolean canEnterDesktopMode(@NonNull Context context) {
        return !enforceDeviceRestrictions() || isDesktopModeSupported(context);
        return (!enforceDeviceRestrictions() || isDesktopModeSupported(context)) && isEnabled();
    }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -167,7 +167,7 @@ class DesktopTasksController(


    init {
    init {
        desktopMode = DesktopModeImpl()
        desktopMode = DesktopModeImpl()
        if (DesktopModeStatus.isEnabled()) {
        if (DesktopModeStatus.canEnterDesktopMode(context)) {
            shellInit.addInitCallback({ onInit() }, this)
            shellInit.addInitCallback({ onInit() }, this)
        }
        }
    }
    }
Loading