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

Commit 6f151129 authored by Kazuki Takise's avatar Kazuki Takise
Browse files

Improve compat mode logging

- Dump shouldCreateAppCompatDisplayInsets() for SCM-eligible apps
 because currently you can tell if an app is eligible for SCM or
 not from activity dump only after mSizeCompatScale or
 mSizeCompatBounds is created (a bit error prone for manual
 testers)

- Dump DCM info
 Dump (i) whether an app is eligible for DCM and (ii) the app is
 currently in DCM. To achieve this, this change also refactors
 AppCompatDisplayCompatModePolicy() so dynamic and static factors
 are clearly seperated in getDisplayCompatModeConfigMask().

Flag: com.android.window.flags.enable_display_compat_mode
Bug: 413176299
Test: adb shell dumpsys activity top-resumed
Change-Id: Ifcbf9522aefc14935f915c519a66d3ee781d3651
parent 5757704a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@ class AppCompatController {
        getTransparentPolicy().dump(pw, prefix);
        getLetterboxPolicy().dump(pw, prefix);
        getSizeCompatModePolicy().dump(pw, prefix);
        getDisplayCompatModePolicy().dump(pw, prefix);
        getSafeRegionPolicy().dump(pw, prefix);
    }
}
+25 −7
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import static android.window.DesktopExperienceFlags.ENABLE_RESTART_MENU_FOR_CONN
import android.annotation.NonNull;
import android.content.pm.ApplicationInfo;

import java.io.PrintWriter;

/**
 * Encapsulate app-compat logic for multi-display environments.
 *
@@ -64,8 +66,7 @@ class AppCompatDisplayCompatModePolicy {
     */
    boolean isRestartMenuEnabledForDisplayMove() {
        // Restart menu is only available to apps in display compat mode.
        return ENABLE_RESTART_MENU_FOR_CONNECTED_DISPLAYS.isTrue() && mDisplayChangedWithoutRestart
                && getDisplayCompatModeConfigMask() != 0;
        return ENABLE_RESTART_MENU_FOR_CONNECTED_DISPLAYS.isTrue() && isInDisplayCompatMode();
    }

    /**
@@ -93,6 +94,14 @@ class AppCompatDisplayCompatModePolicy {
        mDisplayChangedWithoutRestart = false;
    }

    private boolean isInDisplayCompatMode() {
        return getDisplayCompatModeConfigMask() != 0;
    }

    private boolean isEligibleForDisplayCompatMode() {
        return getStaticDisplayCompatModeConfigMask() != 0;
    }

    /**
     * Returns the mask of the config changes that should not trigger activity restart with display
     * move for app-compat reasons.
@@ -101,6 +110,11 @@ class AppCompatDisplayCompatModePolicy {
     * display compat mode is not enabled for the activity.
     */
    int getDisplayCompatModeConfigMask() {
        // Enable display compat mode only when display move is involved.
        return mDisplayChangedWithoutRestart ? getStaticDisplayCompatModeConfigMask() : 0;
    }

    private int getStaticDisplayCompatModeConfigMask() {
        if (!ENABLE_DISPLAY_COMPAT_MODE.isTrue()) return 0;

        if (mActivityRecord.info.applicationInfo.category != ApplicationInfo.CATEGORY_GAME) {
@@ -109,15 +123,19 @@ class AppCompatDisplayCompatModePolicy {
            return 0;
        }

        if (!mDisplayChangedWithoutRestart) {
            // Enable display compat mode when display move is involved.
            return 0;
        }

        // If a specific config change is supported by the activity, it's exempted from this compat
        // treatment. This way, apps can opt out from display compat mode by handling all the config
        // changes that happen with display move by themselves.
        final int supportedConfigChanged = mActivityRecord.info.getRealConfigChanged();
        return DISPLAY_COMPAT_MODE_CONFIG_MASK & (~supportedConfigChanged);
    }

    void dump(@NonNull PrintWriter pw, @NonNull String prefix) {
        if (isEligibleForDisplayCompatMode()) {
            pw.println(prefix + "isEligibleForDisplayCompatMode=true");
        }
        if (isInDisplayCompatMode()) {
            pw.println(prefix + "isInDisplayCompatMode=true");
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -201,6 +201,9 @@ class AppCompatSizeCompatModePolicy {
            pw.println(prefix + "mSizeCompatScale=" + mSizeCompatScale + " mSizeCompatBounds="
                    + mSizeCompatBounds);
        }
        if (shouldCreateAppCompatDisplayInsets()) {
            pw.println(prefix + "shouldCreateAppCompatDisplayInsets=true");
        }
    }

    /**