Loading core/java/android/service/notification/ZenDeviceEffects.java +75 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.service.notification; import android.annotation.FloatRange; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; Loading Loading @@ -57,6 +58,7 @@ public final class ZenDeviceEffects implements Parcelable { FIELD_MINIMIZE_RADIO_USAGE, FIELD_MAXIMIZE_DOZE, FIELD_NIGHT_LIGHT, FIELD_BRIGHTNESS_CAP, FIELD_EXTRA_EFFECTS }) @Retention(RetentionPolicy.SOURCE) Loading Loading @@ -110,7 +112,12 @@ public final class ZenDeviceEffects implements Parcelable { /** @hide */ public static final int FIELD_NIGHT_LIGHT = 1 << 11; /** @hide */ public static final int FIELD_BRIGHTNESS_CAP = 1 << 12; private static final int MAX_EFFECTS_LENGTH = 2_000; // characters private static final float BRIGHTNESS_CAP_MIN = 0f; private static final float BRIGHTNESS_CAP_MAX = 100f; private final boolean mGrayscale; private final boolean mSuppressAmbientDisplay; Loading @@ -124,6 +131,11 @@ public final class ZenDeviceEffects implements Parcelable { private final boolean mMinimizeRadioUsage; private final boolean mMaximizeDoze; private final boolean mNightLight; @Nullable @FloatRange(from = BRIGHTNESS_CAP_MIN, to = BRIGHTNESS_CAP_MAX) private final Float mBrightnessCap; private final Set<String> mExtraEffects; private ZenDeviceEffects( Loading @@ -138,6 +150,7 @@ public final class ZenDeviceEffects implements Parcelable { boolean minimizeRadioUsage, boolean maximizeDoze, boolean nightLight, @Nullable Float brightnessCap, Set<String> extraEffects) { mGrayscale = grayscale; mSuppressAmbientDisplay = suppressAmbientDisplay; Loading @@ -150,6 +163,7 @@ public final class ZenDeviceEffects implements Parcelable { mMinimizeRadioUsage = minimizeRadioUsage; mMaximizeDoze = maximizeDoze; mNightLight = nightLight; mBrightnessCap = Flags.applyBrightnessClampingForModes() ? brightnessCap : null; mExtraEffects = Collections.unmodifiableSet(extraEffects); } Loading @@ -164,6 +178,10 @@ public final class ZenDeviceEffects implements Parcelable { "Total size of extra effects must be at most " + MAX_EFFECTS_LENGTH + " characters"); } if (mBrightnessCap != null && (mBrightnessCap < BRIGHTNESS_CAP_MIN || mBrightnessCap > BRIGHTNESS_CAP_MAX)) { throw new IllegalArgumentException("Brightness cap must be between 0f and 100f"); } } @Override Loading @@ -182,6 +200,7 @@ public final class ZenDeviceEffects implements Parcelable { && this.mMinimizeRadioUsage == that.mMinimizeRadioUsage && this.mMaximizeDoze == that.mMaximizeDoze && this.mNightLight == that.mNightLight && Objects.equals(this.mBrightnessCap, that.mBrightnessCap) && Objects.equals(this.mExtraEffects, that.mExtraEffects); } Loading @@ -199,6 +218,7 @@ public final class ZenDeviceEffects implements Parcelable { mMinimizeRadioUsage, mMaximizeDoze, mNightLight, mBrightnessCap, mExtraEffects); } Loading @@ -216,6 +236,7 @@ public final class ZenDeviceEffects implements Parcelable { if (mMinimizeRadioUsage) effects.add("minimizeRadioUsage"); if (mMaximizeDoze) effects.add("maximizeDoze"); if (mNightLight) effects.add("nightLight"); if (mBrightnessCap != null) effects.add("brightnessCap=" + mBrightnessCap + "%"); if (mExtraEffects.size() > 0) { effects.add("extraEffects=[" + String.join(",", mExtraEffects) + "]"); } Loading Loading @@ -258,6 +279,9 @@ public final class ZenDeviceEffects implements Parcelable { if (((bitmask) & FIELD_NIGHT_LIGHT) != 0) { modified.add("FIELD_NIGHT_LIGHT"); } if (((bitmask) & FIELD_BRIGHTNESS_CAP) != 0) { modified.add("FIELD_BRIGHTNESS_CAP"); } if ((bitmask & FIELD_EXTRA_EFFECTS) != 0) { modified.add("FIELD_EXTRA_EFFECTS"); } Loading Loading @@ -351,6 +375,18 @@ public final class ZenDeviceEffects implements Parcelable { return mNightLight; } /** * Gets the brightness cap that should be applied while the rule is active. This is reflected as * a percentage of the maximum brightness supported by the display. * * @hide */ @Nullable @FloatRange(from = BRIGHTNESS_CAP_MIN, to = BRIGHTNESS_CAP_MAX) public Float getBrightnessPercentageCap() { return mBrightnessCap; } /** * (Immutable) set of extra effects to be applied while the rule is active. Extra effects are * not used in AOSP, but OEMs may add support for them by providing a custom Loading Loading @@ -379,6 +415,7 @@ public final class ZenDeviceEffects implements Parcelable { || mMinimizeRadioUsage || mMaximizeDoze || mNightLight || mBrightnessCap != null || mExtraEffects.size() > 0; } Loading @@ -400,6 +437,7 @@ public final class ZenDeviceEffects implements Parcelable { in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean() ? in.readFloat() : null, Set.of(in.readArray(String.class.getClassLoader(), String.class))); } Loading Loading @@ -427,6 +465,12 @@ public final class ZenDeviceEffects implements Parcelable { dest.writeBoolean(mMinimizeRadioUsage); dest.writeBoolean(mMaximizeDoze); dest.writeBoolean(mNightLight); if (mBrightnessCap != null) { dest.writeBoolean(/* val= */ true); dest.writeFloat(mBrightnessCap); } else { dest.writeBoolean(/* val= */ false); } dest.writeArray(mExtraEffects.toArray(new String[0])); } Loading @@ -444,6 +488,7 @@ public final class ZenDeviceEffects implements Parcelable { private boolean mMinimizeRadioUsage; private boolean mMaximizeDoze; private boolean mNightLight; @Nullable private Float mBrightnessCap = null; private final HashSet<String> mExtraEffects = new HashSet<>(); /** Loading @@ -468,6 +513,7 @@ public final class ZenDeviceEffects implements Parcelable { mMinimizeRadioUsage = zenDeviceEffects.shouldMinimizeRadioUsage(); mMaximizeDoze = zenDeviceEffects.shouldMaximizeDoze(); mNightLight = zenDeviceEffects.shouldUseNightLight(); mBrightnessCap = zenDeviceEffects.getBrightnessPercentageCap(); mExtraEffects.addAll(zenDeviceEffects.getExtraEffects()); } Loading Loading @@ -581,6 +627,21 @@ public final class ZenDeviceEffects implements Parcelable { return this; } /** * Sets whether the maximum brightness of the display should be capped while the rule is * active. This is reflected as a percentage of the maximum brightness supported by the * display. * * @hide */ @NonNull public Builder setBrightnessPercentageCap( @Nullable @FloatRange(from = BRIGHTNESS_CAP_MIN, to = BRIGHTNESS_CAP_MAX) Float brightnessCap) { mBrightnessCap = Flags.applyBrightnessClampingForModes() ? brightnessCap : null; return this; } /** * Sets the extra effects to be applied while the rule is active. Extra effects are not * used in AOSP, but OEMs may add support for them by providing a custom Loading Loading @@ -630,8 +691,12 @@ public final class ZenDeviceEffects implements Parcelable { } /** * Applies the effects that are {@code true} on the supplied {@link ZenDeviceEffects} to * this builder (essentially logically-ORing the effect set). * Applies the supplied {@link ZenDeviceEffects} to this builder which is consolidated on a * case by case basis choosing the most restrictive option. For effects tracked with a * boolean value, currently the structure dictates {@code true} to be most restrictive, * essentially logically-ORing the effect set. For {@link #getBrightnessPercentageCap()}, * the lower range is chosen. * * @hide */ @NonNull Loading @@ -648,6 +713,13 @@ public final class ZenDeviceEffects implements Parcelable { if (effects.shouldMinimizeRadioUsage()) setShouldMinimizeRadioUsage(true); if (effects.shouldMaximizeDoze()) setShouldMaximizeDoze(true); if (effects.shouldUseNightLight()) setShouldUseNightLight(true); if (mBrightnessCap == null) { setBrightnessPercentageCap(effects.getBrightnessPercentageCap()); } else if (effects.getBrightnessPercentageCap() != null) { // BrightnessCap for this and other ZenDeviceEffects is non null. setBrightnessPercentageCap( Math.min(effects.getBrightnessPercentageCap(), mBrightnessCap)); } addExtraEffects(effects.getExtraEffects()); return this; } Loading @@ -667,6 +739,7 @@ public final class ZenDeviceEffects implements Parcelable { mMinimizeRadioUsage, mMaximizeDoze, mNightLight, mBrightnessCap, mExtraEffects); } } Loading core/java/android/service/notification/ZenModeConfig.java +27 −4 Original line number Diff line number Diff line Loading @@ -325,6 +325,7 @@ public class ZenModeConfig implements Parcelable { private static final String DEVICE_EFFECT_MINIMIZE_RADIO_USAGE = "zdeMinimizeRadioUsage"; private static final String DEVICE_EFFECT_MAXIMIZE_DOZE = "zdeMaximizeDoze"; private static final String DEVICE_EFFECT_USE_NIGHT_LIGHT = "zdeUseNightLight"; private static final String DEVICE_EFFECT_CAP_BRIGHTNESS = "zdeCapBrightness"; private static final String DEVICE_EFFECT_EXTRAS = "zdeExtraEffects"; private static final String DEVICE_EFFECT_USER_MODIFIED_FIELDS = "zdeUserModifiedFields"; Loading Loading @@ -1214,7 +1215,7 @@ public class ZenModeConfig implements Parcelable { @Nullable private static ZenDeviceEffects readZenDeviceEffectsXml(TypedXmlPullParser parser) { ZenDeviceEffects deviceEffects = ZenDeviceEffects.Builder builder = new ZenDeviceEffects.Builder() .setShouldDisplayGrayscale( safeBoolean(parser, DEVICE_EFFECT_DISPLAY_GRAYSCALE, false)) Loading @@ -1238,9 +1239,11 @@ public class ZenModeConfig implements Parcelable { safeBoolean(parser, DEVICE_EFFECT_MAXIMIZE_DOZE, false)) .setShouldUseNightLight( safeBoolean(parser, DEVICE_EFFECT_USE_NIGHT_LIGHT, false)) .setExtraEffects(safeStringSet(parser, DEVICE_EFFECT_EXTRAS)) .build(); .setExtraEffects(safeStringSet(parser, DEVICE_EFFECT_EXTRAS)); if (android.service.notification.Flags.applyBrightnessClampingForModes()) { builder.setBrightnessPercentageCap(unsafeFloat(parser, DEVICE_EFFECT_CAP_BRIGHTNESS)); } ZenDeviceEffects deviceEffects = builder.build(); return deviceEffects.hasEffects() ? deviceEffects : null; } Loading @@ -1263,6 +1266,10 @@ public class ZenModeConfig implements Parcelable { deviceEffects.shouldMinimizeRadioUsage()); writeBooleanIfTrue(out, DEVICE_EFFECT_MAXIMIZE_DOZE, deviceEffects.shouldMaximizeDoze()); writeBooleanIfTrue(out, DEVICE_EFFECT_USE_NIGHT_LIGHT, deviceEffects.shouldUseNightLight()); if (android.service.notification.Flags.applyBrightnessClampingForModes()) { writeFloatIfNotNull( out, DEVICE_EFFECT_CAP_BRIGHTNESS, deviceEffects.getBrightnessPercentageCap()); } writeStringSet(out, DEVICE_EFFECT_EXTRAS, deviceEffects.getExtraEffects()); } Loading @@ -1273,6 +1280,13 @@ public class ZenModeConfig implements Parcelable { } } private static void writeFloatIfNotNull( TypedXmlSerializer out, String att, @Nullable Float value) throws IOException { if (value != null) { out.attributeFloat(null, att, value); } } private static void writeStringSet(TypedXmlSerializer out, String att, Set<String> values) throws IOException { if (values.isEmpty()) { Loading Loading @@ -1326,6 +1340,15 @@ public class ZenModeConfig implements Parcelable { return parser.getAttributeInt(null, att, defValue); } @Nullable private static Float unsafeFloat(TypedXmlPullParser parser, String att) { try { return parser.getAttributeFloat(null, att); } catch (Exception e) { return null; } } private static ComponentName safeComponentName(TypedXmlPullParser parser, String att) { final String val = parser.getAttributeValue(null, att); if (TextUtils.isEmpty(val)) return null; Loading core/java/android/service/notification/ZenModeDiff.java +10 −0 Original line number Diff line number Diff line Loading @@ -611,6 +611,7 @@ public class ZenModeDiff { public static final String FIELD_MINIMIZE_RADIO_USAGE = "mMinimizeRadioUsage"; public static final String FIELD_MAXIMIZE_DOZE = "mMaximizeDoze"; public static final String FIELD_NIGHT_LIGHT = "mNightLight"; public static final String FIELD_BRIGHTNESS_CAP = "mBrightnessCap"; public static final String FIELD_EXTRA_EFFECTS = "mExtraEffects"; // NOTE: new field strings must match the variable names in ZenDeviceEffects Loading Loading @@ -683,6 +684,15 @@ public class ZenModeDiff { FIELD_NIGHT_LIGHT, new FieldDiff<>(from.shouldUseNightLight(), to.shouldUseNightLight())); } if (Flags.applyBrightnessClampingForModes() && !Objects.equals( from.getBrightnessPercentageCap(), to.getBrightnessPercentageCap())) { addField( FIELD_BRIGHTNESS_CAP, new FieldDiff<>( from.getBrightnessPercentageCap(), to.getBrightnessPercentageCap())); } if (!Objects.equals(from.getExtraEffects(), to.getExtraEffects())) { addField(FIELD_EXTRA_EFFECTS, new FieldDiff<>(from.getExtraEffects(), to.getExtraEffects())); Loading core/java/android/service/notification/flags.aconfig +6 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,12 @@ flag { bug: "409474564" } flag { name: "apply_brightness_clamping_for_modes" namespace: "wear_frameworks" description: "Whether to apply brightness clamping for modes" bug: "387528442" } Loading services/core/java/com/android/server/notification/ZenModeHelper.java +7 −0 Original line number Diff line number Diff line Loading @@ -1425,6 +1425,7 @@ public class ZenModeHelper { .setShouldMinimizeRadioUsage(oldEffects.shouldMinimizeRadioUsage()) .setShouldMaximizeDoze(oldEffects.shouldMaximizeDoze()) .setShouldUseNightLight(oldEffects.shouldUseNightLight()) .setBrightnessPercentageCap(oldEffects.getBrightnessPercentageCap()) .setExtraEffects(oldEffects.getExtraEffects()) .build(); } Loading Loading @@ -1468,6 +1469,12 @@ public class ZenModeHelper { if (oldEffects.shouldUseNightLight() != newEffects.shouldUseNightLight()) { userModifiedFields |= ZenDeviceEffects.FIELD_NIGHT_LIGHT; } if (android.service.notification.Flags.applyBrightnessClampingForModes() && !Objects.equals( oldEffects.getBrightnessPercentageCap(), newEffects.getBrightnessPercentageCap())) { userModifiedFields |= ZenDeviceEffects.FIELD_BRIGHTNESS_CAP; } if (!Objects.equals(oldEffects.getExtraEffects(), newEffects.getExtraEffects())) { userModifiedFields |= ZenDeviceEffects.FIELD_EXTRA_EFFECTS; } Loading Loading
core/java/android/service/notification/ZenDeviceEffects.java +75 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.service.notification; import android.annotation.FloatRange; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; Loading Loading @@ -57,6 +58,7 @@ public final class ZenDeviceEffects implements Parcelable { FIELD_MINIMIZE_RADIO_USAGE, FIELD_MAXIMIZE_DOZE, FIELD_NIGHT_LIGHT, FIELD_BRIGHTNESS_CAP, FIELD_EXTRA_EFFECTS }) @Retention(RetentionPolicy.SOURCE) Loading Loading @@ -110,7 +112,12 @@ public final class ZenDeviceEffects implements Parcelable { /** @hide */ public static final int FIELD_NIGHT_LIGHT = 1 << 11; /** @hide */ public static final int FIELD_BRIGHTNESS_CAP = 1 << 12; private static final int MAX_EFFECTS_LENGTH = 2_000; // characters private static final float BRIGHTNESS_CAP_MIN = 0f; private static final float BRIGHTNESS_CAP_MAX = 100f; private final boolean mGrayscale; private final boolean mSuppressAmbientDisplay; Loading @@ -124,6 +131,11 @@ public final class ZenDeviceEffects implements Parcelable { private final boolean mMinimizeRadioUsage; private final boolean mMaximizeDoze; private final boolean mNightLight; @Nullable @FloatRange(from = BRIGHTNESS_CAP_MIN, to = BRIGHTNESS_CAP_MAX) private final Float mBrightnessCap; private final Set<String> mExtraEffects; private ZenDeviceEffects( Loading @@ -138,6 +150,7 @@ public final class ZenDeviceEffects implements Parcelable { boolean minimizeRadioUsage, boolean maximizeDoze, boolean nightLight, @Nullable Float brightnessCap, Set<String> extraEffects) { mGrayscale = grayscale; mSuppressAmbientDisplay = suppressAmbientDisplay; Loading @@ -150,6 +163,7 @@ public final class ZenDeviceEffects implements Parcelable { mMinimizeRadioUsage = minimizeRadioUsage; mMaximizeDoze = maximizeDoze; mNightLight = nightLight; mBrightnessCap = Flags.applyBrightnessClampingForModes() ? brightnessCap : null; mExtraEffects = Collections.unmodifiableSet(extraEffects); } Loading @@ -164,6 +178,10 @@ public final class ZenDeviceEffects implements Parcelable { "Total size of extra effects must be at most " + MAX_EFFECTS_LENGTH + " characters"); } if (mBrightnessCap != null && (mBrightnessCap < BRIGHTNESS_CAP_MIN || mBrightnessCap > BRIGHTNESS_CAP_MAX)) { throw new IllegalArgumentException("Brightness cap must be between 0f and 100f"); } } @Override Loading @@ -182,6 +200,7 @@ public final class ZenDeviceEffects implements Parcelable { && this.mMinimizeRadioUsage == that.mMinimizeRadioUsage && this.mMaximizeDoze == that.mMaximizeDoze && this.mNightLight == that.mNightLight && Objects.equals(this.mBrightnessCap, that.mBrightnessCap) && Objects.equals(this.mExtraEffects, that.mExtraEffects); } Loading @@ -199,6 +218,7 @@ public final class ZenDeviceEffects implements Parcelable { mMinimizeRadioUsage, mMaximizeDoze, mNightLight, mBrightnessCap, mExtraEffects); } Loading @@ -216,6 +236,7 @@ public final class ZenDeviceEffects implements Parcelable { if (mMinimizeRadioUsage) effects.add("minimizeRadioUsage"); if (mMaximizeDoze) effects.add("maximizeDoze"); if (mNightLight) effects.add("nightLight"); if (mBrightnessCap != null) effects.add("brightnessCap=" + mBrightnessCap + "%"); if (mExtraEffects.size() > 0) { effects.add("extraEffects=[" + String.join(",", mExtraEffects) + "]"); } Loading Loading @@ -258,6 +279,9 @@ public final class ZenDeviceEffects implements Parcelable { if (((bitmask) & FIELD_NIGHT_LIGHT) != 0) { modified.add("FIELD_NIGHT_LIGHT"); } if (((bitmask) & FIELD_BRIGHTNESS_CAP) != 0) { modified.add("FIELD_BRIGHTNESS_CAP"); } if ((bitmask & FIELD_EXTRA_EFFECTS) != 0) { modified.add("FIELD_EXTRA_EFFECTS"); } Loading Loading @@ -351,6 +375,18 @@ public final class ZenDeviceEffects implements Parcelable { return mNightLight; } /** * Gets the brightness cap that should be applied while the rule is active. This is reflected as * a percentage of the maximum brightness supported by the display. * * @hide */ @Nullable @FloatRange(from = BRIGHTNESS_CAP_MIN, to = BRIGHTNESS_CAP_MAX) public Float getBrightnessPercentageCap() { return mBrightnessCap; } /** * (Immutable) set of extra effects to be applied while the rule is active. Extra effects are * not used in AOSP, but OEMs may add support for them by providing a custom Loading Loading @@ -379,6 +415,7 @@ public final class ZenDeviceEffects implements Parcelable { || mMinimizeRadioUsage || mMaximizeDoze || mNightLight || mBrightnessCap != null || mExtraEffects.size() > 0; } Loading @@ -400,6 +437,7 @@ public final class ZenDeviceEffects implements Parcelable { in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean() ? in.readFloat() : null, Set.of(in.readArray(String.class.getClassLoader(), String.class))); } Loading Loading @@ -427,6 +465,12 @@ public final class ZenDeviceEffects implements Parcelable { dest.writeBoolean(mMinimizeRadioUsage); dest.writeBoolean(mMaximizeDoze); dest.writeBoolean(mNightLight); if (mBrightnessCap != null) { dest.writeBoolean(/* val= */ true); dest.writeFloat(mBrightnessCap); } else { dest.writeBoolean(/* val= */ false); } dest.writeArray(mExtraEffects.toArray(new String[0])); } Loading @@ -444,6 +488,7 @@ public final class ZenDeviceEffects implements Parcelable { private boolean mMinimizeRadioUsage; private boolean mMaximizeDoze; private boolean mNightLight; @Nullable private Float mBrightnessCap = null; private final HashSet<String> mExtraEffects = new HashSet<>(); /** Loading @@ -468,6 +513,7 @@ public final class ZenDeviceEffects implements Parcelable { mMinimizeRadioUsage = zenDeviceEffects.shouldMinimizeRadioUsage(); mMaximizeDoze = zenDeviceEffects.shouldMaximizeDoze(); mNightLight = zenDeviceEffects.shouldUseNightLight(); mBrightnessCap = zenDeviceEffects.getBrightnessPercentageCap(); mExtraEffects.addAll(zenDeviceEffects.getExtraEffects()); } Loading Loading @@ -581,6 +627,21 @@ public final class ZenDeviceEffects implements Parcelable { return this; } /** * Sets whether the maximum brightness of the display should be capped while the rule is * active. This is reflected as a percentage of the maximum brightness supported by the * display. * * @hide */ @NonNull public Builder setBrightnessPercentageCap( @Nullable @FloatRange(from = BRIGHTNESS_CAP_MIN, to = BRIGHTNESS_CAP_MAX) Float brightnessCap) { mBrightnessCap = Flags.applyBrightnessClampingForModes() ? brightnessCap : null; return this; } /** * Sets the extra effects to be applied while the rule is active. Extra effects are not * used in AOSP, but OEMs may add support for them by providing a custom Loading Loading @@ -630,8 +691,12 @@ public final class ZenDeviceEffects implements Parcelable { } /** * Applies the effects that are {@code true} on the supplied {@link ZenDeviceEffects} to * this builder (essentially logically-ORing the effect set). * Applies the supplied {@link ZenDeviceEffects} to this builder which is consolidated on a * case by case basis choosing the most restrictive option. For effects tracked with a * boolean value, currently the structure dictates {@code true} to be most restrictive, * essentially logically-ORing the effect set. For {@link #getBrightnessPercentageCap()}, * the lower range is chosen. * * @hide */ @NonNull Loading @@ -648,6 +713,13 @@ public final class ZenDeviceEffects implements Parcelable { if (effects.shouldMinimizeRadioUsage()) setShouldMinimizeRadioUsage(true); if (effects.shouldMaximizeDoze()) setShouldMaximizeDoze(true); if (effects.shouldUseNightLight()) setShouldUseNightLight(true); if (mBrightnessCap == null) { setBrightnessPercentageCap(effects.getBrightnessPercentageCap()); } else if (effects.getBrightnessPercentageCap() != null) { // BrightnessCap for this and other ZenDeviceEffects is non null. setBrightnessPercentageCap( Math.min(effects.getBrightnessPercentageCap(), mBrightnessCap)); } addExtraEffects(effects.getExtraEffects()); return this; } Loading @@ -667,6 +739,7 @@ public final class ZenDeviceEffects implements Parcelable { mMinimizeRadioUsage, mMaximizeDoze, mNightLight, mBrightnessCap, mExtraEffects); } } Loading
core/java/android/service/notification/ZenModeConfig.java +27 −4 Original line number Diff line number Diff line Loading @@ -325,6 +325,7 @@ public class ZenModeConfig implements Parcelable { private static final String DEVICE_EFFECT_MINIMIZE_RADIO_USAGE = "zdeMinimizeRadioUsage"; private static final String DEVICE_EFFECT_MAXIMIZE_DOZE = "zdeMaximizeDoze"; private static final String DEVICE_EFFECT_USE_NIGHT_LIGHT = "zdeUseNightLight"; private static final String DEVICE_EFFECT_CAP_BRIGHTNESS = "zdeCapBrightness"; private static final String DEVICE_EFFECT_EXTRAS = "zdeExtraEffects"; private static final String DEVICE_EFFECT_USER_MODIFIED_FIELDS = "zdeUserModifiedFields"; Loading Loading @@ -1214,7 +1215,7 @@ public class ZenModeConfig implements Parcelable { @Nullable private static ZenDeviceEffects readZenDeviceEffectsXml(TypedXmlPullParser parser) { ZenDeviceEffects deviceEffects = ZenDeviceEffects.Builder builder = new ZenDeviceEffects.Builder() .setShouldDisplayGrayscale( safeBoolean(parser, DEVICE_EFFECT_DISPLAY_GRAYSCALE, false)) Loading @@ -1238,9 +1239,11 @@ public class ZenModeConfig implements Parcelable { safeBoolean(parser, DEVICE_EFFECT_MAXIMIZE_DOZE, false)) .setShouldUseNightLight( safeBoolean(parser, DEVICE_EFFECT_USE_NIGHT_LIGHT, false)) .setExtraEffects(safeStringSet(parser, DEVICE_EFFECT_EXTRAS)) .build(); .setExtraEffects(safeStringSet(parser, DEVICE_EFFECT_EXTRAS)); if (android.service.notification.Flags.applyBrightnessClampingForModes()) { builder.setBrightnessPercentageCap(unsafeFloat(parser, DEVICE_EFFECT_CAP_BRIGHTNESS)); } ZenDeviceEffects deviceEffects = builder.build(); return deviceEffects.hasEffects() ? deviceEffects : null; } Loading @@ -1263,6 +1266,10 @@ public class ZenModeConfig implements Parcelable { deviceEffects.shouldMinimizeRadioUsage()); writeBooleanIfTrue(out, DEVICE_EFFECT_MAXIMIZE_DOZE, deviceEffects.shouldMaximizeDoze()); writeBooleanIfTrue(out, DEVICE_EFFECT_USE_NIGHT_LIGHT, deviceEffects.shouldUseNightLight()); if (android.service.notification.Flags.applyBrightnessClampingForModes()) { writeFloatIfNotNull( out, DEVICE_EFFECT_CAP_BRIGHTNESS, deviceEffects.getBrightnessPercentageCap()); } writeStringSet(out, DEVICE_EFFECT_EXTRAS, deviceEffects.getExtraEffects()); } Loading @@ -1273,6 +1280,13 @@ public class ZenModeConfig implements Parcelable { } } private static void writeFloatIfNotNull( TypedXmlSerializer out, String att, @Nullable Float value) throws IOException { if (value != null) { out.attributeFloat(null, att, value); } } private static void writeStringSet(TypedXmlSerializer out, String att, Set<String> values) throws IOException { if (values.isEmpty()) { Loading Loading @@ -1326,6 +1340,15 @@ public class ZenModeConfig implements Parcelable { return parser.getAttributeInt(null, att, defValue); } @Nullable private static Float unsafeFloat(TypedXmlPullParser parser, String att) { try { return parser.getAttributeFloat(null, att); } catch (Exception e) { return null; } } private static ComponentName safeComponentName(TypedXmlPullParser parser, String att) { final String val = parser.getAttributeValue(null, att); if (TextUtils.isEmpty(val)) return null; Loading
core/java/android/service/notification/ZenModeDiff.java +10 −0 Original line number Diff line number Diff line Loading @@ -611,6 +611,7 @@ public class ZenModeDiff { public static final String FIELD_MINIMIZE_RADIO_USAGE = "mMinimizeRadioUsage"; public static final String FIELD_MAXIMIZE_DOZE = "mMaximizeDoze"; public static final String FIELD_NIGHT_LIGHT = "mNightLight"; public static final String FIELD_BRIGHTNESS_CAP = "mBrightnessCap"; public static final String FIELD_EXTRA_EFFECTS = "mExtraEffects"; // NOTE: new field strings must match the variable names in ZenDeviceEffects Loading Loading @@ -683,6 +684,15 @@ public class ZenModeDiff { FIELD_NIGHT_LIGHT, new FieldDiff<>(from.shouldUseNightLight(), to.shouldUseNightLight())); } if (Flags.applyBrightnessClampingForModes() && !Objects.equals( from.getBrightnessPercentageCap(), to.getBrightnessPercentageCap())) { addField( FIELD_BRIGHTNESS_CAP, new FieldDiff<>( from.getBrightnessPercentageCap(), to.getBrightnessPercentageCap())); } if (!Objects.equals(from.getExtraEffects(), to.getExtraEffects())) { addField(FIELD_EXTRA_EFFECTS, new FieldDiff<>(from.getExtraEffects(), to.getExtraEffects())); Loading
core/java/android/service/notification/flags.aconfig +6 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,12 @@ flag { bug: "409474564" } flag { name: "apply_brightness_clamping_for_modes" namespace: "wear_frameworks" description: "Whether to apply brightness clamping for modes" bug: "387528442" } Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +7 −0 Original line number Diff line number Diff line Loading @@ -1425,6 +1425,7 @@ public class ZenModeHelper { .setShouldMinimizeRadioUsage(oldEffects.shouldMinimizeRadioUsage()) .setShouldMaximizeDoze(oldEffects.shouldMaximizeDoze()) .setShouldUseNightLight(oldEffects.shouldUseNightLight()) .setBrightnessPercentageCap(oldEffects.getBrightnessPercentageCap()) .setExtraEffects(oldEffects.getExtraEffects()) .build(); } Loading Loading @@ -1468,6 +1469,12 @@ public class ZenModeHelper { if (oldEffects.shouldUseNightLight() != newEffects.shouldUseNightLight()) { userModifiedFields |= ZenDeviceEffects.FIELD_NIGHT_LIGHT; } if (android.service.notification.Flags.applyBrightnessClampingForModes() && !Objects.equals( oldEffects.getBrightnessPercentageCap(), newEffects.getBrightnessPercentageCap())) { userModifiedFields |= ZenDeviceEffects.FIELD_BRIGHTNESS_CAP; } if (!Objects.equals(oldEffects.getExtraEffects(), newEffects.getExtraEffects())) { userModifiedFields |= ZenDeviceEffects.FIELD_EXTRA_EFFECTS; } Loading