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

Commit 3c15dd4c authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas Committed by Android (Google) Code Review
Browse files

Merge "Update desktop mode flag checks to include device config check" into main

parents 5a3c7054 96e7d5d0
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -891,13 +891,13 @@ public abstract class WMShellBaseModule {

    @WMSingleton
    @Provides
    static Optional<DesktopTasksController> providesDesktopTasksController(
    static Optional<DesktopTasksController> providesDesktopTasksController(Context context,
            @DynamicOverride Optional<Lazy<DesktopTasksController>> desktopTasksController) {
        // 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
        // when it will not be returned due to the condition below.
        return desktopTasksController.flatMap((lazy)-> {
            if (DesktopModeStatus.isEnabled()) {
            if (DesktopModeStatus.canEnterDesktopMode(context)) {
                return Optional.of(lazy.get());
            }
            return Optional.empty();
@@ -910,13 +910,13 @@ public abstract class WMShellBaseModule {

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

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

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

    @WMSingleton
+4 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.ActivityManager.RunningTaskInfo
import android.app.ActivityTaskManager.INVALID_TASK_ID
import android.app.TaskInfo
import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
import android.content.Context
import android.os.IBinder
import android.util.SparseArray
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.
 */
class DesktopModeLoggerTransitionObserver(
    context: Context,
    shellInit: ShellInit,
    private val transitions: Transitions,
    private val desktopModeEventLogger: DesktopModeEventLogger
@@ -57,7 +59,8 @@ class DesktopModeLoggerTransitionObserver(
    private val idSequence: InstanceIdSequence by lazy { InstanceIdSequence(Int.MAX_VALUE) }

    init {
        if (Transitions.ENABLE_SHELL_TRANSITIONS && DesktopModeStatus.isEnabled()) {
        if (Transitions.ENABLE_SHELL_TRANSITIONS &&
            DesktopModeStatus.canEnterDesktopMode(context)) {
            shellInit.addInitCallback(this::onInit, this)
        }
    }
+5 −3
Original line number Diff line number Diff line
@@ -93,8 +93,10 @@ public class DesktopModeStatus {
            "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() {
        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) {
        return !enforceDeviceRestrictions() || isDesktopModeSupported(context);
        return (!enforceDeviceRestrictions() || isDesktopModeSupported(context)) && isEnabled();
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ class DesktopTasksController(

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