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

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

Merge "Make `DesktopModeLaunchParamsModifier` no-op if desktop mode not supported" into main

parents 483ca0f5 3884da77
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -6987,4 +6987,7 @@

    <!-- Wear devices: An intent action that is used for remote intent. -->
    <string name="config_wearRemoteIntentAction" translatable="false" />

    <!-- Whether desktop mode is supported on the current device  -->
    <bool name="config_isDesktopModeSupported">false</bool>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -5387,4 +5387,7 @@
  <java-symbol type="bool" name="config_deviceSupportsHighPerfTransitions" />

  <java-symbol type="string" name="config_wearRemoteIntentAction" />

  <!-- Whether desktop mode is supported on the current device  -->
  <java-symbol type="bool" name="config_isDesktopModeSupported" />
</resources>
+0 −3
Original line number Diff line number Diff line
@@ -148,7 +148,4 @@

    <!-- Whether pointer pilfer is required to start back animation. -->
    <bool name="config_backAnimationRequiresPointerPilfer">true</bool>

    <!-- Whether desktop mode is supported on the current device  -->
    <bool name="config_isDesktopModeSupported">false</bool>
</resources>
+1 −1
Original line number Diff line number Diff line
@@ -20,9 +20,9 @@ import android.annotation.NonNull;
import android.content.Context;
import android.os.SystemProperties;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.window.flags.Flags;
import com.android.wm.shell.R;

/**
 * Constants for desktop mode feature
+43 −4
Original line number Diff line number Diff line
@@ -19,13 +19,17 @@ package com.android.server.wm;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Rect;
import android.os.SystemProperties;
import android.util.Slog;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.wm.LaunchParamsController.LaunchParamsModifier;
import com.android.window.flags.Flags;
/**
@@ -37,14 +41,24 @@ public class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            TAG_WITH_CLASS_NAME ? "DesktopModeLaunchParamsModifier" : TAG_ATM;
    private static final boolean DEBUG = false;

    private static final boolean DESKTOP_MODE_PROTO2_SUPPORTED =
            SystemProperties.getBoolean("persist.wm.debug.desktop_mode_2", false);
    public static final float DESKTOP_MODE_INITIAL_BOUNDS_SCALE =
            SystemProperties
                    .getInt("persist.wm.debug.desktop_mode_initial_bounds_scale", 75) / 100f;

    /**
     * Flag to indicate whether to restrict desktop mode to supported devices.
     */
    private static final boolean ENFORCE_DEVICE_RESTRICTIONS = SystemProperties.getBoolean(
            "persist.wm.debug.desktop_mode_enforce_device_restrictions", true);

    private StringBuilder mLogBuilder;

    private final Context mContext;

    DesktopModeLaunchParamsModifier(@NonNull Context context) {
        mContext = context;
    }

    @Override
    public int onCalculate(@Nullable Task task, @Nullable ActivityInfo.WindowLayout layout,
            @Nullable ActivityRecord activity, @Nullable ActivityRecord source,
@@ -65,7 +79,7 @@ public class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            LaunchParamsController.LaunchParams currentParams,
            LaunchParamsController.LaunchParams outParams) {

        if (!isDesktopModeEnabled()) {
        if (!canEnterDesktopMode(mContext)) {
            appendLog("desktop mode is not enabled, continuing");
            return RESULT_CONTINUE;
        }
@@ -90,7 +104,7 @@ public class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
        // previous windowing mode to be restored even if the desktop mode state has changed.
        // Let task launches inherit the windowing mode from the source task if available, which
        // should have the desired windowing mode set by WM Shell. See b/286929122.
        if (isDesktopModeEnabled() && source != null && source.getTask() != null) {
        if (source != null && source.getTask() != null) {
            final Task sourceTask = source.getTask();
            outParams.mWindowingMode = sourceTask.getWindowingMode();
            appendLog("inherit-from-source=" + outParams.mWindowingMode);
@@ -147,4 +161,29 @@ public class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
    static boolean isDesktopModeEnabled() {
        return Flags.enableDesktopWindowingMode();
    }

    /**
     * Return {@code true} if desktop mode should be restricted to supported devices.
     */
    @VisibleForTesting
    public boolean enforceDeviceRestrictions() {
        return ENFORCE_DEVICE_RESTRICTIONS;
    }

    /**
     * Return {@code true} if the current device supports desktop mode.
     */
    @VisibleForTesting
    public boolean isDesktopModeSupported(@NonNull Context context) {
        return context.getResources().getBoolean(R.bool.config_isDesktopModeSupported);
    }

    /**
     * Return {@code true} if desktop mode can be entered on the current device.
     */
    boolean canEnterDesktopMode(@NonNull Context context) {
        return isDesktopModeEnabled()
                && (!enforceDeviceRestrictions() || isDesktopModeSupported(context));
    }

}
Loading