diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/hardware/display/DisplayManager.java | 39 | ||||
| -rw-r--r-- | core/java/android/hardware/display/DisplayManagerGlobal.java | 43 | ||||
| -rw-r--r-- | core/java/android/hardware/display/IDisplayManager.aidl | 9 | ||||
| -rw-r--r-- | core/java/android/provider/Settings.java | 34 | ||||
| -rw-r--r-- | core/java/android/view/Display.java | 37 | ||||
| -rw-r--r-- | core/java/android/view/DisplayInfo.java | 16 | ||||
| -rw-r--r-- | core/java/android/view/SurfaceControl.java | 16 |
7 files changed, 192 insertions, 2 deletions
diff --git a/core/java/android/hardware/display/DisplayManager.java b/core/java/android/hardware/display/DisplayManager.java index 6dd67447c321..3100610f8e68 100644 --- a/core/java/android/hardware/display/DisplayManager.java +++ b/core/java/android/hardware/display/DisplayManager.java @@ -17,6 +17,7 @@ package android.hardware.display; import static android.view.Display.DEFAULT_DISPLAY; +import static android.view.Display.HdrCapabilities.HdrType; import android.Manifest; import android.annotation.IntDef; @@ -709,6 +710,44 @@ public final class DisplayManager { } /** + * Sets the HDR types that have been disabled by user. + * @param userDisabledTypes the HDR types to disable. + * @hide + */ + @TestApi + @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS) + public void setUserDisabledHdrTypes(@NonNull @HdrType int[] userDisabledTypes) { + mGlobal.setUserDisabledHdrTypes(userDisabledTypes); + } + + /** + * Sets whether or not the user disabled HDR types are returned from + * {@link Display#getHdrCapabilities}. + * + * @param areUserDisabledHdrTypesAllowed If true, the user-disabled types + * are ignored and returned, if the display supports them. If false, the + * user-disabled types are taken into consideration and are never returned, + * even if the display supports them. + * @hide + */ + @TestApi + @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS) + public void setAreUserDisabledHdrTypesAllowed(boolean areUserDisabledHdrTypesAllowed) { + mGlobal.setAreUserDisabledHdrTypesAllowed(areUserDisabledHdrTypesAllowed); + } + + /** + * Returns whether or not the user-disabled HDR types are returned from + * {@link Display#getHdrCapabilities}. + * + * @hide + */ + @TestApi + public boolean areUserDisabledHdrTypesAllowed() { + return mGlobal.areUserDisabledHdrTypesAllowed(); + } + + /** * Creates a virtual display. * * @see #createVirtualDisplay(String, int, int, int, Surface, int, diff --git a/core/java/android/hardware/display/DisplayManagerGlobal.java b/core/java/android/hardware/display/DisplayManagerGlobal.java index fd0431c5bc3f..5de4ad2a2243 100644 --- a/core/java/android/hardware/display/DisplayManagerGlobal.java +++ b/core/java/android/hardware/display/DisplayManagerGlobal.java @@ -16,7 +16,9 @@ package android.hardware.display; + import static android.hardware.display.DisplayManager.EventsMask; +import static android.view.Display.HdrCapabilities.HdrType; import android.annotation.IntDef; import android.annotation.NonNull; @@ -508,6 +510,47 @@ public final class DisplayManagerGlobal { } } + /** + * Sets the HDR types that have been disabled by user. + * @param userDisabledHdrTypes the HDR types to disable. The HDR types are any of + */ + public void setUserDisabledHdrTypes(@HdrType int[] userDisabledHdrTypes) { + try { + mDm.setUserDisabledHdrTypes(userDisabledHdrTypes); + } catch (RemoteException ex) { + throw ex.rethrowFromSystemServer(); + } + } + + /** + * Sets whether or not the user disabled HDR types are returned from + * {@link Display#getHdrCapabilities}. + * + * @param areUserDisabledHdrTypesAllowed If true, the user-disabled + * types are ignored and returned, if the display supports them. If + * false, the user-disabled types are taken into consideration and + * are never returned, even if the display supports them. + */ + public void setAreUserDisabledHdrTypesAllowed(boolean areUserDisabledHdrTypesAllowed) { + try { + mDm.setAreUserDisabledHdrTypesAllowed(areUserDisabledHdrTypesAllowed); + } catch (RemoteException ex) { + throw ex.rethrowFromSystemServer(); + } + } + + /** + * Returns whether or not the user-disabled HDR types are returned from + * {@link Display#getHdrCapabilities}. + */ + public boolean areUserDisabledHdrTypesAllowed() { + try { + return mDm.areUserDisabledHdrTypesAllowed(); + } catch (RemoteException ex) { + throw ex.rethrowFromSystemServer(); + } + } + public void requestColorMode(int displayId, int colorMode) { try { mDm.requestColorMode(displayId, colorMode); diff --git a/core/java/android/hardware/display/IDisplayManager.aidl b/core/java/android/hardware/display/IDisplayManager.aidl index dee91445c224..db95132bd0c2 100644 --- a/core/java/android/hardware/display/IDisplayManager.aidl +++ b/core/java/android/hardware/display/IDisplayManager.aidl @@ -68,6 +68,15 @@ interface IDisplayManager { // No permissions required. WifiDisplayStatus getWifiDisplayStatus(); + // Requires WRITE_SECURE_SETTINGS permission. + void setUserDisabledHdrTypes(in int[] userDisabledTypes); + + // Requires WRITE_SECURE_SETTINGS permission. + void setAreUserDisabledHdrTypesAllowed(boolean areUserDisabledHdrTypesAllowed); + + // No permissions required. + boolean areUserDisabledHdrTypesAllowed(); + // Requires CONFIGURE_DISPLAY_COLOR_MODE void requestColorMode(int displayId, int colorMode); diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 719c38392fb1..08b80c206411 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -14041,6 +14041,40 @@ public final class Settings { @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public static final int ZEN_MODE_ALARMS = 3; + /** + * A comma-separated list of HDR formats that have been disabled by the user. + * <p> + * If present, these formats will not be reported to apps, even if the display supports + * them. This list is treated as empty if the ARE_USER_DISABLED_HDR_FORMATS_ALLOWED setting + * is '1'. + * </p> + * @hide + */ + @TestApi + @Readable + @SuppressLint("NoSettingsProvider") + public static final String USER_DISABLED_HDR_FORMATS = "user_disabled_hdr_formats"; + + /** + * Whether or not user-disabled HDR formats are allowed. + * <p> + * The value is boolean (1 or 0). The value '1' means the user preference for disabling a + * format is ignored, and the disabled formats are still reported to apps (if supported + * by the display). The value '0' means the user-disabled formats are not reported to + * apps, even if the display supports them. + * </p><p> + * The list of formats disabled by the user are contained in the + * USER_DISABLED_HDR_FORMATS setting. This list is treated as empty when the value of + * this setting is '1'. + * </p> + * @hide + */ + @TestApi + @Readable + @SuppressLint("NoSettingsProvider") + public static final String ARE_USER_DISABLED_HDR_FORMATS_ALLOWED = + "are_user_disabled_hdr_formats_allowed"; + /** @hide */ public static String zenModeToString(int mode) { if (mode == ZEN_MODE_IMPORTANT_INTERRUPTIONS) return "ZEN_MODE_IMPORTANT_INTERRUPTIONS"; if (mode == ZEN_MODE_ALARMS) return "ZEN_MODE_ALARMS"; diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java index d484f4d47e99..1e2271abee90 100644 --- a/core/java/android/view/Display.java +++ b/core/java/android/view/Display.java @@ -44,6 +44,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.Process; import android.os.SystemClock; +import android.util.ArraySet; import android.util.DisplayMetrics; import android.util.Log; @@ -1066,7 +1067,31 @@ public final class Display { public HdrCapabilities getHdrCapabilities() { synchronized (mLock) { updateDisplayInfoLocked(); - return mDisplayInfo.hdrCapabilities; + if (mDisplayInfo.userDisabledHdrTypes.length == 0) { + return mDisplayInfo.hdrCapabilities; + } + ArraySet<Integer> enabledTypesSet = new ArraySet<>(); + for (int supportedType : mDisplayInfo.hdrCapabilities.getSupportedHdrTypes()) { + boolean typeDisabled = false; + for (int userDisabledType : mDisplayInfo.userDisabledHdrTypes) { + if (supportedType == userDisabledType) { + typeDisabled = true; + break; + } + } + if (!typeDisabled) { + enabledTypesSet.add(supportedType); + } + } + int[] enabledTypes = new int[enabledTypesSet.size()]; + int index = 0; + for (int enabledType : enabledTypesSet) { + enabledTypes[index++] = enabledType; + } + return new HdrCapabilities(enabledTypes, + mDisplayInfo.hdrCapabilities.mMaxLuminance, + mDisplayInfo.hdrCapabilities.mMaxAverageLuminance, + mDisplayInfo.hdrCapabilities.mMinLuminance); } } @@ -1079,7 +1104,7 @@ public final class Display { public boolean isHdr() { synchronized (mLock) { updateDisplayInfoLocked(); - return mDisplayInfo.isHdr(); + return !(getHdrCapabilities().getSupportedHdrTypes().length == 0); } } @@ -1855,6 +1880,14 @@ public final class Display { public static final int HDR_TYPE_HDR10_PLUS = 4; /** @hide */ + public static final int[] HDR_TYPES = { + HDR_TYPE_DOLBY_VISION, + HDR_TYPE_HDR10, + HDR_TYPE_HLG, + HDR_TYPE_HDR10_PLUS + }; + + /** @hide */ @IntDef(prefix = { "HDR_TYPE_" }, value = { HDR_TYPE_DOLBY_VISION, HDR_TYPE_HDR10, diff --git a/core/java/android/view/DisplayInfo.java b/core/java/android/view/DisplayInfo.java index 9aaf5c066073..36be9f856282 100644 --- a/core/java/android/view/DisplayInfo.java +++ b/core/java/android/view/DisplayInfo.java @@ -198,6 +198,9 @@ public final class DisplayInfo implements Parcelable { /** The display's HDR capabilities */ public Display.HdrCapabilities hdrCapabilities; + /** The formats disabled by user **/ + public int[] userDisabledHdrTypes = {}; + /** * Indicates whether the display can be switched into a mode with minimal post * processing. @@ -363,6 +366,7 @@ public final class DisplayInfo implements Parcelable { && colorMode == other.colorMode && Arrays.equals(supportedColorModes, other.supportedColorModes) && Objects.equals(hdrCapabilities, other.hdrCapabilities) + && Arrays.equals(userDisabledHdrTypes, other.userDisabledHdrTypes) && minimalPostProcessingSupported == other.minimalPostProcessingSupported && logicalDensityDpi == other.logicalDensityDpi && physicalXDpi == other.physicalXDpi @@ -412,6 +416,7 @@ public final class DisplayInfo implements Parcelable { supportedColorModes = Arrays.copyOf( other.supportedColorModes, other.supportedColorModes.length); hdrCapabilities = other.hdrCapabilities; + userDisabledHdrTypes = other.userDisabledHdrTypes; minimalPostProcessingSupported = other.minimalPostProcessingSupported; logicalDensityDpi = other.logicalDensityDpi; physicalXDpi = other.physicalXDpi; @@ -478,6 +483,11 @@ public final class DisplayInfo implements Parcelable { brightnessMaximum = source.readFloat(); brightnessDefault = source.readFloat(); roundedCorners = source.readTypedObject(RoundedCorners.CREATOR); + int numUserDisabledFormats = source.readInt(); + userDisabledHdrTypes = new int[numUserDisabledFormats]; + for (int i = 0; i < numUserDisabledFormats; i++) { + userDisabledHdrTypes[i] = source.readInt(); + } } @Override @@ -528,6 +538,10 @@ public final class DisplayInfo implements Parcelable { dest.writeFloat(brightnessMaximum); dest.writeFloat(brightnessDefault); dest.writeTypedObject(roundedCorners, flags); + dest.writeInt(userDisabledHdrTypes.length); + for (int i = 0; i < userDisabledHdrTypes.length; i++) { + dest.writeInt(userDisabledHdrTypes[i]); + } } @Override @@ -729,6 +743,8 @@ public final class DisplayInfo implements Parcelable { sb.append(Arrays.toString(supportedModes)); sb.append(", hdrCapabilities "); sb.append(hdrCapabilities); + sb.append(", userDisabledHdrTypes "); + sb.append(Arrays.toString(userDisabledHdrTypes)); sb.append(", minimalPostProcessingSupported "); sb.append(minimalPostProcessingSupported); sb.append(", rotation "); diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 85d4878d044c..b2a84a29b9a1 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -190,6 +190,8 @@ public final class SurfaceControl implements Parcelable { private static native void nativeReparent(long transactionObj, long nativeObject, long newParentNativeObject); + private static native void nativeOverrideHdrTypes(IBinder displayToken, int[] modes); + private static native void nativeSetInputWindowInfo(long transactionObj, long nativeObject, InputWindowHandle handle); @@ -2204,6 +2206,18 @@ public final class SurfaceControl implements Parcelable { } /** + * Overrides HDR modes for a display device. + * + * If the caller does not have ACCESS_SURFACE_FLINGER permission, this will throw a Security + * Exception. + * @hide + */ + @TestApi + public static void overrideHdrTypes(@NonNull IBinder displayToken, @NonNull int[] modes) { + nativeOverrideHdrTypes(displayToken, modes); + } + + /** * @hide */ @UnsupportedAppUsage @@ -2244,6 +2258,8 @@ public final class SurfaceControl implements Parcelable { * * @hide */ + @TestApi + @NonNull public static IBinder getInternalDisplayToken() { final long[] physicalDisplayIds = getPhysicalDisplayIds(); if (physicalDisplayIds.length == 0) { |
