• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.service.notification;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.TestApi;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.HashSet;
31 import java.util.Objects;
32 import java.util.Set;
33 
34 /**
35  * Represents the set of device effects (affecting display and device behavior in general) that
36  * are applied whenever an {@link android.app.AutomaticZenRule} is active.
37  */
38 public final class ZenDeviceEffects implements Parcelable {
39 
40     /**
41      * Enum for the user-modifiable fields in this object.
42      *
43      * @hide
44      */
45     @IntDef(
46             flag = true,
47             prefix = {"FIELD_"},
48             value = {
49                 FIELD_GRAYSCALE,
50                 FIELD_SUPPRESS_AMBIENT_DISPLAY,
51                 FIELD_DIM_WALLPAPER,
52                 FIELD_NIGHT_MODE,
53                 FIELD_DISABLE_AUTO_BRIGHTNESS,
54                 FIELD_DISABLE_TAP_TO_WAKE,
55                 FIELD_DISABLE_TILT_TO_WAKE,
56                 FIELD_DISABLE_TOUCH,
57                 FIELD_MINIMIZE_RADIO_USAGE,
58                 FIELD_MAXIMIZE_DOZE,
59                 FIELD_NIGHT_LIGHT,
60                 FIELD_EXTRA_EFFECTS
61             })
62     @Retention(RetentionPolicy.SOURCE)
63     public @interface ModifiableField {}
64 
65     /**
66      * @hide
67      */
68     public static final int FIELD_GRAYSCALE = 1 << 0;
69     /**
70      * @hide
71      */
72     public static final int FIELD_SUPPRESS_AMBIENT_DISPLAY = 1 << 1;
73     /**
74      * @hide
75      */
76     public static final int FIELD_DIM_WALLPAPER = 1 << 2;
77     /**
78      * @hide
79      */
80     public static final int FIELD_NIGHT_MODE = 1 << 3;
81     /**
82      * @hide
83      */
84     public static final int FIELD_DISABLE_AUTO_BRIGHTNESS = 1 << 4;
85     /**
86      * @hide
87      */
88     public static final int FIELD_DISABLE_TAP_TO_WAKE = 1 << 5;
89     /**
90      * @hide
91      */
92     public static final int FIELD_DISABLE_TILT_TO_WAKE = 1 << 6;
93     /**
94      * @hide
95      */
96     public static final int FIELD_DISABLE_TOUCH = 1 << 7;
97     /**
98      * @hide
99      */
100     public static final int FIELD_MINIMIZE_RADIO_USAGE = 1 << 8;
101     /**
102      * @hide
103      */
104     public static final int FIELD_MAXIMIZE_DOZE = 1 << 9;
105     /**
106      * @hide
107      */
108     public static final int FIELD_EXTRA_EFFECTS = 1 << 10;
109 
110     /** @hide */
111     public static final int FIELD_NIGHT_LIGHT = 1 << 11;
112 
113     private static final int MAX_EFFECTS_LENGTH = 2_000; // characters
114 
115     private final boolean mGrayscale;
116     private final boolean mSuppressAmbientDisplay;
117     private final boolean mDimWallpaper;
118     private final boolean mNightMode;
119 
120     private final boolean mDisableAutoBrightness;
121     private final boolean mDisableTapToWake;
122     private final boolean mDisableTiltToWake;
123     private final boolean mDisableTouch;
124     private final boolean mMinimizeRadioUsage;
125     private final boolean mMaximizeDoze;
126     private final boolean mNightLight;
127     private final Set<String> mExtraEffects;
128 
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)129     private ZenDeviceEffects(
130             boolean grayscale,
131             boolean suppressAmbientDisplay,
132             boolean dimWallpaper,
133             boolean nightMode,
134             boolean disableAutoBrightness,
135             boolean disableTapToWake,
136             boolean disableTiltToWake,
137             boolean disableTouch,
138             boolean minimizeRadioUsage,
139             boolean maximizeDoze,
140             boolean nightLight,
141             Set<String> extraEffects) {
142         mGrayscale = grayscale;
143         mSuppressAmbientDisplay = suppressAmbientDisplay;
144         mDimWallpaper = dimWallpaper;
145         mNightMode = nightMode;
146         mDisableAutoBrightness = disableAutoBrightness;
147         mDisableTapToWake = disableTapToWake;
148         mDisableTiltToWake = disableTiltToWake;
149         mDisableTouch = disableTouch;
150         mMinimizeRadioUsage = minimizeRadioUsage;
151         mMaximizeDoze = maximizeDoze;
152         mNightLight = nightLight;
153         mExtraEffects = Collections.unmodifiableSet(extraEffects);
154     }
155 
156     /** @hide */
validate()157     public void validate() {
158         int extraEffectsLength = 0;
159         for (String extraEffect : mExtraEffects) {
160             extraEffectsLength += extraEffect.length();
161         }
162         if (extraEffectsLength > MAX_EFFECTS_LENGTH) {
163             throw new IllegalArgumentException(
164                     "Total size of extra effects must be at most " + MAX_EFFECTS_LENGTH
165                             + " characters");
166         }
167     }
168 
169     @Override
equals(Object obj)170     public boolean equals(Object obj) {
171         if (!(obj instanceof final ZenDeviceEffects that)) return false;
172         if (obj == this) return true;
173 
174         return this.mGrayscale == that.mGrayscale
175                 && this.mSuppressAmbientDisplay == that.mSuppressAmbientDisplay
176                 && this.mDimWallpaper == that.mDimWallpaper
177                 && this.mNightMode == that.mNightMode
178                 && this.mDisableAutoBrightness == that.mDisableAutoBrightness
179                 && this.mDisableTapToWake == that.mDisableTapToWake
180                 && this.mDisableTiltToWake == that.mDisableTiltToWake
181                 && this.mDisableTouch == that.mDisableTouch
182                 && this.mMinimizeRadioUsage == that.mMinimizeRadioUsage
183                 && this.mMaximizeDoze == that.mMaximizeDoze
184                 && this.mNightLight == that.mNightLight
185                 && Objects.equals(this.mExtraEffects, that.mExtraEffects);
186     }
187 
188     @Override
hashCode()189     public int hashCode() {
190         return Objects.hash(
191                 mGrayscale,
192                 mSuppressAmbientDisplay,
193                 mDimWallpaper,
194                 mNightMode,
195                 mDisableAutoBrightness,
196                 mDisableTapToWake,
197                 mDisableTiltToWake,
198                 mDisableTouch,
199                 mMinimizeRadioUsage,
200                 mMaximizeDoze,
201                 mNightLight,
202                 mExtraEffects);
203     }
204 
205     @Override
toString()206     public String toString() {
207         ArrayList<String> effects = new ArrayList<>(11);
208         if (mGrayscale) effects.add("grayscale");
209         if (mSuppressAmbientDisplay) effects.add("suppressAmbientDisplay");
210         if (mDimWallpaper) effects.add("dimWallpaper");
211         if (mNightMode) effects.add("nightMode");
212         if (mDisableAutoBrightness) effects.add("disableAutoBrightness");
213         if (mDisableTapToWake) effects.add("disableTapToWake");
214         if (mDisableTiltToWake) effects.add("disableTiltToWake");
215         if (mDisableTouch) effects.add("disableTouch");
216         if (mMinimizeRadioUsage) effects.add("minimizeRadioUsage");
217         if (mMaximizeDoze) effects.add("maximizeDoze");
218         if (mNightLight) effects.add("nightLight");
219         if (mExtraEffects.size() > 0) {
220             effects.add("extraEffects=[" + String.join(",", mExtraEffects) + "]");
221         }
222         return "[" + String.join(", ", effects) + "]";
223     }
224 
225     /** @hide */
fieldsToString(@odifiableField int bitmask)226     public static String fieldsToString(@ModifiableField int bitmask) {
227         ArrayList<String> modified = new ArrayList<>();
228         if ((bitmask & FIELD_GRAYSCALE) != 0) {
229             modified.add("FIELD_GRAYSCALE");
230         }
231         if ((bitmask & FIELD_SUPPRESS_AMBIENT_DISPLAY) != 0) {
232             modified.add("FIELD_SUPPRESS_AMBIENT_DISPLAY");
233         }
234         if ((bitmask & FIELD_DIM_WALLPAPER) != 0) {
235             modified.add("FIELD_DIM_WALLPAPER");
236         }
237         if ((bitmask & FIELD_NIGHT_MODE) != 0) {
238             modified.add("FIELD_NIGHT_MODE");
239         }
240         if ((bitmask & FIELD_DISABLE_AUTO_BRIGHTNESS) != 0) {
241             modified.add("FIELD_DISABLE_AUTO_BRIGHTNESS");
242         }
243         if ((bitmask & FIELD_DISABLE_TAP_TO_WAKE) != 0) {
244             modified.add("FIELD_DISABLE_TAP_TO_WAKE");
245         }
246         if ((bitmask & FIELD_DISABLE_TILT_TO_WAKE) != 0) {
247             modified.add("FIELD_DISABLE_TILT_TO_WAKE");
248         }
249         if ((bitmask & FIELD_DISABLE_TOUCH) != 0) {
250             modified.add("FIELD_DISABLE_TOUCH");
251         }
252         if ((bitmask & FIELD_MINIMIZE_RADIO_USAGE) != 0) {
253             modified.add("FIELD_MINIMIZE_RADIO_USAGE");
254         }
255         if ((bitmask & FIELD_MAXIMIZE_DOZE) != 0) {
256             modified.add("FIELD_MAXIMIZE_DOZE");
257         }
258         if (((bitmask) & FIELD_NIGHT_LIGHT) != 0) {
259             modified.add("FIELD_NIGHT_LIGHT");
260         }
261         if ((bitmask & FIELD_EXTRA_EFFECTS) != 0) {
262             modified.add("FIELD_EXTRA_EFFECTS");
263         }
264         return "{" + String.join(",", modified) + "}";
265     }
266 
267     /**
268      * Whether the level of color saturation of the display should be set to minimum, effectively
269      * switching it to grayscale, while the rule is active.
270      */
shouldDisplayGrayscale()271     public boolean shouldDisplayGrayscale() {
272         return mGrayscale;
273     }
274 
275     /**
276      * Whether the ambient (always-on) display feature should be disabled while the rule is active.
277      * This will have no effect if the device doesn't support always-on display or if it's not
278      * generally enabled.
279      */
shouldSuppressAmbientDisplay()280     public boolean shouldSuppressAmbientDisplay() {
281         return mSuppressAmbientDisplay;
282     }
283 
284     /** Whether the wallpaper should be dimmed while the rule is active. */
shouldDimWallpaper()285     public boolean shouldDimWallpaper() {
286         return mDimWallpaper;
287     }
288 
289     /** Whether night mode (aka dark theme) should be applied while the rule is active. */
shouldUseNightMode()290     public boolean shouldUseNightMode() {
291         return mNightMode;
292     }
293 
294     /**
295      * Whether the display's automatic brightness adjustment should be disabled while the rule is
296      * active.
297      * @hide
298      */
shouldDisableAutoBrightness()299     public boolean shouldDisableAutoBrightness() {
300         return mDisableAutoBrightness;
301     }
302 
303     /**
304      * Whether "tap to wake" should be disabled while the rule is active.
305      * @hide
306      */
shouldDisableTapToWake()307     public boolean shouldDisableTapToWake() {
308         return mDisableTapToWake;
309     }
310 
311     /**
312      * Whether "tilt to wake" should be disabled while the rule is active.
313      * @hide
314      */
shouldDisableTiltToWake()315     public boolean shouldDisableTiltToWake() {
316         return mDisableTiltToWake;
317     }
318 
319     /**
320      * Whether touch interactions should be disabled while the rule is active.
321      * @hide
322      */
shouldDisableTouch()323     public boolean shouldDisableTouch() {
324         return mDisableTouch;
325     }
326 
327     /**
328      * Whether radio (wi-fi, LTE, etc) traffic, and its attendant battery consumption, should be
329      * minimized while the rule is active.
330      * @hide
331      */
shouldMinimizeRadioUsage()332     public boolean shouldMinimizeRadioUsage() {
333         return mMinimizeRadioUsage;
334     }
335 
336     /**
337      * Whether Doze should be enhanced (e.g. with more aggressive activation, or less frequent
338      * maintenance windows) while the rule is active.
339      * @hide
340      */
shouldMaximizeDoze()341     public boolean shouldMaximizeDoze() {
342         return mMaximizeDoze;
343     }
344 
345     /**
346      * Whether the night display transformation should be activated while the rule is active.
347      *
348      * @hide
349      */
shouldUseNightLight()350     public boolean shouldUseNightLight() {
351         return mNightLight;
352     }
353 
354     /**
355      * (Immutable) set of extra effects to be applied while the rule is active. Extra effects are
356      * not used in AOSP, but OEMs may add support for them by providing a custom
357      * {@link DeviceEffectsApplier}.
358      * @hide
359      */
360     @TestApi
361     @NonNull
getExtraEffects()362     public Set<String> getExtraEffects() {
363         return mExtraEffects;
364     }
365 
366     /**
367      * Whether any of the effects are set up.
368      * @hide
369      */
hasEffects()370     public boolean hasEffects() {
371         return mGrayscale
372                 || mSuppressAmbientDisplay
373                 || mDimWallpaper
374                 || mNightMode
375                 || mDisableAutoBrightness
376                 || mDisableTapToWake
377                 || mDisableTiltToWake
378                 || mDisableTouch
379                 || mMinimizeRadioUsage
380                 || mMaximizeDoze
381                 || mNightLight
382                 || mExtraEffects.size() > 0;
383     }
384 
385     /** {@link Parcelable.Creator} that instantiates {@link ZenDeviceEffects} objects. */
386     @NonNull
387     public static final Creator<ZenDeviceEffects> CREATOR =
388             new Creator<ZenDeviceEffects>() {
389                 @Override
390                 public ZenDeviceEffects createFromParcel(Parcel in) {
391                     return new ZenDeviceEffects(
392                             in.readBoolean(),
393                             in.readBoolean(),
394                             in.readBoolean(),
395                             in.readBoolean(),
396                             in.readBoolean(),
397                             in.readBoolean(),
398                             in.readBoolean(),
399                             in.readBoolean(),
400                             in.readBoolean(),
401                             in.readBoolean(),
402                             in.readBoolean(),
403                             Set.of(in.readArray(String.class.getClassLoader(), String.class)));
404                 }
405 
406                 @Override
407                 public ZenDeviceEffects[] newArray(int size) {
408                     return new ZenDeviceEffects[size];
409                 }
410             };
411 
412     @Override
describeContents()413     public int describeContents() {
414         return 0;
415     }
416 
417     @Override
writeToParcel(@onNull Parcel dest, int flags)418     public void writeToParcel(@NonNull Parcel dest, int flags) {
419         dest.writeBoolean(mGrayscale);
420         dest.writeBoolean(mSuppressAmbientDisplay);
421         dest.writeBoolean(mDimWallpaper);
422         dest.writeBoolean(mNightMode);
423         dest.writeBoolean(mDisableAutoBrightness);
424         dest.writeBoolean(mDisableTapToWake);
425         dest.writeBoolean(mDisableTiltToWake);
426         dest.writeBoolean(mDisableTouch);
427         dest.writeBoolean(mMinimizeRadioUsage);
428         dest.writeBoolean(mMaximizeDoze);
429         dest.writeBoolean(mNightLight);
430         dest.writeArray(mExtraEffects.toArray(new String[0]));
431     }
432 
433     /** Builder class for {@link ZenDeviceEffects} objects. */
434     public static final class Builder {
435 
436         private boolean mGrayscale;
437         private boolean mSuppressAmbientDisplay;
438         private boolean mDimWallpaper;
439         private boolean mNightMode;
440         private boolean mDisableAutoBrightness;
441         private boolean mDisableTapToWake;
442         private boolean mDisableTiltToWake;
443         private boolean mDisableTouch;
444         private boolean mMinimizeRadioUsage;
445         private boolean mMaximizeDoze;
446         private boolean mNightLight;
447         private final HashSet<String> mExtraEffects = new HashSet<>();
448 
449         /**
450          * Instantiates a new {@link ZenPolicy.Builder} with all effects set to default (disabled).
451          */
Builder()452         public Builder() {
453         }
454 
455         /**
456          * Instantiates a new {@link ZenPolicy.Builder} with all effects set to their corresponding
457          * values in the supplied {@link ZenDeviceEffects}.
458          */
Builder(@onNull ZenDeviceEffects zenDeviceEffects)459         public Builder(@NonNull ZenDeviceEffects zenDeviceEffects) {
460             mGrayscale = zenDeviceEffects.shouldDisplayGrayscale();
461             mSuppressAmbientDisplay = zenDeviceEffects.shouldSuppressAmbientDisplay();
462             mDimWallpaper = zenDeviceEffects.shouldDimWallpaper();
463             mNightMode = zenDeviceEffects.shouldUseNightMode();
464             mDisableAutoBrightness = zenDeviceEffects.shouldDisableAutoBrightness();
465             mDisableTapToWake = zenDeviceEffects.shouldDisableTapToWake();
466             mDisableTiltToWake = zenDeviceEffects.shouldDisableTiltToWake();
467             mDisableTouch = zenDeviceEffects.shouldDisableTouch();
468             mMinimizeRadioUsage = zenDeviceEffects.shouldMinimizeRadioUsage();
469             mMaximizeDoze = zenDeviceEffects.shouldMaximizeDoze();
470             mNightLight = zenDeviceEffects.shouldUseNightLight();
471             mExtraEffects.addAll(zenDeviceEffects.getExtraEffects());
472         }
473 
474         /**
475          * Sets whether the level of color saturation of the display should be set to minimum,
476          * effectively switching it to grayscale, while the rule is active.
477          */
478         @NonNull
setShouldDisplayGrayscale(boolean grayscale)479         public Builder setShouldDisplayGrayscale(boolean grayscale) {
480             mGrayscale = grayscale;
481             return this;
482         }
483 
484         /**
485          * Sets whether the ambient (always-on) display feature should be disabled while the rule
486          * is active. This will have no effect if the device doesn't support always-on display or if
487          * it's not generally enabled.
488          */
489         @NonNull
setShouldSuppressAmbientDisplay(boolean suppressAmbientDisplay)490         public Builder setShouldSuppressAmbientDisplay(boolean suppressAmbientDisplay) {
491             mSuppressAmbientDisplay = suppressAmbientDisplay;
492             return this;
493         }
494 
495         /** Sets whether the wallpaper should be dimmed while the rule is active. */
496         @NonNull
setShouldDimWallpaper(boolean dimWallpaper)497         public Builder setShouldDimWallpaper(boolean dimWallpaper) {
498             mDimWallpaper = dimWallpaper;
499             return this;
500         }
501 
502         /** Sets whether night mode (aka dark theme) should be applied while the rule is active. */
503         @NonNull
setShouldUseNightMode(boolean nightMode)504         public Builder setShouldUseNightMode(boolean nightMode) {
505             mNightMode = nightMode;
506             return this;
507         }
508 
509         /**
510          * Sets whether the display's automatic brightness adjustment should be disabled while the
511          * rule is active.
512          * @hide
513          */
514         @NonNull
setShouldDisableAutoBrightness(boolean disableAutoBrightness)515         public Builder setShouldDisableAutoBrightness(boolean disableAutoBrightness) {
516             mDisableAutoBrightness = disableAutoBrightness;
517             return this;
518         }
519 
520         /**
521          * Sets whether "tap to wake" should be disabled while the rule is active.
522          * @hide
523          */
524         @NonNull
setShouldDisableTapToWake(boolean disableTapToWake)525         public Builder setShouldDisableTapToWake(boolean disableTapToWake) {
526             mDisableTapToWake = disableTapToWake;
527             return this;
528         }
529 
530         /**
531          * Sets whether "tilt to wake" should be disabled while the rule is active.
532          * @hide
533          */
534         @NonNull
setShouldDisableTiltToWake(boolean disableTiltToWake)535         public Builder setShouldDisableTiltToWake(boolean disableTiltToWake) {
536             mDisableTiltToWake = disableTiltToWake;
537             return this;
538         }
539 
540         /**
541          * Sets whether touch interactions should be disabled while the rule is active.
542          * @hide
543          */
544         @NonNull
setShouldDisableTouch(boolean disableTouch)545         public Builder setShouldDisableTouch(boolean disableTouch) {
546             mDisableTouch = disableTouch;
547             return this;
548         }
549 
550         /**
551          * Sets whether radio (wi-fi, LTE, etc) traffic, and its attendant battery consumption,
552          * should be minimized while the rule is active.
553          * @hide
554          */
555         @NonNull
setShouldMinimizeRadioUsage(boolean minimizeRadioUsage)556         public Builder setShouldMinimizeRadioUsage(boolean minimizeRadioUsage) {
557             mMinimizeRadioUsage = minimizeRadioUsage;
558             return this;
559         }
560 
561         /**
562          * Sets whether Doze should be enhanced (e.g. with more aggressive activation, or less
563          * frequent maintenance windows) while the rule is active.
564          * @hide
565          */
566         @NonNull
setShouldMaximizeDoze(boolean maximizeDoze)567         public Builder setShouldMaximizeDoze(boolean maximizeDoze) {
568             mMaximizeDoze = maximizeDoze;
569             return this;
570         }
571 
572         /**
573          * Sets whether the night display transformation should be activated while the rule is
574          * active.
575          *
576          * @hide
577          */
578         @NonNull
setShouldUseNightLight(boolean nightLight)579         public Builder setShouldUseNightLight(boolean nightLight) {
580             mNightLight = nightLight;
581             return this;
582         }
583 
584         /**
585          * Sets the extra effects to be applied while the rule is active. Extra effects are not
586          * used in AOSP, but OEMs may add support for them by providing a custom
587          * {@link DeviceEffectsApplier}.
588          *
589          * @apiNote The total size of the extra effects (concatenation of strings) is limited.
590          *
591          * @hide
592          */
593         @TestApi
594         @NonNull
setExtraEffects(@onNull Set<String> extraEffects)595         public Builder setExtraEffects(@NonNull Set<String> extraEffects) {
596             Objects.requireNonNull(extraEffects);
597             mExtraEffects.clear();
598             mExtraEffects.addAll(extraEffects);
599             return this;
600         }
601 
602         /**
603          * Adds the supplied extra effects to the set to be applied while the rule is active.
604          * Extra effects are not used in AOSP, but OEMs may add support for them by providing a
605          * custom {@link DeviceEffectsApplier}.
606          *
607          * @apiNote The total size of the extra effects (concatenation of strings) is limited.
608          *
609          * @hide
610          */
611         @NonNull
addExtraEffects(@onNull Set<String> extraEffects)612         public Builder addExtraEffects(@NonNull Set<String> extraEffects) {
613             mExtraEffects.addAll(Objects.requireNonNull(extraEffects));
614             return this;
615         }
616 
617         /**
618          * Adds the supplied extra effect to the set to be applied while the rule is active.
619          * Extra effects are not used in AOSP, but OEMs may add support for them by providing a
620          * custom {@link DeviceEffectsApplier}.
621          *
622          * @apiNote The total size of the extra effects (concatenation of strings) is limited.
623          *
624          * @hide
625          */
626         @NonNull
addExtraEffect(@onNull String extraEffect)627         public Builder addExtraEffect(@NonNull String extraEffect) {
628             mExtraEffects.add(Objects.requireNonNull(extraEffect));
629             return this;
630         }
631 
632         /**
633          * Applies the effects that are {@code true} on the supplied {@link ZenDeviceEffects} to
634          * this builder (essentially logically-ORing the effect set).
635          * @hide
636          */
637         @NonNull
add(@ullable ZenDeviceEffects effects)638         public Builder add(@Nullable ZenDeviceEffects effects) {
639             if (effects == null) return this;
640             if (effects.shouldDisplayGrayscale()) setShouldDisplayGrayscale(true);
641             if (effects.shouldSuppressAmbientDisplay()) setShouldSuppressAmbientDisplay(true);
642             if (effects.shouldDimWallpaper()) setShouldDimWallpaper(true);
643             if (effects.shouldUseNightMode()) setShouldUseNightMode(true);
644             if (effects.shouldDisableAutoBrightness()) setShouldDisableAutoBrightness(true);
645             if (effects.shouldDisableTapToWake()) setShouldDisableTapToWake(true);
646             if (effects.shouldDisableTiltToWake()) setShouldDisableTiltToWake(true);
647             if (effects.shouldDisableTouch()) setShouldDisableTouch(true);
648             if (effects.shouldMinimizeRadioUsage()) setShouldMinimizeRadioUsage(true);
649             if (effects.shouldMaximizeDoze()) setShouldMaximizeDoze(true);
650             if (effects.shouldUseNightLight()) setShouldUseNightLight(true);
651             addExtraEffects(effects.getExtraEffects());
652             return this;
653         }
654 
655         /** Builds a {@link ZenDeviceEffects} object based on the builder's state. */
656         @NonNull
build()657         public ZenDeviceEffects build() {
658             return new ZenDeviceEffects(
659                     mGrayscale,
660                     mSuppressAmbientDisplay,
661                     mDimWallpaper,
662                     mNightMode,
663                     mDisableAutoBrightness,
664                     mDisableTapToWake,
665                     mDisableTiltToWake,
666                     mDisableTouch,
667                     mMinimizeRadioUsage,
668                     mMaximizeDoze,
669                     mNightLight,
670                     mExtraEffects);
671         }
672     }
673 }
674