Loading core/java/android/service/notification/ZenDeviceEffects.java +127 −42 Original line number Diff line number Diff line Loading @@ -42,9 +42,13 @@ public final class ZenDeviceEffects implements Parcelable { /** * Enum for the user-modifiable fields in this object. * * @hide */ @IntDef(flag = true, prefix = { "FIELD_" }, value = { @IntDef( flag = true, prefix = {"FIELD_"}, value = { FIELD_GRAYSCALE, FIELD_SUPPRESS_AMBIENT_DISPLAY, FIELD_DIM_WALLPAPER, Loading @@ -55,6 +59,7 @@ public final class ZenDeviceEffects implements Parcelable { FIELD_DISABLE_TOUCH, FIELD_MINIMIZE_RADIO_USAGE, FIELD_MAXIMIZE_DOZE, FIELD_NIGHT_LIGHT, FIELD_EXTRA_EFFECTS }) @Retention(RetentionPolicy.SOURCE) Loading Loading @@ -105,6 +110,9 @@ public final class ZenDeviceEffects implements Parcelable { */ public static final int FIELD_EXTRA_EFFECTS = 1 << 10; /** @hide */ public static final int FIELD_NIGHT_LIGHT = 1 << 11; private static final int MAX_EFFECTS_LENGTH = 2_000; // characters private final boolean mGrayscale; Loading @@ -118,12 +126,22 @@ public final class ZenDeviceEffects implements Parcelable { private final boolean mDisableTouch; private final boolean mMinimizeRadioUsage; private final boolean mMaximizeDoze; private final boolean mNightLight; private final Set<String> mExtraEffects; private ZenDeviceEffects(boolean grayscale, boolean suppressAmbientDisplay, boolean dimWallpaper, boolean nightMode, boolean disableAutoBrightness, boolean disableTapToWake, boolean disableTiltToWake, boolean disableTouch, boolean minimizeRadioUsage, boolean maximizeDoze, Set<String> extraEffects) { private ZenDeviceEffects( boolean grayscale, boolean suppressAmbientDisplay, boolean dimWallpaper, boolean nightMode, boolean disableAutoBrightness, boolean disableTapToWake, boolean disableTiltToWake, boolean disableTouch, boolean minimizeRadioUsage, boolean maximizeDoze, boolean nightLight, Set<String> extraEffects) { mGrayscale = grayscale; mSuppressAmbientDisplay = suppressAmbientDisplay; mDimWallpaper = dimWallpaper; Loading @@ -134,6 +152,7 @@ public final class ZenDeviceEffects implements Parcelable { mDisableTouch = disableTouch; mMinimizeRadioUsage = minimizeRadioUsage; mMaximizeDoze = maximizeDoze; mNightLight = nightLight; mExtraEffects = Collections.unmodifiableSet(extraEffects); } Loading Loading @@ -166,14 +185,25 @@ public final class ZenDeviceEffects implements Parcelable { && this.mDisableTouch == that.mDisableTouch && this.mMinimizeRadioUsage == that.mMinimizeRadioUsage && this.mMaximizeDoze == that.mMaximizeDoze && this.mNightLight == that.mNightLight && Objects.equals(this.mExtraEffects, that.mExtraEffects); } @Override public int hashCode() { return Objects.hash(mGrayscale, mSuppressAmbientDisplay, mDimWallpaper, mNightMode, mDisableAutoBrightness, mDisableTapToWake, mDisableTiltToWake, mDisableTouch, mMinimizeRadioUsage, mMaximizeDoze, mExtraEffects); return Objects.hash( mGrayscale, mSuppressAmbientDisplay, mDimWallpaper, mNightMode, mDisableAutoBrightness, mDisableTapToWake, mDisableTiltToWake, mDisableTouch, mMinimizeRadioUsage, mMaximizeDoze, mNightLight, mExtraEffects); } @Override Loading @@ -189,6 +219,7 @@ public final class ZenDeviceEffects implements Parcelable { if (mDisableTouch) effects.add("disableTouch"); if (mMinimizeRadioUsage) effects.add("minimizeRadioUsage"); if (mMaximizeDoze) effects.add("maximizeDoze"); if (mNightLight) effects.add("nightLight"); if (mExtraEffects.size() > 0) { effects.add("extraEffects=[" + String.join(",", mExtraEffects) + "]"); } Loading Loading @@ -228,6 +259,9 @@ public final class ZenDeviceEffects implements Parcelable { if ((bitmask & FIELD_MAXIMIZE_DOZE) != 0) { modified.add("FIELD_MAXIMIZE_DOZE"); } if (((bitmask) & FIELD_NIGHT_LIGHT) != 0) { modified.add("FIELD_NIGHT_LIGHT"); } if ((bitmask & FIELD_EXTRA_EFFECTS) != 0) { modified.add("FIELD_EXTRA_EFFECTS"); } Loading Loading @@ -312,6 +346,15 @@ public final class ZenDeviceEffects implements Parcelable { return mMaximizeDoze; } /** * Whether the night display transformation should be activated while the rule is active. * * @hide */ public boolean shouldUseNightLight() { return mNightLight; } /** * (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 @@ -329,20 +372,37 @@ public final class ZenDeviceEffects implements Parcelable { * @hide */ public boolean hasEffects() { return mGrayscale || mSuppressAmbientDisplay || mDimWallpaper || mNightMode || mDisableAutoBrightness || mDisableTapToWake || mDisableTiltToWake || mDisableTouch || mMinimizeRadioUsage || mMaximizeDoze return mGrayscale || mSuppressAmbientDisplay || mDimWallpaper || mNightMode || mDisableAutoBrightness || mDisableTapToWake || mDisableTiltToWake || mDisableTouch || mMinimizeRadioUsage || mMaximizeDoze || mNightLight || mExtraEffects.size() > 0; } /** {@link Parcelable.Creator} that instantiates {@link ZenDeviceEffects} objects. */ @NonNull public static final Creator<ZenDeviceEffects> CREATOR = new Creator<ZenDeviceEffects>() { public static final Creator<ZenDeviceEffects> CREATOR = new Creator<ZenDeviceEffects>() { @Override public ZenDeviceEffects createFromParcel(Parcel in) { return new ZenDeviceEffects(in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), return new ZenDeviceEffects( in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), Set.of(in.readArray(String.class.getClassLoader(), String.class))); } Loading Loading @@ -370,6 +430,7 @@ public final class ZenDeviceEffects implements Parcelable { dest.writeBoolean(mDisableTouch); dest.writeBoolean(mMinimizeRadioUsage); dest.writeBoolean(mMaximizeDoze); dest.writeBoolean(mNightLight); dest.writeArray(mExtraEffects.toArray(new String[0])); } Loading @@ -387,6 +448,7 @@ public final class ZenDeviceEffects implements Parcelable { private boolean mDisableTouch; private boolean mMinimizeRadioUsage; private boolean mMaximizeDoze; private boolean mNightLight; private final HashSet<String> mExtraEffects = new HashSet<>(); /** Loading @@ -410,6 +472,7 @@ public final class ZenDeviceEffects implements Parcelable { mDisableTouch = zenDeviceEffects.shouldDisableTouch(); mMinimizeRadioUsage = zenDeviceEffects.shouldMinimizeRadioUsage(); mMaximizeDoze = zenDeviceEffects.shouldMaximizeDoze(); mNightLight = zenDeviceEffects.shouldUseNightLight(); mExtraEffects.addAll(zenDeviceEffects.getExtraEffects()); } Loading Loading @@ -511,6 +574,18 @@ public final class ZenDeviceEffects implements Parcelable { return this; } /** * Sets whether the night display transformation should be activated while the rule is * active. * * @hide */ @NonNull public Builder setShouldUseNightLight(boolean nightLight) { mNightLight = nightLight; 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 @@ -577,6 +652,7 @@ public final class ZenDeviceEffects implements Parcelable { if (effects.shouldDisableTouch()) setShouldDisableTouch(true); if (effects.shouldMinimizeRadioUsage()) setShouldMinimizeRadioUsage(true); if (effects.shouldMaximizeDoze()) setShouldMaximizeDoze(true); if (effects.shouldUseNightLight()) setShouldUseNightLight(true); addExtraEffects(effects.getExtraEffects()); return this; } Loading @@ -584,10 +660,19 @@ public final class ZenDeviceEffects implements Parcelable { /** Builds a {@link ZenDeviceEffects} object based on the builder's state. */ @NonNull public ZenDeviceEffects build() { return new ZenDeviceEffects(mGrayscale, mSuppressAmbientDisplay, mDimWallpaper, mNightMode, mDisableAutoBrightness, mDisableTapToWake, mDisableTiltToWake, mDisableTouch, mMinimizeRadioUsage, mMaximizeDoze, mExtraEffects); return new ZenDeviceEffects( mGrayscale, mSuppressAmbientDisplay, mDimWallpaper, mNightMode, mDisableAutoBrightness, mDisableTapToWake, mDisableTiltToWake, mDisableTouch, mMinimizeRadioUsage, mMaximizeDoze, mNightLight, mExtraEffects); } } } core/java/android/service/notification/ZenModeConfig.java +28 −19 Original line number Diff line number Diff line Loading @@ -325,6 +325,7 @@ public class ZenModeConfig implements Parcelable { private static final String DEVICE_EFFECT_DISABLE_TOUCH = "zdeDisableTouch"; 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_EXTRAS = "zdeExtraEffects"; private static final String DEVICE_EFFECT_USER_MODIFIED_FIELDS = "zdeUserModifiedFields"; Loading Loading @@ -1508,23 +1509,30 @@ public class ZenModeConfig implements Parcelable { @FlaggedApi(Flags.FLAG_MODES_API) @Nullable private static ZenDeviceEffects readZenDeviceEffectsXml(TypedXmlPullParser parser) { ZenDeviceEffects deviceEffects = new ZenDeviceEffects.Builder() ZenDeviceEffects deviceEffects = new ZenDeviceEffects.Builder() .setShouldDisplayGrayscale( safeBoolean(parser, DEVICE_EFFECT_DISPLAY_GRAYSCALE, false)) .setShouldSuppressAmbientDisplay( safeBoolean(parser, DEVICE_EFFECT_SUPPRESS_AMBIENT_DISPLAY, false)) .setShouldDimWallpaper(safeBoolean(parser, DEVICE_EFFECT_DIM_WALLPAPER, false)) .setShouldUseNightMode(safeBoolean(parser, DEVICE_EFFECT_USE_NIGHT_MODE, false)) .setShouldDimWallpaper( safeBoolean(parser, DEVICE_EFFECT_DIM_WALLPAPER, false)) .setShouldUseNightMode( safeBoolean(parser, DEVICE_EFFECT_USE_NIGHT_MODE, false)) .setShouldDisableAutoBrightness( safeBoolean(parser, DEVICE_EFFECT_DISABLE_AUTO_BRIGHTNESS, false)) .setShouldDisableTapToWake( safeBoolean(parser, DEVICE_EFFECT_DISABLE_TAP_TO_WAKE, false)) .setShouldDisableTiltToWake( safeBoolean(parser, DEVICE_EFFECT_DISABLE_TILT_TO_WAKE, false)) .setShouldDisableTouch(safeBoolean(parser, DEVICE_EFFECT_DISABLE_TOUCH, false)) .setShouldDisableTouch( safeBoolean(parser, DEVICE_EFFECT_DISABLE_TOUCH, false)) .setShouldMinimizeRadioUsage( safeBoolean(parser, DEVICE_EFFECT_MINIMIZE_RADIO_USAGE, false)) .setShouldMaximizeDoze(safeBoolean(parser, DEVICE_EFFECT_MAXIMIZE_DOZE, false)) .setShouldMaximizeDoze( safeBoolean(parser, DEVICE_EFFECT_MAXIMIZE_DOZE, false)) .setShouldUseNightLight( safeBoolean(parser, DEVICE_EFFECT_USE_NIGHT_LIGHT, false)) .setExtraEffects(safeStringSet(parser, DEVICE_EFFECT_EXTRAS)) .build(); Loading @@ -1550,6 +1558,7 @@ public class ZenModeConfig implements Parcelable { writeBooleanIfTrue(out, DEVICE_EFFECT_MINIMIZE_RADIO_USAGE, deviceEffects.shouldMinimizeRadioUsage()); writeBooleanIfTrue(out, DEVICE_EFFECT_MAXIMIZE_DOZE, deviceEffects.shouldMaximizeDoze()); writeBooleanIfTrue(out, DEVICE_EFFECT_USE_NIGHT_LIGHT, deviceEffects.shouldUseNightLight()); writeStringSet(out, DEVICE_EFFECT_EXTRAS, deviceEffects.getExtraEffects()); } Loading core/java/android/service/notification/ZenModeDiff.java +6 −0 Original line number Diff line number Diff line Loading @@ -714,6 +714,7 @@ public class ZenModeDiff { public static final String FIELD_DISABLE_TOUCH = "mDisableTouch"; 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_EXTRA_EFFECTS = "mExtraEffects"; // NOTE: new field strings must match the variable names in ZenDeviceEffects Loading Loading @@ -781,6 +782,11 @@ public class ZenModeDiff { addField(FIELD_MAXIMIZE_DOZE, new FieldDiff<>(from.shouldMaximizeDoze(), to.shouldMaximizeDoze())); } if (from.shouldUseNightLight() != to.shouldUseNightLight()) { addField( FIELD_NIGHT_LIGHT, new FieldDiff<>(from.shouldUseNightLight(), to.shouldUseNightLight())); } if (!Objects.equals(from.getExtraEffects(), to.getExtraEffects())) { addField(FIELD_EXTRA_EFFECTS, new FieldDiff<>(from.getExtraEffects(), to.getExtraEffects())); Loading services/core/java/com/android/server/notification/ZenModeHelper.java +15 −9 Original line number Diff line number Diff line Loading @@ -1554,13 +1554,16 @@ public class ZenModeHelper { if (isFromApp) { // Don't allow apps to toggle hidden (non-public-API) effects. newEffects = new ZenDeviceEffects.Builder(newEffects) .setShouldDisableAutoBrightness(oldEffects.shouldDisableAutoBrightness()) newEffects = new ZenDeviceEffects.Builder(newEffects) .setShouldDisableAutoBrightness( oldEffects.shouldDisableAutoBrightness()) .setShouldDisableTapToWake(oldEffects.shouldDisableTapToWake()) .setShouldDisableTiltToWake(oldEffects.shouldDisableTiltToWake()) .setShouldDisableTouch(oldEffects.shouldDisableTouch()) .setShouldMinimizeRadioUsage(oldEffects.shouldMinimizeRadioUsage()) .setShouldMaximizeDoze(oldEffects.shouldMaximizeDoze()) .setShouldUseNightLight(oldEffects.shouldUseNightLight()) .setExtraEffects(oldEffects.getExtraEffects()) .build(); } Loading Loading @@ -1601,6 +1604,9 @@ public class ZenModeHelper { if (oldEffects.shouldMaximizeDoze() != newEffects.shouldMaximizeDoze()) { userModifiedFields |= ZenDeviceEffects.FIELD_MAXIMIZE_DOZE; } if (oldEffects.shouldUseNightLight() != newEffects.shouldUseNightLight()) { userModifiedFields |= ZenDeviceEffects.FIELD_NIGHT_LIGHT; } if (!Objects.equals(oldEffects.getExtraEffects(), newEffects.getExtraEffects())) { userModifiedFields |= ZenDeviceEffects.FIELD_EXTRA_EFFECTS; } Loading services/tests/uiservicestests/src/com/android/server/notification/ZenDeviceEffectsTest.java +25 −17 Original line number Diff line number Diff line Loading @@ -49,13 +49,17 @@ public class ZenDeviceEffectsTest extends UiServiceTestCase { @Test public void builder() { ZenDeviceEffects deviceEffects = new ZenDeviceEffects.Builder() ZenDeviceEffects deviceEffects = new ZenDeviceEffects.Builder() .setShouldDimWallpaper(true) .setShouldDisableTapToWake(true).setShouldDisableTapToWake(false) .setShouldDisableTapToWake(true) .setShouldDisableTapToWake(false) .setShouldDisableTiltToWake(true) .setShouldMaximizeDoze(true) .setShouldUseNightMode(false) .setShouldSuppressAmbientDisplay(false).setShouldSuppressAmbientDisplay(true) .setShouldUseNightLight(true) .setShouldSuppressAmbientDisplay(false) .setShouldSuppressAmbientDisplay(true) .addExtraEffect("WILL BE GONE") .setExtraEffects(ImmutableSet.of("1", "2")) .addExtraEffects(ImmutableSet.of("3", "4")) Loading @@ -68,6 +72,7 @@ public class ZenDeviceEffectsTest extends UiServiceTestCase { assertThat(deviceEffects.shouldDisableTiltToWake()).isTrue(); assertThat(deviceEffects.shouldDisableTouch()).isFalse(); assertThat(deviceEffects.shouldDisplayGrayscale()).isFalse(); assertThat(deviceEffects.shouldUseNightLight()).isTrue(); assertThat(deviceEffects.shouldMaximizeDoze()).isTrue(); assertThat(deviceEffects.shouldMinimizeRadioUsage()).isFalse(); assertThat(deviceEffects.shouldUseNightMode()).isFalse(); Loading @@ -85,15 +90,18 @@ public class ZenDeviceEffectsTest extends UiServiceTestCase { .addExtraEffect("1") .build(); ZenDeviceEffects modified = new ZenDeviceEffects.Builder(original) ZenDeviceEffects modified = new ZenDeviceEffects.Builder(original) .setShouldDisplayGrayscale(true) .setShouldUseNightMode(false) .setShouldUseNightLight(true) .addExtraEffect("2") .build(); assertThat(modified.shouldDimWallpaper()).isTrue(); // from original assertThat(modified.shouldDisableTiltToWake()).isTrue(); // from original assertThat(modified.shouldDisplayGrayscale()).isTrue(); // updated assertThat(modified.shouldUseNightLight()).isTrue(); // updated assertThat(modified.shouldUseNightMode()).isFalse(); // updated assertThat(modified.shouldSuppressAmbientDisplay()).isTrue(); // from original assertThat(modified.getExtraEffects()).containsExactly("1", "2"); // updated Loading Loading
core/java/android/service/notification/ZenDeviceEffects.java +127 −42 Original line number Diff line number Diff line Loading @@ -42,9 +42,13 @@ public final class ZenDeviceEffects implements Parcelable { /** * Enum for the user-modifiable fields in this object. * * @hide */ @IntDef(flag = true, prefix = { "FIELD_" }, value = { @IntDef( flag = true, prefix = {"FIELD_"}, value = { FIELD_GRAYSCALE, FIELD_SUPPRESS_AMBIENT_DISPLAY, FIELD_DIM_WALLPAPER, Loading @@ -55,6 +59,7 @@ public final class ZenDeviceEffects implements Parcelable { FIELD_DISABLE_TOUCH, FIELD_MINIMIZE_RADIO_USAGE, FIELD_MAXIMIZE_DOZE, FIELD_NIGHT_LIGHT, FIELD_EXTRA_EFFECTS }) @Retention(RetentionPolicy.SOURCE) Loading Loading @@ -105,6 +110,9 @@ public final class ZenDeviceEffects implements Parcelable { */ public static final int FIELD_EXTRA_EFFECTS = 1 << 10; /** @hide */ public static final int FIELD_NIGHT_LIGHT = 1 << 11; private static final int MAX_EFFECTS_LENGTH = 2_000; // characters private final boolean mGrayscale; Loading @@ -118,12 +126,22 @@ public final class ZenDeviceEffects implements Parcelable { private final boolean mDisableTouch; private final boolean mMinimizeRadioUsage; private final boolean mMaximizeDoze; private final boolean mNightLight; private final Set<String> mExtraEffects; private ZenDeviceEffects(boolean grayscale, boolean suppressAmbientDisplay, boolean dimWallpaper, boolean nightMode, boolean disableAutoBrightness, boolean disableTapToWake, boolean disableTiltToWake, boolean disableTouch, boolean minimizeRadioUsage, boolean maximizeDoze, Set<String> extraEffects) { private ZenDeviceEffects( boolean grayscale, boolean suppressAmbientDisplay, boolean dimWallpaper, boolean nightMode, boolean disableAutoBrightness, boolean disableTapToWake, boolean disableTiltToWake, boolean disableTouch, boolean minimizeRadioUsage, boolean maximizeDoze, boolean nightLight, Set<String> extraEffects) { mGrayscale = grayscale; mSuppressAmbientDisplay = suppressAmbientDisplay; mDimWallpaper = dimWallpaper; Loading @@ -134,6 +152,7 @@ public final class ZenDeviceEffects implements Parcelable { mDisableTouch = disableTouch; mMinimizeRadioUsage = minimizeRadioUsage; mMaximizeDoze = maximizeDoze; mNightLight = nightLight; mExtraEffects = Collections.unmodifiableSet(extraEffects); } Loading Loading @@ -166,14 +185,25 @@ public final class ZenDeviceEffects implements Parcelable { && this.mDisableTouch == that.mDisableTouch && this.mMinimizeRadioUsage == that.mMinimizeRadioUsage && this.mMaximizeDoze == that.mMaximizeDoze && this.mNightLight == that.mNightLight && Objects.equals(this.mExtraEffects, that.mExtraEffects); } @Override public int hashCode() { return Objects.hash(mGrayscale, mSuppressAmbientDisplay, mDimWallpaper, mNightMode, mDisableAutoBrightness, mDisableTapToWake, mDisableTiltToWake, mDisableTouch, mMinimizeRadioUsage, mMaximizeDoze, mExtraEffects); return Objects.hash( mGrayscale, mSuppressAmbientDisplay, mDimWallpaper, mNightMode, mDisableAutoBrightness, mDisableTapToWake, mDisableTiltToWake, mDisableTouch, mMinimizeRadioUsage, mMaximizeDoze, mNightLight, mExtraEffects); } @Override Loading @@ -189,6 +219,7 @@ public final class ZenDeviceEffects implements Parcelable { if (mDisableTouch) effects.add("disableTouch"); if (mMinimizeRadioUsage) effects.add("minimizeRadioUsage"); if (mMaximizeDoze) effects.add("maximizeDoze"); if (mNightLight) effects.add("nightLight"); if (mExtraEffects.size() > 0) { effects.add("extraEffects=[" + String.join(",", mExtraEffects) + "]"); } Loading Loading @@ -228,6 +259,9 @@ public final class ZenDeviceEffects implements Parcelable { if ((bitmask & FIELD_MAXIMIZE_DOZE) != 0) { modified.add("FIELD_MAXIMIZE_DOZE"); } if (((bitmask) & FIELD_NIGHT_LIGHT) != 0) { modified.add("FIELD_NIGHT_LIGHT"); } if ((bitmask & FIELD_EXTRA_EFFECTS) != 0) { modified.add("FIELD_EXTRA_EFFECTS"); } Loading Loading @@ -312,6 +346,15 @@ public final class ZenDeviceEffects implements Parcelable { return mMaximizeDoze; } /** * Whether the night display transformation should be activated while the rule is active. * * @hide */ public boolean shouldUseNightLight() { return mNightLight; } /** * (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 @@ -329,20 +372,37 @@ public final class ZenDeviceEffects implements Parcelable { * @hide */ public boolean hasEffects() { return mGrayscale || mSuppressAmbientDisplay || mDimWallpaper || mNightMode || mDisableAutoBrightness || mDisableTapToWake || mDisableTiltToWake || mDisableTouch || mMinimizeRadioUsage || mMaximizeDoze return mGrayscale || mSuppressAmbientDisplay || mDimWallpaper || mNightMode || mDisableAutoBrightness || mDisableTapToWake || mDisableTiltToWake || mDisableTouch || mMinimizeRadioUsage || mMaximizeDoze || mNightLight || mExtraEffects.size() > 0; } /** {@link Parcelable.Creator} that instantiates {@link ZenDeviceEffects} objects. */ @NonNull public static final Creator<ZenDeviceEffects> CREATOR = new Creator<ZenDeviceEffects>() { public static final Creator<ZenDeviceEffects> CREATOR = new Creator<ZenDeviceEffects>() { @Override public ZenDeviceEffects createFromParcel(Parcel in) { return new ZenDeviceEffects(in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), return new ZenDeviceEffects( in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), in.readBoolean(), Set.of(in.readArray(String.class.getClassLoader(), String.class))); } Loading Loading @@ -370,6 +430,7 @@ public final class ZenDeviceEffects implements Parcelable { dest.writeBoolean(mDisableTouch); dest.writeBoolean(mMinimizeRadioUsage); dest.writeBoolean(mMaximizeDoze); dest.writeBoolean(mNightLight); dest.writeArray(mExtraEffects.toArray(new String[0])); } Loading @@ -387,6 +448,7 @@ public final class ZenDeviceEffects implements Parcelable { private boolean mDisableTouch; private boolean mMinimizeRadioUsage; private boolean mMaximizeDoze; private boolean mNightLight; private final HashSet<String> mExtraEffects = new HashSet<>(); /** Loading @@ -410,6 +472,7 @@ public final class ZenDeviceEffects implements Parcelable { mDisableTouch = zenDeviceEffects.shouldDisableTouch(); mMinimizeRadioUsage = zenDeviceEffects.shouldMinimizeRadioUsage(); mMaximizeDoze = zenDeviceEffects.shouldMaximizeDoze(); mNightLight = zenDeviceEffects.shouldUseNightLight(); mExtraEffects.addAll(zenDeviceEffects.getExtraEffects()); } Loading Loading @@ -511,6 +574,18 @@ public final class ZenDeviceEffects implements Parcelable { return this; } /** * Sets whether the night display transformation should be activated while the rule is * active. * * @hide */ @NonNull public Builder setShouldUseNightLight(boolean nightLight) { mNightLight = nightLight; 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 @@ -577,6 +652,7 @@ public final class ZenDeviceEffects implements Parcelable { if (effects.shouldDisableTouch()) setShouldDisableTouch(true); if (effects.shouldMinimizeRadioUsage()) setShouldMinimizeRadioUsage(true); if (effects.shouldMaximizeDoze()) setShouldMaximizeDoze(true); if (effects.shouldUseNightLight()) setShouldUseNightLight(true); addExtraEffects(effects.getExtraEffects()); return this; } Loading @@ -584,10 +660,19 @@ public final class ZenDeviceEffects implements Parcelable { /** Builds a {@link ZenDeviceEffects} object based on the builder's state. */ @NonNull public ZenDeviceEffects build() { return new ZenDeviceEffects(mGrayscale, mSuppressAmbientDisplay, mDimWallpaper, mNightMode, mDisableAutoBrightness, mDisableTapToWake, mDisableTiltToWake, mDisableTouch, mMinimizeRadioUsage, mMaximizeDoze, mExtraEffects); return new ZenDeviceEffects( mGrayscale, mSuppressAmbientDisplay, mDimWallpaper, mNightMode, mDisableAutoBrightness, mDisableTapToWake, mDisableTiltToWake, mDisableTouch, mMinimizeRadioUsage, mMaximizeDoze, mNightLight, mExtraEffects); } } }
core/java/android/service/notification/ZenModeConfig.java +28 −19 Original line number Diff line number Diff line Loading @@ -325,6 +325,7 @@ public class ZenModeConfig implements Parcelable { private static final String DEVICE_EFFECT_DISABLE_TOUCH = "zdeDisableTouch"; 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_EXTRAS = "zdeExtraEffects"; private static final String DEVICE_EFFECT_USER_MODIFIED_FIELDS = "zdeUserModifiedFields"; Loading Loading @@ -1508,23 +1509,30 @@ public class ZenModeConfig implements Parcelable { @FlaggedApi(Flags.FLAG_MODES_API) @Nullable private static ZenDeviceEffects readZenDeviceEffectsXml(TypedXmlPullParser parser) { ZenDeviceEffects deviceEffects = new ZenDeviceEffects.Builder() ZenDeviceEffects deviceEffects = new ZenDeviceEffects.Builder() .setShouldDisplayGrayscale( safeBoolean(parser, DEVICE_EFFECT_DISPLAY_GRAYSCALE, false)) .setShouldSuppressAmbientDisplay( safeBoolean(parser, DEVICE_EFFECT_SUPPRESS_AMBIENT_DISPLAY, false)) .setShouldDimWallpaper(safeBoolean(parser, DEVICE_EFFECT_DIM_WALLPAPER, false)) .setShouldUseNightMode(safeBoolean(parser, DEVICE_EFFECT_USE_NIGHT_MODE, false)) .setShouldDimWallpaper( safeBoolean(parser, DEVICE_EFFECT_DIM_WALLPAPER, false)) .setShouldUseNightMode( safeBoolean(parser, DEVICE_EFFECT_USE_NIGHT_MODE, false)) .setShouldDisableAutoBrightness( safeBoolean(parser, DEVICE_EFFECT_DISABLE_AUTO_BRIGHTNESS, false)) .setShouldDisableTapToWake( safeBoolean(parser, DEVICE_EFFECT_DISABLE_TAP_TO_WAKE, false)) .setShouldDisableTiltToWake( safeBoolean(parser, DEVICE_EFFECT_DISABLE_TILT_TO_WAKE, false)) .setShouldDisableTouch(safeBoolean(parser, DEVICE_EFFECT_DISABLE_TOUCH, false)) .setShouldDisableTouch( safeBoolean(parser, DEVICE_EFFECT_DISABLE_TOUCH, false)) .setShouldMinimizeRadioUsage( safeBoolean(parser, DEVICE_EFFECT_MINIMIZE_RADIO_USAGE, false)) .setShouldMaximizeDoze(safeBoolean(parser, DEVICE_EFFECT_MAXIMIZE_DOZE, false)) .setShouldMaximizeDoze( safeBoolean(parser, DEVICE_EFFECT_MAXIMIZE_DOZE, false)) .setShouldUseNightLight( safeBoolean(parser, DEVICE_EFFECT_USE_NIGHT_LIGHT, false)) .setExtraEffects(safeStringSet(parser, DEVICE_EFFECT_EXTRAS)) .build(); Loading @@ -1550,6 +1558,7 @@ public class ZenModeConfig implements Parcelable { writeBooleanIfTrue(out, DEVICE_EFFECT_MINIMIZE_RADIO_USAGE, deviceEffects.shouldMinimizeRadioUsage()); writeBooleanIfTrue(out, DEVICE_EFFECT_MAXIMIZE_DOZE, deviceEffects.shouldMaximizeDoze()); writeBooleanIfTrue(out, DEVICE_EFFECT_USE_NIGHT_LIGHT, deviceEffects.shouldUseNightLight()); writeStringSet(out, DEVICE_EFFECT_EXTRAS, deviceEffects.getExtraEffects()); } Loading
core/java/android/service/notification/ZenModeDiff.java +6 −0 Original line number Diff line number Diff line Loading @@ -714,6 +714,7 @@ public class ZenModeDiff { public static final String FIELD_DISABLE_TOUCH = "mDisableTouch"; 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_EXTRA_EFFECTS = "mExtraEffects"; // NOTE: new field strings must match the variable names in ZenDeviceEffects Loading Loading @@ -781,6 +782,11 @@ public class ZenModeDiff { addField(FIELD_MAXIMIZE_DOZE, new FieldDiff<>(from.shouldMaximizeDoze(), to.shouldMaximizeDoze())); } if (from.shouldUseNightLight() != to.shouldUseNightLight()) { addField( FIELD_NIGHT_LIGHT, new FieldDiff<>(from.shouldUseNightLight(), to.shouldUseNightLight())); } if (!Objects.equals(from.getExtraEffects(), to.getExtraEffects())) { addField(FIELD_EXTRA_EFFECTS, new FieldDiff<>(from.getExtraEffects(), to.getExtraEffects())); Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +15 −9 Original line number Diff line number Diff line Loading @@ -1554,13 +1554,16 @@ public class ZenModeHelper { if (isFromApp) { // Don't allow apps to toggle hidden (non-public-API) effects. newEffects = new ZenDeviceEffects.Builder(newEffects) .setShouldDisableAutoBrightness(oldEffects.shouldDisableAutoBrightness()) newEffects = new ZenDeviceEffects.Builder(newEffects) .setShouldDisableAutoBrightness( oldEffects.shouldDisableAutoBrightness()) .setShouldDisableTapToWake(oldEffects.shouldDisableTapToWake()) .setShouldDisableTiltToWake(oldEffects.shouldDisableTiltToWake()) .setShouldDisableTouch(oldEffects.shouldDisableTouch()) .setShouldMinimizeRadioUsage(oldEffects.shouldMinimizeRadioUsage()) .setShouldMaximizeDoze(oldEffects.shouldMaximizeDoze()) .setShouldUseNightLight(oldEffects.shouldUseNightLight()) .setExtraEffects(oldEffects.getExtraEffects()) .build(); } Loading Loading @@ -1601,6 +1604,9 @@ public class ZenModeHelper { if (oldEffects.shouldMaximizeDoze() != newEffects.shouldMaximizeDoze()) { userModifiedFields |= ZenDeviceEffects.FIELD_MAXIMIZE_DOZE; } if (oldEffects.shouldUseNightLight() != newEffects.shouldUseNightLight()) { userModifiedFields |= ZenDeviceEffects.FIELD_NIGHT_LIGHT; } if (!Objects.equals(oldEffects.getExtraEffects(), newEffects.getExtraEffects())) { userModifiedFields |= ZenDeviceEffects.FIELD_EXTRA_EFFECTS; } Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenDeviceEffectsTest.java +25 −17 Original line number Diff line number Diff line Loading @@ -49,13 +49,17 @@ public class ZenDeviceEffectsTest extends UiServiceTestCase { @Test public void builder() { ZenDeviceEffects deviceEffects = new ZenDeviceEffects.Builder() ZenDeviceEffects deviceEffects = new ZenDeviceEffects.Builder() .setShouldDimWallpaper(true) .setShouldDisableTapToWake(true).setShouldDisableTapToWake(false) .setShouldDisableTapToWake(true) .setShouldDisableTapToWake(false) .setShouldDisableTiltToWake(true) .setShouldMaximizeDoze(true) .setShouldUseNightMode(false) .setShouldSuppressAmbientDisplay(false).setShouldSuppressAmbientDisplay(true) .setShouldUseNightLight(true) .setShouldSuppressAmbientDisplay(false) .setShouldSuppressAmbientDisplay(true) .addExtraEffect("WILL BE GONE") .setExtraEffects(ImmutableSet.of("1", "2")) .addExtraEffects(ImmutableSet.of("3", "4")) Loading @@ -68,6 +72,7 @@ public class ZenDeviceEffectsTest extends UiServiceTestCase { assertThat(deviceEffects.shouldDisableTiltToWake()).isTrue(); assertThat(deviceEffects.shouldDisableTouch()).isFalse(); assertThat(deviceEffects.shouldDisplayGrayscale()).isFalse(); assertThat(deviceEffects.shouldUseNightLight()).isTrue(); assertThat(deviceEffects.shouldMaximizeDoze()).isTrue(); assertThat(deviceEffects.shouldMinimizeRadioUsage()).isFalse(); assertThat(deviceEffects.shouldUseNightMode()).isFalse(); Loading @@ -85,15 +90,18 @@ public class ZenDeviceEffectsTest extends UiServiceTestCase { .addExtraEffect("1") .build(); ZenDeviceEffects modified = new ZenDeviceEffects.Builder(original) ZenDeviceEffects modified = new ZenDeviceEffects.Builder(original) .setShouldDisplayGrayscale(true) .setShouldUseNightMode(false) .setShouldUseNightLight(true) .addExtraEffect("2") .build(); assertThat(modified.shouldDimWallpaper()).isTrue(); // from original assertThat(modified.shouldDisableTiltToWake()).isTrue(); // from original assertThat(modified.shouldDisplayGrayscale()).isTrue(); // updated assertThat(modified.shouldUseNightLight()).isTrue(); // updated assertThat(modified.shouldUseNightMode()).isFalse(); // updated assertThat(modified.shouldSuppressAmbientDisplay()).isTrue(); // from original assertThat(modified.getExtraEffects()).containsExactly("1", "2"); // updated Loading