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

Commit 0de70a41 authored by Ats Jenk's avatar Ats Jenk Committed by Android (Google) Code Review
Browse files

Merge "Move check for 'desktop mode active' to helper" into tm-qpr-dev

parents 52176fa6 fe50d13c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ import com.android.wm.shell.common.TaskStackListenerImpl;
import com.android.wm.shell.common.TransactionPool;
import com.android.wm.shell.common.annotations.ShellBackgroundThread;
import com.android.wm.shell.common.annotations.ShellMainThread;
import com.android.wm.shell.desktopmode.DesktopModeConstants;
import com.android.wm.shell.desktopmode.DesktopMode;
import com.android.wm.shell.desktopmode.DesktopModeController;
import com.android.wm.shell.draganddrop.DragAndDropController;
import com.android.wm.shell.freeform.FreeformComponents;
@@ -599,7 +599,7 @@ public abstract class WMShellModule {
            RootDisplayAreaOrganizer rootDisplayAreaOrganizer,
            @ShellMainThread Handler mainHandler
    ) {
        if (DesktopModeConstants.IS_FEATURE_ENABLED) {
        if (DesktopMode.IS_SUPPORTED) {
            return Optional.of(new DesktopModeController(context, shellInit, shellTaskOrganizer,
                    rootDisplayAreaOrganizer,
                    mainHandler));
+58 −0
Original line number Diff line number Diff line
@@ -16,16 +16,43 @@

package com.android.wm.shell.desktopmode;

import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE;

import android.content.Context;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;

import com.android.internal.protolog.common.ProtoLog;

/**
 * Constants for desktop mode feature
 */
public class DesktopModeConstants {
public class DesktopMode {

    /**
     * Flag to indicate whether desktop mode is available on the device
     */
    public static final boolean IS_FEATURE_ENABLED = SystemProperties.getBoolean(
    public static final boolean IS_SUPPORTED = SystemProperties.getBoolean(
            "persist.wm.debug.desktop_mode", false);

    /**
     * Check if desktop mode is active
     *
     * @return {@code true} if active
     */
    public static boolean isActive(Context context) {
        if (!IS_SUPPORTED) {
            return false;
        }
        try {
            int result = Settings.System.getIntForUser(context.getContentResolver(),
                    Settings.System.DESKTOP_MODE, UserHandle.USER_CURRENT);
            ProtoLog.d(WM_SHELL_DESKTOP_MODE, "isDesktopModeEnabled=%s", result);
            return result != 0;
        } catch (Settings.SettingNotFoundException e) {
            ProtoLog.e(WM_SHELL_DESKTOP_MODE, "Failed to read DESKTOP_MODE setting %s", e);
            return false;
        }
    }
}
+5 −17
Original line number Diff line number Diff line
@@ -65,8 +65,8 @@ public class DesktopModeController {
    }

    @VisibleForTesting
    void updateDesktopModeEnabled(boolean enabled) {
        ProtoLog.d(WM_SHELL_DESKTOP_MODE, "updateDesktopModeState: enabled=%s", enabled);
    void updateDesktopModeActive(boolean active) {
        ProtoLog.d(WM_SHELL_DESKTOP_MODE, "updateDesktopModeActive: active=%s", active);

        int displayId = mContext.getDisplayId();

@@ -75,7 +75,7 @@ public class DesktopModeController {
        // container value)
        wct.merge(mShellTaskOrganizer.prepareClearFreeformForTasks(displayId), true /* transfer */);
        int targetWindowingMode;
        if (enabled) {
        if (active) {
            targetWindowingMode = WINDOWING_MODE_FREEFORM;
        } else {
            targetWindowingMode = WINDOWING_MODE_FULLSCREEN;
@@ -118,20 +118,8 @@ public class DesktopModeController {
        }

        private void desktopModeSettingChanged() {
            boolean enabled = isDesktopModeEnabled();
            updateDesktopModeEnabled(enabled);
        }

        private boolean isDesktopModeEnabled() {
            try {
                int result = Settings.System.getIntForUser(mContext.getContentResolver(),
                        Settings.System.DESKTOP_MODE, UserHandle.USER_CURRENT);
                ProtoLog.d(WM_SHELL_DESKTOP_MODE, "isDesktopModeEnabled=%s", result);
                return result != 0;
            } catch (Settings.SettingNotFoundException e) {
                ProtoLog.e(WM_SHELL_DESKTOP_MODE, "Failed to read DESKTOP_MODE setting %s", e);
                return false;
            }
            boolean enabled = DesktopMode.isActive(mContext);
            updateDesktopModeActive(enabled);
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import com.android.wm.shell.R;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.desktopmode.DesktopModeConstants;
import com.android.wm.shell.desktopmode.DesktopMode;

/**
 * Defines visuals and behaviors of a window decoration of a caption bar and shadows. It works with
@@ -164,7 +164,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
        View caption = mResult.mRootView.findViewById(R.id.caption);
        caption.setOnTouchListener(mOnCaptionTouchListener);
        View maximize = caption.findViewById(R.id.maximize_window);
        if (DesktopModeConstants.IS_FEATURE_ENABLED) {
        if (DesktopMode.IS_SUPPORTED) {
            // Hide maximize button when desktop mode is available
            maximize.setVisibility(View.GONE);
        } else {
+2 −2
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ public class DesktopModeControllerTest extends ShellTestCase {
                WINDOWING_MODE_FREEFORM)).thenReturn(displayWct);

        // The test
        mController.updateDesktopModeEnabled(true);
        mController.updateDesktopModeActive(true);

        ArgumentCaptor<WindowContainerTransaction> arg = ArgumentCaptor.forClass(
                WindowContainerTransaction.class);
@@ -144,7 +144,7 @@ public class DesktopModeControllerTest extends ShellTestCase {
                WINDOWING_MODE_FULLSCREEN)).thenReturn(displayWct);

        // The test
        mController.updateDesktopModeEnabled(false);
        mController.updateDesktopModeActive(false);

        ArgumentCaptor<WindowContainerTransaction> arg = ArgumentCaptor.forClass(
                WindowContainerTransaction.class);
Loading