From c67906dbb90ede816d895158cd27a5bc615e50a0 Mon Sep 17 00:00:00 2001 From: Oleg Blinnikov Date: Wed, 15 Mar 2023 10:44:15 +0000 Subject: [PATCH] Add DOWNSCALED_INVERSE override Some applications could benefit from UPSCALE overrides, but we already have DOWNSCALED and DOWNSCALE_XX overrides. This CL uses DOWNSCALE_XX overrides but inverses the value to upscale the applications if DOWNSCALED_INVERSE is enabled. Bug: 273564678 Test: CtsWindowManagerDeviceTestCases:CompatScaleTests Change-Id: I9f76f56fc7eabb023cb1188aa6a7d8b96cba518d Merged-In: I9f76f56fc7eabb023cb1188aa6a7d8b96cba518d --- .../android/server/wm/CompatModePackages.java | 279 ++++++++++++------ 1 file changed, 182 insertions(+), 97 deletions(-) diff --git a/services/core/java/com/android/server/wm/CompatModePackages.java b/services/core/java/com/android/server/wm/CompatModePackages.java index d5828ef082512..c6978fd591343 100644 --- a/services/core/java/com/android/server/wm/CompatModePackages.java +++ b/services/core/java/com/android/server/wm/CompatModePackages.java @@ -17,7 +17,6 @@ package com.android.server.wm; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_CONFIGURATION; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.wm.ActivityTaskSupervisor.PRESERVE_WINDOWS; @@ -62,37 +61,60 @@ import java.util.Iterator; import java.util.Map; public final class CompatModePackages { - private static final String TAG = TAG_WITH_CLASS_NAME ? "CompatModePackages" : TAG_ATM; - private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; - - private final ActivityTaskManagerService mService; - private GameManagerInternal mGameManager; - private final AtomicFile mFile; - - // Compatibility state: no longer ask user to select the mode. - private static final int COMPAT_FLAG_DONT_ASK = 1<<0; - // Compatibility state: compatibility mode is enabled. - private static final int COMPAT_FLAG_ENABLED = 1<<1; + /** + * {@link CompatModePackages#DOWNSCALED_INVERSE} is the gatekeeper of all per-app buffer inverse + * downscale changes. Enabling this change will allow the following scaling factors: + * {@link CompatModePackages#DOWNSCALE_90} + * {@link CompatModePackages#DOWNSCALE_85} + * {@link CompatModePackages#DOWNSCALE_80} + * {@link CompatModePackages#DOWNSCALE_75} + * {@link CompatModePackages#DOWNSCALE_70} + * {@link CompatModePackages#DOWNSCALE_65} + * {@link CompatModePackages#DOWNSCALE_60} + * {@link CompatModePackages#DOWNSCALE_55} + * {@link CompatModePackages#DOWNSCALE_50} + * {@link CompatModePackages#DOWNSCALE_45} + * {@link CompatModePackages#DOWNSCALE_40} + * {@link CompatModePackages#DOWNSCALE_35} + * {@link CompatModePackages#DOWNSCALE_30} + * + * If {@link CompatModePackages#DOWNSCALED_INVERSE} is enabled for an app package, then the app + * will be forcibly resized to the lowest enabled scaling factor e.g. 1/0.8 if both 1/0.8 and + * 1/0.7 (* 100%) were enabled. + * + * When both {@link CompatModePackages#DOWNSCALED_INVERSE} + * and {@link CompatModePackages#DOWNSCALED} are enabled, then + * {@link CompatModePackages#DOWNSCALED_INVERSE} takes precedence. + */ + @ChangeId + @Disabled + @Overridable + public static final long DOWNSCALED_INVERSE = 273564678L; // This is a Bug ID. /** - * CompatModePackages#DOWNSCALED is the gatekeeper of all per-app buffer downscaling - * changes. Disabling this change will prevent the following scaling factors from working: - * CompatModePackages#DOWNSCALE_90 - * CompatModePackages#DOWNSCALE_85 - * CompatModePackages#DOWNSCALE_80 - * CompatModePackages#DOWNSCALE_75 - * CompatModePackages#DOWNSCALE_70 - * CompatModePackages#DOWNSCALE_65 - * CompatModePackages#DOWNSCALE_60 - * CompatModePackages#DOWNSCALE_55 - * CompatModePackages#DOWNSCALE_50 - * CompatModePackages#DOWNSCALE_45 - * CompatModePackages#DOWNSCALE_40 - * CompatModePackages#DOWNSCALE_35 - * CompatModePackages#DOWNSCALE_30 + * {@link CompatModePackages#DOWNSCALED} is the gatekeeper of all per-app buffer downscaling + * changes. Enabling this change will allow the following scaling factors: + * {@link CompatModePackages#DOWNSCALE_90} + * {@link CompatModePackages#DOWNSCALE_85} + * {@link CompatModePackages#DOWNSCALE_80} + * {@link CompatModePackages#DOWNSCALE_75} + * {@link CompatModePackages#DOWNSCALE_70} + * {@link CompatModePackages#DOWNSCALE_65} + * {@link CompatModePackages#DOWNSCALE_60} + * {@link CompatModePackages#DOWNSCALE_55} + * {@link CompatModePackages#DOWNSCALE_50} + * {@link CompatModePackages#DOWNSCALE_45} + * {@link CompatModePackages#DOWNSCALE_40} + * {@link CompatModePackages#DOWNSCALE_35} + * {@link CompatModePackages#DOWNSCALE_30} * - * If CompatModePackages#DOWNSCALED is enabled for an app package, then the app will be forcibly - * resized to the highest enabled scaling factor e.g. 80% if both 80% and 70% were enabled. + * If {@link CompatModePackages#DOWNSCALED} is enabled for an app package, then the app will be + * forcibly resized to the highest enabled scaling factor e.g. 80% if both 80% and 70% were + * enabled. + * + * When both {@link CompatModePackages#DOWNSCALED_INVERSE} + * and {@link CompatModePackages#DOWNSCALED} are enabled, then + * {@link CompatModePackages#DOWNSCALED_INVERSE} takes precedence. */ @ChangeId @Disabled @@ -100,9 +122,12 @@ public final class CompatModePackages { public static final long DOWNSCALED = 168419799L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_90 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_90} for a package will force the app to assume it's * running on a display with 90% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 111.11% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -110,9 +135,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_90 = 182811243L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_85 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_85} for a package will force the app to assume it's * running on a display with 85% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 117.65% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -120,9 +148,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_85 = 189969734L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_80 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_80} for a package will force the app to assume it's * running on a display with 80% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 125% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -130,9 +161,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_80 = 176926753L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_75 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_75} for a package will force the app to assume it's * running on a display with 75% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 133.33% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -140,9 +174,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_75 = 189969779L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_70 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_70} for a package will force the app to assume it's * running on a display with 70% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 142.86% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -150,9 +187,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_70 = 176926829L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_65 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_65} for a package will force the app to assume it's * running on a display with 65% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 153.85% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -160,9 +200,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_65 = 189969744L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_60 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_60} for a package will force the app to assume it's * running on a display with 60% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 166.67% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -170,9 +213,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_60 = 176926771L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_55 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_55} for a package will force the app to assume it's * running on a display with 55% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 181.82% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -180,9 +226,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_55 = 189970036L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_50 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_50} for a package will force the app to assume it's * running on a display with 50% vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 200% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -190,9 +239,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_50 = 176926741L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_45 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_45} for a package will force the app to assume it's * running on a display with 45% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 222.22% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -200,9 +252,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_45 = 189969782L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_40 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_40} for a package will force the app to assume it's * running on a display with 40% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 250% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -210,9 +265,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_40 = 189970038L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_35 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_35} for a package will force the app to assume it's * running on a display with 35% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 285.71% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -220,9 +278,12 @@ public final class CompatModePackages { public static final long DOWNSCALE_35 = 189969749L; /** - * With CompatModePackages#DOWNSCALED enabled, subsequently enabling change-id - * CompatModePackages#DOWNSCALE_30 for a package will force the app to assume it's + * With {@link CompatModePackages#DOWNSCALED} enabled, subsequently enabling change-id + * {@link CompatModePackages#DOWNSCALE_30} for a package will force the app to assume it's * running on a display with 30% the vertical and horizontal resolution of the real display. + * + * With {@link CompatModePackages#DOWNSCALED_INVERSE} enabled will force the app to assume it's + * running on a display with 333.33% the vertical and horizontal resolution of the real display */ @ChangeId @Disabled @@ -240,11 +301,15 @@ public final class CompatModePackages { @EnabledSince(targetSdkVersion = Build.VERSION_CODES.S) private static final long DO_NOT_DOWNSCALE_TO_1080P_ON_TV = 157629738L; // This is a Bug ID. - private final HashMap mPackages = new HashMap(); - private static final int MSG_WRITE = 300; - private final CompatHandler mHandler; + private static final String TAG = TAG_WITH_CLASS_NAME ? "CompatModePackages" : TAG_ATM; + + // Compatibility state: no longer ask user to select the mode. + private static final int COMPAT_FLAG_DONT_ASK = 1 << 0; + + // Compatibility state: compatibility mode is enabled. + private static final int COMPAT_FLAG_ENABLED = 1 << 1; private final class CompatHandler extends Handler { public CompatHandler(Looper looper) { @@ -261,6 +326,12 @@ public final class CompatModePackages { } } + private final ActivityTaskManagerService mService; + private GameManagerInternal mGameManager; + private final AtomicFile mFile; + private final HashMap mPackages = new HashMap<>(); + private final CompatHandler mHandler; + public CompatModePackages(ActivityTaskManagerService service, File systemDir, Handler handler) { mService = service; mFile = new AtomicFile(new File(systemDir, "packages-compat.xml"), "compat-mode"); @@ -390,45 +461,16 @@ public final class CompatModePackages { } } - if (CompatChanges.isChangeEnabled(DOWNSCALED, packageName, userHandle)) { - if (CompatChanges.isChangeEnabled(DOWNSCALE_90, packageName, userHandle)) { - return 1f / 0.9f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_85, packageName, userHandle)) { - return 1f / 0.85f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_80, packageName, userHandle)) { - return 1f / 0.8f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_75, packageName, userHandle)) { - return 1f / 0.75f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_70, packageName, userHandle)) { - return 1f / 0.7f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_65, packageName, userHandle)) { - return 1f / 0.65f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_60, packageName, userHandle)) { - return 1f / 0.6f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_55, packageName, userHandle)) { - return 1f / 0.55f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_50, packageName, userHandle)) { - return 1f / 0.5f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_45, packageName, userHandle)) { - return 1f / 0.45f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_40, packageName, userHandle)) { - return 1f / 0.4f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_35, packageName, userHandle)) { - return 1f / 0.35f; - } - if (CompatChanges.isChangeEnabled(DOWNSCALE_30, packageName, userHandle)) { - return 1f / 0.3f; + final boolean isDownscaledEnabled = CompatChanges.isChangeEnabled( + DOWNSCALED, packageName, userHandle); + final boolean isDownscaledInverseEnabled = CompatChanges.isChangeEnabled( + DOWNSCALED_INVERSE, packageName, userHandle); + if (isDownscaledEnabled || isDownscaledInverseEnabled) { + final float scalingFactor = getScalingFactor(packageName, userHandle); + if (scalingFactor != 1f) { + // For Upscaling the returned factor must be scalingFactor + // For Downscaling the returned factor must be 1f / scalingFactor + return isDownscaledInverseEnabled ? scalingFactor : 1f / scalingFactor; } } @@ -445,6 +487,49 @@ public final class CompatModePackages { return 1f; } + private static float getScalingFactor(String packageName, UserHandle userHandle) { + if (CompatChanges.isChangeEnabled(DOWNSCALE_90, packageName, userHandle)) { + return 0.9f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_85, packageName, userHandle)) { + return 0.85f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_80, packageName, userHandle)) { + return 0.8f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_75, packageName, userHandle)) { + return 0.75f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_70, packageName, userHandle)) { + return 0.7f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_65, packageName, userHandle)) { + return 0.65f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_60, packageName, userHandle)) { + return 0.6f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_55, packageName, userHandle)) { + return 0.55f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_50, packageName, userHandle)) { + return 0.5f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_45, packageName, userHandle)) { + return 0.45f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_40, packageName, userHandle)) { + return 0.4f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_35, packageName, userHandle)) { + return 0.35f; + } + if (CompatChanges.isChangeEnabled(DOWNSCALE_30, packageName, userHandle)) { + return 0.3f; + } + return 1f; + } + public int computeCompatModeLocked(ApplicationInfo ai) { final CompatibilityInfo info = compatibilityInfoForPackageLocked(ai); if (info.alwaysSupportsScreen()) {