• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.media;
18 
19 import android.annotation.NonNull;
20 import android.annotation.SuppressLint;
21 import android.annotation.TestApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import java.util.Objects;
26 
27 /** @hide */
28 @TestApi
29 @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
30 public final class VolumePolicy implements Parcelable {
31     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
32     @NonNull
33     public static final VolumePolicy DEFAULT = new VolumePolicy(false, false, false, 400);
34 
35     /**
36      * Accessibility volume policy where the STREAM_MUSIC volume (i.e. media volume) affects
37      * the STREAM_ACCESSIBILITY volume, and vice-versa.
38      */
39     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
40     public static final int A11Y_MODE_MEDIA_A11Y_VOLUME = 0;
41     /**
42      * Accessibility volume policy where the STREAM_ACCESSIBILITY volume is independent from
43      * any other volume.
44      */
45     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
46     public static final int A11Y_MODE_INDEPENDENT_A11Y_VOLUME = 1;
47 
48     /** Allow volume adjustments lower from vibrate to enter ringer mode = silent */
49     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
50     public final boolean volumeDownToEnterSilent;
51 
52     /** Allow volume adjustments higher to exit ringer mode = silent */
53     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
54     public final boolean volumeUpToExitSilent;
55 
56     /** Automatically enter do not disturb when ringer mode = silent */
57     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
58     public final boolean doNotDisturbWhenSilent;
59 
60     /** Only allow volume adjustment from vibrate to silent after this
61         number of milliseconds since an adjustment from normal to vibrate. */
62     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
63     public final int vibrateToSilentDebounce;
64 
65     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
VolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent, boolean doNotDisturbWhenSilent, int vibrateToSilentDebounce)66     public VolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent,
67             boolean doNotDisturbWhenSilent, int vibrateToSilentDebounce) {
68         this.volumeDownToEnterSilent = volumeDownToEnterSilent;
69         this.volumeUpToExitSilent = volumeUpToExitSilent;
70         this.doNotDisturbWhenSilent = doNotDisturbWhenSilent;
71         this.vibrateToSilentDebounce = vibrateToSilentDebounce;
72     }
73 
74     @Override
toString()75     public String toString() {
76         return "VolumePolicy[volumeDownToEnterSilent=" + volumeDownToEnterSilent
77                 + ",volumeUpToExitSilent=" + volumeUpToExitSilent
78                 + ",doNotDisturbWhenSilent=" + doNotDisturbWhenSilent
79                 + ",vibrateToSilentDebounce=" + vibrateToSilentDebounce + "]";
80     }
81 
82     @Override
hashCode()83     public int hashCode() {
84         return Objects.hash(volumeDownToEnterSilent, volumeUpToExitSilent, doNotDisturbWhenSilent,
85                 vibrateToSilentDebounce);
86     }
87 
88     @Override
equals(Object o)89     public boolean equals(Object o) {
90         if (!(o instanceof VolumePolicy)) return false;
91         if (o == this) return true;
92         final VolumePolicy other = (VolumePolicy) o;
93         return other.volumeDownToEnterSilent == volumeDownToEnterSilent
94                 && other.volumeUpToExitSilent == volumeUpToExitSilent
95                 && other.doNotDisturbWhenSilent == doNotDisturbWhenSilent
96                 && other.vibrateToSilentDebounce == vibrateToSilentDebounce;
97     }
98 
99     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
100     @Override
describeContents()101     public int describeContents() {
102         return 0;
103     }
104 
105     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
106     @Override
writeToParcel(@onNull Parcel dest, int flags)107     public void writeToParcel(@NonNull Parcel dest, int flags) {
108         dest.writeInt(volumeDownToEnterSilent ? 1 : 0);
109         dest.writeInt(volumeUpToExitSilent ? 1 : 0);
110         dest.writeInt(doNotDisturbWhenSilent ? 1 : 0);
111         dest.writeInt(vibrateToSilentDebounce);
112     }
113 
114     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
115     public static final @android.annotation.NonNull Parcelable.Creator<VolumePolicy> CREATOR
116             = new Parcelable.Creator<VolumePolicy>() {
117         @Override
118         public VolumePolicy createFromParcel(Parcel p) {
119             return new VolumePolicy(p.readInt() != 0,
120                     p.readInt() != 0,
121                     p.readInt() != 0,
122                     p.readInt());
123         }
124 
125         @Override
126         public VolumePolicy[] newArray(int size) {
127             return new VolumePolicy[size];
128         }
129     };
130 }