Loading core/api/current.txt +2 −0 Original line number Original line Diff line number Diff line Loading @@ -20809,6 +20809,7 @@ package android.hardware.display { method public int describeContents(); method public int describeContents(); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @FloatRange(from=0.0f, to=1.0f) public float getDefaultBrightness(); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @FloatRange(from=0.0f, to=1.0f) public float getDefaultBrightness(); method public int getDensityDpi(); method public int getDensityDpi(); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @FloatRange(from=0.0f, to=1.0f) public float getDimBrightness(); method @NonNull public java.util.Set<java.lang.String> getDisplayCategories(); method @NonNull public java.util.Set<java.lang.String> getDisplayCategories(); method public int getFlags(); method public int getFlags(); method public int getHeight(); method public int getHeight(); Loading @@ -20830,6 +20831,7 @@ package android.hardware.display { method @NonNull public android.hardware.display.VirtualDisplayConfig build(); method @NonNull public android.hardware.display.VirtualDisplayConfig build(); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setBrightnessListener(@NonNull java.util.concurrent.Executor, @NonNull android.hardware.display.VirtualDisplayConfig.BrightnessListener); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setBrightnessListener(@NonNull java.util.concurrent.Executor, @NonNull android.hardware.display.VirtualDisplayConfig.BrightnessListener); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDefaultBrightness(@FloatRange(from=0.0f, to=1.0f) float); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDefaultBrightness(@FloatRange(from=0.0f, to=1.0f) float); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDimBrightness(@FloatRange(from=0.0f, to=1.0f) float); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDisplayCategories(@NonNull java.util.Set<java.lang.String>); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDisplayCategories(@NonNull java.util.Set<java.lang.String>); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setFlags(int); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setFlags(int); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setRequestedRefreshRate(@FloatRange(from=0.0f) float); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setRequestedRefreshRate(@FloatRange(from=0.0f) float); core/java/android/hardware/display/VirtualDisplayConfig.java +65 −5 Original line number Original line Diff line number Diff line Loading @@ -66,6 +66,7 @@ public final class VirtualDisplayConfig implements Parcelable { private final DisplayCutout mDisplayCutout; private final DisplayCutout mDisplayCutout; private final boolean mIgnoreActivitySizeRestrictions; private final boolean mIgnoreActivitySizeRestrictions; private final float mDefaultBrightness; private final float mDefaultBrightness; private final float mDimBrightness; private final IBrightnessListener mBrightnessListener; private final IBrightnessListener mBrightnessListener; private VirtualDisplayConfig( private VirtualDisplayConfig( Loading @@ -84,6 +85,7 @@ public final class VirtualDisplayConfig implements Parcelable { @Nullable DisplayCutout displayCutout, @Nullable DisplayCutout displayCutout, boolean ignoreActivitySizeRestrictions, boolean ignoreActivitySizeRestrictions, @FloatRange(from = 0.0f, to = 1.0f) float defaultBrightness, @FloatRange(from = 0.0f, to = 1.0f) float defaultBrightness, @FloatRange(from = 0.0f, to = 1.0f) float dimBrightness, IBrightnessListener brightnessListener) { IBrightnessListener brightnessListener) { mName = name; mName = name; mWidth = width; mWidth = width; Loading @@ -100,6 +102,7 @@ public final class VirtualDisplayConfig implements Parcelable { mDisplayCutout = displayCutout; mDisplayCutout = displayCutout; mIgnoreActivitySizeRestrictions = ignoreActivitySizeRestrictions; mIgnoreActivitySizeRestrictions = ignoreActivitySizeRestrictions; mDefaultBrightness = defaultBrightness; mDefaultBrightness = defaultBrightness; mDimBrightness = dimBrightness; mBrightnessListener = brightnessListener; mBrightnessListener = brightnessListener; } } Loading Loading @@ -179,6 +182,19 @@ public final class VirtualDisplayConfig implements Parcelable { return mDefaultBrightness; return mDefaultBrightness; } } /** * Returns the dim brightness of the display. * * <p>Value of {@code 0.0} indicates the minimum supported brightness and value of {@code 1.0} * indicates the maximum supported brightness.</p> * * @see Builder#setDimBrightness(float) */ @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_DEVICE_AWARE_DISPLAY_POWER) public @FloatRange(from = 0.0f, to = 1.0f) float getDimBrightness() { return mDimBrightness; } /** /** * Returns the listener to get notified about changes in the display brightness. * Returns the listener to get notified about changes in the display brightness. * @hide * @hide Loading Loading @@ -278,6 +294,7 @@ public final class VirtualDisplayConfig implements Parcelable { DisplayCutout.ParcelableWrapper.writeCutoutToParcel(mDisplayCutout, dest, flags); DisplayCutout.ParcelableWrapper.writeCutoutToParcel(mDisplayCutout, dest, flags); dest.writeBoolean(mIgnoreActivitySizeRestrictions); dest.writeBoolean(mIgnoreActivitySizeRestrictions); dest.writeFloat(mDefaultBrightness); dest.writeFloat(mDefaultBrightness); dest.writeFloat(mDimBrightness); dest.writeStrongBinder(mBrightnessListener != null ? mBrightnessListener.asBinder() : null); dest.writeStrongBinder(mBrightnessListener != null ? mBrightnessListener.asBinder() : null); } } Loading Loading @@ -308,8 +325,8 @@ public final class VirtualDisplayConfig implements Parcelable { && mIgnoreActivitySizeRestrictions == that.mIgnoreActivitySizeRestrictions && mIgnoreActivitySizeRestrictions == that.mIgnoreActivitySizeRestrictions && Objects.equals(mDisplayCutout, that.mDisplayCutout) && Objects.equals(mDisplayCutout, that.mDisplayCutout) && mDefaultBrightness == that.mDefaultBrightness && mDefaultBrightness == that.mDefaultBrightness && mDimBrightness == that.mDimBrightness && Objects.equals(mBrightnessListener, that.mBrightnessListener); && Objects.equals(mBrightnessListener, that.mBrightnessListener); } } @Override @Override Loading @@ -318,7 +335,8 @@ public final class VirtualDisplayConfig implements Parcelable { mName, mWidth, mHeight, mDensityDpi, mFlags, mSurface, mUniqueId, mName, mWidth, mHeight, mDensityDpi, mFlags, mSurface, mUniqueId, mDisplayIdToMirror, mWindowManagerMirroringEnabled, mDisplayCategories, mDisplayIdToMirror, mWindowManagerMirroringEnabled, mDisplayCategories, mRequestedRefreshRate, mIsHomeSupported, mDisplayCutout, mRequestedRefreshRate, mIsHomeSupported, mDisplayCutout, mIgnoreActivitySizeRestrictions, mDefaultBrightness, mBrightnessListener); mIgnoreActivitySizeRestrictions, mDefaultBrightness, mDimBrightness, mBrightnessListener); return hashCode; return hashCode; } } Loading @@ -341,6 +359,7 @@ public final class VirtualDisplayConfig implements Parcelable { + " mDisplayCutout=" + mDisplayCutout + " mDisplayCutout=" + mDisplayCutout + " mIgnoreActivitySizeRestrictions=" + mIgnoreActivitySizeRestrictions + " mIgnoreActivitySizeRestrictions=" + mIgnoreActivitySizeRestrictions + " mDefaultBrightness=" + mDefaultBrightness + " mDefaultBrightness=" + mDefaultBrightness + " mDimBrightness=" + mDimBrightness + ")"; + ")"; } } Loading @@ -360,8 +379,8 @@ public final class VirtualDisplayConfig implements Parcelable { mDisplayCutout = DisplayCutout.ParcelableWrapper.readCutoutFromParcel(in); mDisplayCutout = DisplayCutout.ParcelableWrapper.readCutoutFromParcel(in); mIgnoreActivitySizeRestrictions = in.readBoolean(); mIgnoreActivitySizeRestrictions = in.readBoolean(); mDefaultBrightness = in.readFloat(); mDefaultBrightness = in.readFloat(); mDimBrightness = in.readFloat(); mBrightnessListener = IBrightnessListener.Stub.asInterface(in.readStrongBinder()); mBrightnessListener = IBrightnessListener.Stub.asInterface(in.readStrongBinder()); } } /** /** Loading Loading @@ -432,6 +451,7 @@ public final class VirtualDisplayConfig implements Parcelable { private DisplayCutout mDisplayCutout = null; private DisplayCutout mDisplayCutout = null; private boolean mIgnoreActivitySizeRestrictions = false; private boolean mIgnoreActivitySizeRestrictions = false; private float mDefaultBrightness = 0.0f; private float mDefaultBrightness = 0.0f; private float mDimBrightness = PowerManager.BRIGHTNESS_INVALID; private IBrightnessListener mBrightnessListener = null; private IBrightnessListener mBrightnessListener = null; /** /** Loading Loading @@ -635,14 +655,14 @@ public final class VirtualDisplayConfig implements Parcelable { * * * <p>If unset, defaults to {@code 0.0}</p> * <p>If unset, defaults to {@code 0.0}</p> * * * @throws IllegalArgumentException if the brightness is outside the valid range [0.0, 1.0] * @see android.view.View#setKeepScreenOn(boolean) * @see android.view.View#setKeepScreenOn(boolean) * @see #setBrightnessListener(Executor, BrightnessListener) * @see #setBrightnessListener(Executor, BrightnessListener) */ */ @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_DEVICE_AWARE_DISPLAY_POWER) @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_DEVICE_AWARE_DISPLAY_POWER) @NonNull @NonNull public Builder setDefaultBrightness(@FloatRange(from = 0.0f, to = 1.0f) float brightness) { public Builder setDefaultBrightness(@FloatRange(from = 0.0f, to = 1.0f) float brightness) { if (brightness < PowerManager.BRIGHTNESS_MIN if (!isValidBrightness(brightness)) { || brightness > PowerManager.BRIGHTNESS_MAX) { throw new IllegalArgumentException( throw new IllegalArgumentException( "Virtual display default brightness must be in range [0.0, 1.0]"); "Virtual display default brightness must be in range [0.0, 1.0]"); } } Loading @@ -650,6 +670,33 @@ public final class VirtualDisplayConfig implements Parcelable { return this; return this; } } /** * Sets the dim brightness of the display. * * <p>The system will use this brightness value whenever the display should be dim, i.e. * it is powered on and dimmed due to user activity or app activity.</p> * * <p>Value of {@code 0.0} indicates the minimum supported brightness and value of * {@code 1.0} indicates the maximum supported brightness.</p> * * <p>If set, the default brightness must also be set to a value greater or equal to the * dim brightness. If unset, defaults to the system default.</p> * * @throws IllegalArgumentException if the brightness is outside the valid range [0.0, 1.0] * @see Builder#setDefaultBrightness(float) * @see #setBrightnessListener(Executor, BrightnessListener) */ @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_DEVICE_AWARE_DISPLAY_POWER) @NonNull public Builder setDimBrightness(@FloatRange(from = 0.0f, to = 1.0f) float brightness) { if (!isValidBrightness(brightness)) { throw new IllegalArgumentException( "Virtual display dim brightness must be in range [0.0, 1.0]"); } mDimBrightness = brightness; return this; } /** /** * Sets the listener to get notified about changes in the display brightness. * Sets the listener to get notified about changes in the display brightness. * * Loading @@ -666,11 +713,23 @@ public final class VirtualDisplayConfig implements Parcelable { return this; return this; } } private boolean isValidBrightness(float brightness) { return !Float.isNaN(brightness) && PowerManager.BRIGHTNESS_MIN <= brightness && brightness <= PowerManager.BRIGHTNESS_MAX; } /** /** * Builds the {@link VirtualDisplayConfig} instance. * Builds the {@link VirtualDisplayConfig} instance. * * @throws IllegalArgumentException if the dim brightness is set to a value greater than * the default brightness. */ */ @NonNull @NonNull public VirtualDisplayConfig build() { public VirtualDisplayConfig build() { if (isValidBrightness(mDimBrightness) && mDimBrightness > mDefaultBrightness) { throw new IllegalArgumentException( "The dim brightness must not be greater than the default brightness"); } return new VirtualDisplayConfig( return new VirtualDisplayConfig( mName, mName, mWidth, mWidth, Loading @@ -687,6 +746,7 @@ public final class VirtualDisplayConfig implements Parcelable { mDisplayCutout, mDisplayCutout, mIgnoreActivitySizeRestrictions, mIgnoreActivitySizeRestrictions, mDefaultBrightness, mDefaultBrightness, mDimBrightness, mBrightnessListener); mBrightnessListener); } } } } Loading core/java/android/os/IPowerManager.aidl +1 −1 Original line number Original line Diff line number Diff line Loading @@ -55,7 +55,7 @@ interface IPowerManager void goToSleepWithDisplayId(int displayId, long time, int reason, int flags); void goToSleepWithDisplayId(int displayId, long time, int reason, int flags); @UnsupportedAppUsage(maxTargetSdk = 28) @UnsupportedAppUsage(maxTargetSdk = 28) void nap(long time); void nap(long time); float getBrightnessConstraint(int constraint); float getBrightnessConstraint(int displayId, int constraint); @UnsupportedAppUsage @UnsupportedAppUsage boolean isInteractive(); boolean isInteractive(); boolean isDisplayInteractive(int displayId); boolean isDisplayInteractive(int displayId); Loading core/java/android/os/PowerManager.java +10 −2 Original line number Original line Diff line number Diff line Loading @@ -1266,9 +1266,17 @@ public final class PowerManager { * @hide * @hide */ */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public float getBrightnessConstraint(int constraint) { public float getBrightnessConstraint(@BrightnessConstraint int constraint) { return getBrightnessConstraint(Display.DEFAULT_DISPLAY, constraint); } /** * Gets a float screen brightness setting for a specific display. * @hide */ public float getBrightnessConstraint(int displayId, @BrightnessConstraint int constraint) { try { try { return mService.getBrightnessConstraint(constraint); return mService.getBrightnessConstraint(displayId, constraint); } catch (RemoteException e) { } catch (RemoteException e) { throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer(); } } Loading core/java/android/view/DisplayInfo.java +12 −0 Original line number Original line Diff line number Diff line Loading @@ -360,6 +360,12 @@ public final class DisplayInfo implements Parcelable { */ */ public float brightnessDefault; public float brightnessDefault; /** * The current dim brightness of the display. Value between 0.0 and 1.0, * derived from the configuration of the display device of this logical display. */ public float brightnessDim; /** /** * The {@link RoundedCorners} if present, otherwise {@code null}. * The {@link RoundedCorners} if present, otherwise {@code null}. */ */ Loading Loading @@ -479,6 +485,7 @@ public final class DisplayInfo implements Parcelable { && brightnessMinimum == other.brightnessMinimum && brightnessMinimum == other.brightnessMinimum && brightnessMaximum == other.brightnessMaximum && brightnessMaximum == other.brightnessMaximum && brightnessDefault == other.brightnessDefault && brightnessDefault == other.brightnessDefault && brightnessDim == other.brightnessDim && Objects.equals(roundedCorners, other.roundedCorners) && Objects.equals(roundedCorners, other.roundedCorners) && installOrientation == other.installOrientation && installOrientation == other.installOrientation && Objects.equals(displayShape, other.displayShape) && Objects.equals(displayShape, other.displayShape) Loading Loading @@ -546,6 +553,7 @@ public final class DisplayInfo implements Parcelable { brightnessMinimum = other.brightnessMinimum; brightnessMinimum = other.brightnessMinimum; brightnessMaximum = other.brightnessMaximum; brightnessMaximum = other.brightnessMaximum; brightnessDefault = other.brightnessDefault; brightnessDefault = other.brightnessDefault; brightnessDim = other.brightnessDim; roundedCorners = other.roundedCorners; roundedCorners = other.roundedCorners; installOrientation = other.installOrientation; installOrientation = other.installOrientation; displayShape = other.displayShape; displayShape = other.displayShape; Loading Loading @@ -620,6 +628,7 @@ public final class DisplayInfo implements Parcelable { brightnessMinimum = source.readFloat(); brightnessMinimum = source.readFloat(); brightnessMaximum = source.readFloat(); brightnessMaximum = source.readFloat(); brightnessDefault = source.readFloat(); brightnessDefault = source.readFloat(); brightnessDim = source.readFloat(); roundedCorners = source.readTypedObject(RoundedCorners.CREATOR); roundedCorners = source.readTypedObject(RoundedCorners.CREATOR); int numUserDisabledFormats = source.readInt(); int numUserDisabledFormats = source.readInt(); userDisabledHdrTypes = new int[numUserDisabledFormats]; userDisabledHdrTypes = new int[numUserDisabledFormats]; Loading Loading @@ -696,6 +705,7 @@ public final class DisplayInfo implements Parcelable { dest.writeFloat(brightnessMinimum); dest.writeFloat(brightnessMinimum); dest.writeFloat(brightnessMaximum); dest.writeFloat(brightnessMaximum); dest.writeFloat(brightnessDefault); dest.writeFloat(brightnessDefault); dest.writeFloat(brightnessDim); dest.writeTypedObject(roundedCorners, flags); dest.writeTypedObject(roundedCorners, flags); dest.writeInt(userDisabledHdrTypes.length); dest.writeInt(userDisabledHdrTypes.length); for (int i = 0; i < userDisabledHdrTypes.length; i++) { for (int i = 0; i < userDisabledHdrTypes.length; i++) { Loading Loading @@ -994,6 +1004,8 @@ public final class DisplayInfo implements Parcelable { sb.append(brightnessMaximum); sb.append(brightnessMaximum); sb.append(", brightnessDefault "); sb.append(", brightnessDefault "); sb.append(brightnessDefault); sb.append(brightnessDefault); sb.append(", brightnessDim "); sb.append(brightnessDim); sb.append(", installOrientation "); sb.append(", installOrientation "); sb.append(Surface.rotationToString(installOrientation)); sb.append(Surface.rotationToString(installOrientation)); sb.append(", layoutLimitedRefreshRate "); sb.append(", layoutLimitedRefreshRate "); Loading Loading
core/api/current.txt +2 −0 Original line number Original line Diff line number Diff line Loading @@ -20809,6 +20809,7 @@ package android.hardware.display { method public int describeContents(); method public int describeContents(); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @FloatRange(from=0.0f, to=1.0f) public float getDefaultBrightness(); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @FloatRange(from=0.0f, to=1.0f) public float getDefaultBrightness(); method public int getDensityDpi(); method public int getDensityDpi(); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @FloatRange(from=0.0f, to=1.0f) public float getDimBrightness(); method @NonNull public java.util.Set<java.lang.String> getDisplayCategories(); method @NonNull public java.util.Set<java.lang.String> getDisplayCategories(); method public int getFlags(); method public int getFlags(); method public int getHeight(); method public int getHeight(); Loading @@ -20830,6 +20831,7 @@ package android.hardware.display { method @NonNull public android.hardware.display.VirtualDisplayConfig build(); method @NonNull public android.hardware.display.VirtualDisplayConfig build(); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setBrightnessListener(@NonNull java.util.concurrent.Executor, @NonNull android.hardware.display.VirtualDisplayConfig.BrightnessListener); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setBrightnessListener(@NonNull java.util.concurrent.Executor, @NonNull android.hardware.display.VirtualDisplayConfig.BrightnessListener); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDefaultBrightness(@FloatRange(from=0.0f, to=1.0f) float); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDefaultBrightness(@FloatRange(from=0.0f, to=1.0f) float); method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDimBrightness(@FloatRange(from=0.0f, to=1.0f) float); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDisplayCategories(@NonNull java.util.Set<java.lang.String>); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDisplayCategories(@NonNull java.util.Set<java.lang.String>); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setFlags(int); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setFlags(int); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setRequestedRefreshRate(@FloatRange(from=0.0f) float); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setRequestedRefreshRate(@FloatRange(from=0.0f) float);
core/java/android/hardware/display/VirtualDisplayConfig.java +65 −5 Original line number Original line Diff line number Diff line Loading @@ -66,6 +66,7 @@ public final class VirtualDisplayConfig implements Parcelable { private final DisplayCutout mDisplayCutout; private final DisplayCutout mDisplayCutout; private final boolean mIgnoreActivitySizeRestrictions; private final boolean mIgnoreActivitySizeRestrictions; private final float mDefaultBrightness; private final float mDefaultBrightness; private final float mDimBrightness; private final IBrightnessListener mBrightnessListener; private final IBrightnessListener mBrightnessListener; private VirtualDisplayConfig( private VirtualDisplayConfig( Loading @@ -84,6 +85,7 @@ public final class VirtualDisplayConfig implements Parcelable { @Nullable DisplayCutout displayCutout, @Nullable DisplayCutout displayCutout, boolean ignoreActivitySizeRestrictions, boolean ignoreActivitySizeRestrictions, @FloatRange(from = 0.0f, to = 1.0f) float defaultBrightness, @FloatRange(from = 0.0f, to = 1.0f) float defaultBrightness, @FloatRange(from = 0.0f, to = 1.0f) float dimBrightness, IBrightnessListener brightnessListener) { IBrightnessListener brightnessListener) { mName = name; mName = name; mWidth = width; mWidth = width; Loading @@ -100,6 +102,7 @@ public final class VirtualDisplayConfig implements Parcelable { mDisplayCutout = displayCutout; mDisplayCutout = displayCutout; mIgnoreActivitySizeRestrictions = ignoreActivitySizeRestrictions; mIgnoreActivitySizeRestrictions = ignoreActivitySizeRestrictions; mDefaultBrightness = defaultBrightness; mDefaultBrightness = defaultBrightness; mDimBrightness = dimBrightness; mBrightnessListener = brightnessListener; mBrightnessListener = brightnessListener; } } Loading Loading @@ -179,6 +182,19 @@ public final class VirtualDisplayConfig implements Parcelable { return mDefaultBrightness; return mDefaultBrightness; } } /** * Returns the dim brightness of the display. * * <p>Value of {@code 0.0} indicates the minimum supported brightness and value of {@code 1.0} * indicates the maximum supported brightness.</p> * * @see Builder#setDimBrightness(float) */ @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_DEVICE_AWARE_DISPLAY_POWER) public @FloatRange(from = 0.0f, to = 1.0f) float getDimBrightness() { return mDimBrightness; } /** /** * Returns the listener to get notified about changes in the display brightness. * Returns the listener to get notified about changes in the display brightness. * @hide * @hide Loading Loading @@ -278,6 +294,7 @@ public final class VirtualDisplayConfig implements Parcelable { DisplayCutout.ParcelableWrapper.writeCutoutToParcel(mDisplayCutout, dest, flags); DisplayCutout.ParcelableWrapper.writeCutoutToParcel(mDisplayCutout, dest, flags); dest.writeBoolean(mIgnoreActivitySizeRestrictions); dest.writeBoolean(mIgnoreActivitySizeRestrictions); dest.writeFloat(mDefaultBrightness); dest.writeFloat(mDefaultBrightness); dest.writeFloat(mDimBrightness); dest.writeStrongBinder(mBrightnessListener != null ? mBrightnessListener.asBinder() : null); dest.writeStrongBinder(mBrightnessListener != null ? mBrightnessListener.asBinder() : null); } } Loading Loading @@ -308,8 +325,8 @@ public final class VirtualDisplayConfig implements Parcelable { && mIgnoreActivitySizeRestrictions == that.mIgnoreActivitySizeRestrictions && mIgnoreActivitySizeRestrictions == that.mIgnoreActivitySizeRestrictions && Objects.equals(mDisplayCutout, that.mDisplayCutout) && Objects.equals(mDisplayCutout, that.mDisplayCutout) && mDefaultBrightness == that.mDefaultBrightness && mDefaultBrightness == that.mDefaultBrightness && mDimBrightness == that.mDimBrightness && Objects.equals(mBrightnessListener, that.mBrightnessListener); && Objects.equals(mBrightnessListener, that.mBrightnessListener); } } @Override @Override Loading @@ -318,7 +335,8 @@ public final class VirtualDisplayConfig implements Parcelable { mName, mWidth, mHeight, mDensityDpi, mFlags, mSurface, mUniqueId, mName, mWidth, mHeight, mDensityDpi, mFlags, mSurface, mUniqueId, mDisplayIdToMirror, mWindowManagerMirroringEnabled, mDisplayCategories, mDisplayIdToMirror, mWindowManagerMirroringEnabled, mDisplayCategories, mRequestedRefreshRate, mIsHomeSupported, mDisplayCutout, mRequestedRefreshRate, mIsHomeSupported, mDisplayCutout, mIgnoreActivitySizeRestrictions, mDefaultBrightness, mBrightnessListener); mIgnoreActivitySizeRestrictions, mDefaultBrightness, mDimBrightness, mBrightnessListener); return hashCode; return hashCode; } } Loading @@ -341,6 +359,7 @@ public final class VirtualDisplayConfig implements Parcelable { + " mDisplayCutout=" + mDisplayCutout + " mDisplayCutout=" + mDisplayCutout + " mIgnoreActivitySizeRestrictions=" + mIgnoreActivitySizeRestrictions + " mIgnoreActivitySizeRestrictions=" + mIgnoreActivitySizeRestrictions + " mDefaultBrightness=" + mDefaultBrightness + " mDefaultBrightness=" + mDefaultBrightness + " mDimBrightness=" + mDimBrightness + ")"; + ")"; } } Loading @@ -360,8 +379,8 @@ public final class VirtualDisplayConfig implements Parcelable { mDisplayCutout = DisplayCutout.ParcelableWrapper.readCutoutFromParcel(in); mDisplayCutout = DisplayCutout.ParcelableWrapper.readCutoutFromParcel(in); mIgnoreActivitySizeRestrictions = in.readBoolean(); mIgnoreActivitySizeRestrictions = in.readBoolean(); mDefaultBrightness = in.readFloat(); mDefaultBrightness = in.readFloat(); mDimBrightness = in.readFloat(); mBrightnessListener = IBrightnessListener.Stub.asInterface(in.readStrongBinder()); mBrightnessListener = IBrightnessListener.Stub.asInterface(in.readStrongBinder()); } } /** /** Loading Loading @@ -432,6 +451,7 @@ public final class VirtualDisplayConfig implements Parcelable { private DisplayCutout mDisplayCutout = null; private DisplayCutout mDisplayCutout = null; private boolean mIgnoreActivitySizeRestrictions = false; private boolean mIgnoreActivitySizeRestrictions = false; private float mDefaultBrightness = 0.0f; private float mDefaultBrightness = 0.0f; private float mDimBrightness = PowerManager.BRIGHTNESS_INVALID; private IBrightnessListener mBrightnessListener = null; private IBrightnessListener mBrightnessListener = null; /** /** Loading Loading @@ -635,14 +655,14 @@ public final class VirtualDisplayConfig implements Parcelable { * * * <p>If unset, defaults to {@code 0.0}</p> * <p>If unset, defaults to {@code 0.0}</p> * * * @throws IllegalArgumentException if the brightness is outside the valid range [0.0, 1.0] * @see android.view.View#setKeepScreenOn(boolean) * @see android.view.View#setKeepScreenOn(boolean) * @see #setBrightnessListener(Executor, BrightnessListener) * @see #setBrightnessListener(Executor, BrightnessListener) */ */ @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_DEVICE_AWARE_DISPLAY_POWER) @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_DEVICE_AWARE_DISPLAY_POWER) @NonNull @NonNull public Builder setDefaultBrightness(@FloatRange(from = 0.0f, to = 1.0f) float brightness) { public Builder setDefaultBrightness(@FloatRange(from = 0.0f, to = 1.0f) float brightness) { if (brightness < PowerManager.BRIGHTNESS_MIN if (!isValidBrightness(brightness)) { || brightness > PowerManager.BRIGHTNESS_MAX) { throw new IllegalArgumentException( throw new IllegalArgumentException( "Virtual display default brightness must be in range [0.0, 1.0]"); "Virtual display default brightness must be in range [0.0, 1.0]"); } } Loading @@ -650,6 +670,33 @@ public final class VirtualDisplayConfig implements Parcelable { return this; return this; } } /** * Sets the dim brightness of the display. * * <p>The system will use this brightness value whenever the display should be dim, i.e. * it is powered on and dimmed due to user activity or app activity.</p> * * <p>Value of {@code 0.0} indicates the minimum supported brightness and value of * {@code 1.0} indicates the maximum supported brightness.</p> * * <p>If set, the default brightness must also be set to a value greater or equal to the * dim brightness. If unset, defaults to the system default.</p> * * @throws IllegalArgumentException if the brightness is outside the valid range [0.0, 1.0] * @see Builder#setDefaultBrightness(float) * @see #setBrightnessListener(Executor, BrightnessListener) */ @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_DEVICE_AWARE_DISPLAY_POWER) @NonNull public Builder setDimBrightness(@FloatRange(from = 0.0f, to = 1.0f) float brightness) { if (!isValidBrightness(brightness)) { throw new IllegalArgumentException( "Virtual display dim brightness must be in range [0.0, 1.0]"); } mDimBrightness = brightness; return this; } /** /** * Sets the listener to get notified about changes in the display brightness. * Sets the listener to get notified about changes in the display brightness. * * Loading @@ -666,11 +713,23 @@ public final class VirtualDisplayConfig implements Parcelable { return this; return this; } } private boolean isValidBrightness(float brightness) { return !Float.isNaN(brightness) && PowerManager.BRIGHTNESS_MIN <= brightness && brightness <= PowerManager.BRIGHTNESS_MAX; } /** /** * Builds the {@link VirtualDisplayConfig} instance. * Builds the {@link VirtualDisplayConfig} instance. * * @throws IllegalArgumentException if the dim brightness is set to a value greater than * the default brightness. */ */ @NonNull @NonNull public VirtualDisplayConfig build() { public VirtualDisplayConfig build() { if (isValidBrightness(mDimBrightness) && mDimBrightness > mDefaultBrightness) { throw new IllegalArgumentException( "The dim brightness must not be greater than the default brightness"); } return new VirtualDisplayConfig( return new VirtualDisplayConfig( mName, mName, mWidth, mWidth, Loading @@ -687,6 +746,7 @@ public final class VirtualDisplayConfig implements Parcelable { mDisplayCutout, mDisplayCutout, mIgnoreActivitySizeRestrictions, mIgnoreActivitySizeRestrictions, mDefaultBrightness, mDefaultBrightness, mDimBrightness, mBrightnessListener); mBrightnessListener); } } } } Loading
core/java/android/os/IPowerManager.aidl +1 −1 Original line number Original line Diff line number Diff line Loading @@ -55,7 +55,7 @@ interface IPowerManager void goToSleepWithDisplayId(int displayId, long time, int reason, int flags); void goToSleepWithDisplayId(int displayId, long time, int reason, int flags); @UnsupportedAppUsage(maxTargetSdk = 28) @UnsupportedAppUsage(maxTargetSdk = 28) void nap(long time); void nap(long time); float getBrightnessConstraint(int constraint); float getBrightnessConstraint(int displayId, int constraint); @UnsupportedAppUsage @UnsupportedAppUsage boolean isInteractive(); boolean isInteractive(); boolean isDisplayInteractive(int displayId); boolean isDisplayInteractive(int displayId); Loading
core/java/android/os/PowerManager.java +10 −2 Original line number Original line Diff line number Diff line Loading @@ -1266,9 +1266,17 @@ public final class PowerManager { * @hide * @hide */ */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public float getBrightnessConstraint(int constraint) { public float getBrightnessConstraint(@BrightnessConstraint int constraint) { return getBrightnessConstraint(Display.DEFAULT_DISPLAY, constraint); } /** * Gets a float screen brightness setting for a specific display. * @hide */ public float getBrightnessConstraint(int displayId, @BrightnessConstraint int constraint) { try { try { return mService.getBrightnessConstraint(constraint); return mService.getBrightnessConstraint(displayId, constraint); } catch (RemoteException e) { } catch (RemoteException e) { throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer(); } } Loading
core/java/android/view/DisplayInfo.java +12 −0 Original line number Original line Diff line number Diff line Loading @@ -360,6 +360,12 @@ public final class DisplayInfo implements Parcelable { */ */ public float brightnessDefault; public float brightnessDefault; /** * The current dim brightness of the display. Value between 0.0 and 1.0, * derived from the configuration of the display device of this logical display. */ public float brightnessDim; /** /** * The {@link RoundedCorners} if present, otherwise {@code null}. * The {@link RoundedCorners} if present, otherwise {@code null}. */ */ Loading Loading @@ -479,6 +485,7 @@ public final class DisplayInfo implements Parcelable { && brightnessMinimum == other.brightnessMinimum && brightnessMinimum == other.brightnessMinimum && brightnessMaximum == other.brightnessMaximum && brightnessMaximum == other.brightnessMaximum && brightnessDefault == other.brightnessDefault && brightnessDefault == other.brightnessDefault && brightnessDim == other.brightnessDim && Objects.equals(roundedCorners, other.roundedCorners) && Objects.equals(roundedCorners, other.roundedCorners) && installOrientation == other.installOrientation && installOrientation == other.installOrientation && Objects.equals(displayShape, other.displayShape) && Objects.equals(displayShape, other.displayShape) Loading Loading @@ -546,6 +553,7 @@ public final class DisplayInfo implements Parcelable { brightnessMinimum = other.brightnessMinimum; brightnessMinimum = other.brightnessMinimum; brightnessMaximum = other.brightnessMaximum; brightnessMaximum = other.brightnessMaximum; brightnessDefault = other.brightnessDefault; brightnessDefault = other.brightnessDefault; brightnessDim = other.brightnessDim; roundedCorners = other.roundedCorners; roundedCorners = other.roundedCorners; installOrientation = other.installOrientation; installOrientation = other.installOrientation; displayShape = other.displayShape; displayShape = other.displayShape; Loading Loading @@ -620,6 +628,7 @@ public final class DisplayInfo implements Parcelable { brightnessMinimum = source.readFloat(); brightnessMinimum = source.readFloat(); brightnessMaximum = source.readFloat(); brightnessMaximum = source.readFloat(); brightnessDefault = source.readFloat(); brightnessDefault = source.readFloat(); brightnessDim = source.readFloat(); roundedCorners = source.readTypedObject(RoundedCorners.CREATOR); roundedCorners = source.readTypedObject(RoundedCorners.CREATOR); int numUserDisabledFormats = source.readInt(); int numUserDisabledFormats = source.readInt(); userDisabledHdrTypes = new int[numUserDisabledFormats]; userDisabledHdrTypes = new int[numUserDisabledFormats]; Loading Loading @@ -696,6 +705,7 @@ public final class DisplayInfo implements Parcelable { dest.writeFloat(brightnessMinimum); dest.writeFloat(brightnessMinimum); dest.writeFloat(brightnessMaximum); dest.writeFloat(brightnessMaximum); dest.writeFloat(brightnessDefault); dest.writeFloat(brightnessDefault); dest.writeFloat(brightnessDim); dest.writeTypedObject(roundedCorners, flags); dest.writeTypedObject(roundedCorners, flags); dest.writeInt(userDisabledHdrTypes.length); dest.writeInt(userDisabledHdrTypes.length); for (int i = 0; i < userDisabledHdrTypes.length; i++) { for (int i = 0; i < userDisabledHdrTypes.length; i++) { Loading Loading @@ -994,6 +1004,8 @@ public final class DisplayInfo implements Parcelable { sb.append(brightnessMaximum); sb.append(brightnessMaximum); sb.append(", brightnessDefault "); sb.append(", brightnessDefault "); sb.append(brightnessDefault); sb.append(brightnessDefault); sb.append(", brightnessDim "); sb.append(brightnessDim); sb.append(", installOrientation "); sb.append(", installOrientation "); sb.append(Surface.rotationToString(installOrientation)); sb.append(Surface.rotationToString(installOrientation)); sb.append(", layoutLimitedRefreshRate "); sb.append(", layoutLimitedRefreshRate "); Loading