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

Commit 9d98b2a9 authored by Graciela Wissen Putri's avatar Graciela Wissen Putri
Browse files

[4/n] Add OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS

Per-app override for system to handle caption insets for apps targeting
SDK < 35 and couples configuration with the caption insets.

Flag: com.android.window.flags.exclude_caption_from_app_bounds
Test: atest DesktopModeCompatPolicyTest
Bug: 388014743
Change-Id: I9581d0938827d2ece607ffba8c251e39d10902b4
parent 7506a12b
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -1642,6 +1642,19 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
    @Overridable
    public static final long OVERRIDE_ENABLE_INSETS_DECOUPLED_CONFIGURATION = 327313645L;

    /**
     * When the override is enabled, the activity receives configuration coupled with caption bar
     * insets. Normally, caption bar insets are decoupled from configuration.
     *
     * <p>Override applies only if the activity targets SDK level 34 or earlier version.
     *
     * @hide
     */
    @ChangeId
    @Overridable
    @Disabled
    public static final long OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS = 388014743L;

    /**
     * Optional set of a certificates identifying apps that are allowed to embed this activity. From
     * the "knownActivityEmbeddingCerts" attribute.
+6 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context
import android.content.pm.ActivityInfo
import android.content.pm.ActivityInfo.INSETS_DECOUPLED_CONFIGURATION_ENFORCED
import android.content.pm.ActivityInfo.OVERRIDE_ENABLE_INSETS_DECOUPLED_CONFIGURATION
import android.content.pm.ActivityInfo.OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS
import android.window.DesktopModeFlags
import com.android.internal.R
import com.android.window.flags.Flags
@@ -59,13 +60,16 @@ class DesktopModeCompatPolicy(private val context: Context) {
     * The treatment is enabled when all the of the following is true:
     * * Any flags to forcibly consume caption insets are enabled.
     * * Top activity have configuration coupled with insets.
     * * Task is not resizeable.
     * * Task is not resizeable or [ActivityInfo.OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS]
     * is enabled.
     */
    fun shouldExcludeCaptionFromAppBounds(taskInfo: TaskInfo): Boolean =
        Flags.excludeCaptionFromAppBounds()
                && isAnyForceConsumptionFlagsEnabled()
                && taskInfo.topActivityInfo?.let {
            isInsetsCoupledWithConfiguration(it) && !taskInfo.isResizeable
            isInsetsCoupledWithConfiguration(it) && (!taskInfo.isResizeable || it.isChangeEnabled(
                OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS
            ))
        } ?: false

    /**
+11 −0
Original line number Diff line number Diff line
@@ -181,6 +181,17 @@ class DesktopModeCompatPolicyTest : ShellTestCase() {
        )
    }


    @Test
    @EnableFlags(Flags.FLAG_EXCLUDE_CAPTION_FROM_APP_BOUNDS)
    @DisableCompatChanges(ActivityInfo.INSETS_DECOUPLED_CONFIGURATION_ENFORCED)
    @EnableCompatChanges(ActivityInfo.OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS)
    fun testShouldExcludeCaptionFromAppBounds_resizeable_overridden_true() {
        assertTrue(desktopModeCompatPolicy.shouldExcludeCaptionFromAppBounds(
            setUpFreeformTask().apply { isResizeable = true })
        )
    }

    fun setUpFreeformTask(): TaskInfo =
        createFreeformTask().apply {
            val componentName =