diff --git a/core/api/current.txt b/core/api/current.txt index 3773d3b09299f..038933783ea28 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -18809,9 +18809,14 @@ package android.hardware.display { method public android.view.Display getDisplay(int); method public android.view.Display[] getDisplays(); method public android.view.Display[] getDisplays(String); + method public int getMatchContentFrameRateUserPreference(); method public void registerDisplayListener(android.hardware.display.DisplayManager.DisplayListener, android.os.Handler); method public void unregisterDisplayListener(android.hardware.display.DisplayManager.DisplayListener); field public static final String DISPLAY_CATEGORY_PRESENTATION = "android.hardware.display.category.PRESENTATION"; + field public static final int MATCH_CONTENT_FRAMERATE_ALWAYS = 2; // 0x2 + field public static final int MATCH_CONTENT_FRAMERATE_NEVER = 0; // 0x0 + field public static final int MATCH_CONTENT_FRAMERATE_SEAMLESSS_ONLY = 1; // 0x1 + field public static final int MATCH_CONTENT_FRAMERATE_UNKNOWN = -1; // 0xffffffff field public static final int VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR = 16; // 0x10 field public static final int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 8; // 0x8 field public static final int VIRTUAL_DISPLAY_FLAG_PRESENTATION = 2; // 0x2 diff --git a/core/api/test-current.txt b/core/api/test-current.txt index 21771df3c6a3c..12a4c6d592da1 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -1141,7 +1141,6 @@ package android.hardware.display { public final class DisplayManager { method public boolean areUserDisabledHdrTypesAllowed(); - method @RequiresPermission(android.Manifest.permission.MODIFY_REFRESH_RATE_SWITCHING_TYPE) public int getRefreshRateSwitchingType(); method @NonNull public int[] getUserDisabledHdrTypes(); method public boolean isMinimalPostProcessingRequested(int); method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setAreUserDisabledHdrTypesAllowed(boolean); diff --git a/core/java/android/hardware/display/DisplayManager.java b/core/java/android/hardware/display/DisplayManager.java index 216e7b079f6b4..6c2d1402b303c 100644 --- a/core/java/android/hardware/display/DisplayManager.java +++ b/core/java/android/hardware/display/DisplayManager.java @@ -38,6 +38,7 @@ import android.media.projection.MediaProjection; import android.os.Build; import android.os.Handler; import android.util.Pair; +import android.util.Slog; import android.util.SparseArray; import android.view.Display; import android.view.Surface; @@ -347,6 +348,37 @@ public final class DisplayManager { public static final int VIRTUAL_DISPLAY_FLAG_OWN_DISPLAY_GROUP = 1 << 11; + /** @hide */ + @IntDef(prefix = {"MATCH_CONTENT_FRAMERATE_"}, value = { + MATCH_CONTENT_FRAMERATE_UNKNOWN, + MATCH_CONTENT_FRAMERATE_NEVER, + MATCH_CONTENT_FRAMERATE_SEAMLESSS_ONLY, + MATCH_CONTENT_FRAMERATE_ALWAYS, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface MatchContentFrameRateType {} + + /** + * Match content frame rate user preference is unknown. + */ + public static final int MATCH_CONTENT_FRAMERATE_UNKNOWN = -1; + + /** + * No mode switching is allowed. + */ + public static final int MATCH_CONTENT_FRAMERATE_NEVER = 0; + + /** + * Only refresh rate switches without visual interruptions are allowed. + */ + public static final int MATCH_CONTENT_FRAMERATE_SEAMLESSS_ONLY = 1; + + /** + * Refresh rate switches between all refresh rates are allowed even if they have visual + * interruptions for the user. + */ + public static final int MATCH_CONTENT_FRAMERATE_ALWAYS = 2; + /** @hide */ @IntDef(prefix = {"SWITCHING_TYPE_"}, value = { SWITCHING_TYPE_NONE, @@ -1076,14 +1108,36 @@ public final class DisplayManager { } /** - * Returns the refresh rate switching type. - * - * @hide + * Returns the user preference for "Match content frame rate". + *

+ * Never: Even if the app requests it, the device will never try to match its output to the + * original frame rate of the content. + *

+ * Seamless: If the app requests it, the device will match its output to the original frame + * rate of the content, ONLY if the display can transition seamlessly. + *

+ * Always: If the app requests it, the device will match its output to the original + * frame rate of the content. This may cause the screen to go blank for a + * second when exiting or entering a video playback. + *

*/ - @TestApi - @RequiresPermission(Manifest.permission.MODIFY_REFRESH_RATE_SWITCHING_TYPE) - @SwitchingType public int getRefreshRateSwitchingType() { - return mGlobal.getRefreshRateSwitchingType(); + @MatchContentFrameRateType public int getMatchContentFrameRateUserPreference() { + return toMatchContentFrameRateSetting(mGlobal.getRefreshRateSwitchingType()); + } + + @MatchContentFrameRateType + private int toMatchContentFrameRateSetting(@SwitchingType int switchingType) { + switch (switchingType) { + case SWITCHING_TYPE_NONE: + return MATCH_CONTENT_FRAMERATE_NEVER; + case SWITCHING_TYPE_WITHIN_GROUPS: + return MATCH_CONTENT_FRAMERATE_SEAMLESSS_ONLY; + case SWITCHING_TYPE_ACROSS_AND_WITHIN_GROUPS: + return MATCH_CONTENT_FRAMERATE_ALWAYS; + default: + Slog.e(TAG, switchingType + " is not a valid value of switching type."); + return MATCH_CONTENT_FRAMERATE_UNKNOWN; + } } /** diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java index 9d02576cefb70..393a4eb83dd68 100644 --- a/services/core/java/com/android/server/display/DisplayManagerService.java +++ b/services/core/java/com/android/server/display/DisplayManagerService.java @@ -2932,9 +2932,6 @@ public final class DisplayManagerService extends SystemService { @Override // Binder call public int getRefreshRateSwitchingType() { - mContext.enforceCallingOrSelfPermission( - Manifest.permission.MODIFY_REFRESH_RATE_SWITCHING_TYPE, - "Permission required read refresh rate switching type."); final long token = Binder.clearCallingIdentity(); try { return getRefreshRateSwitchingTypeInternal();