blob: b193b70bac2c6521125aedb9662fc2f6527ee0fa [file] [log] [blame]
John Spurlocka48d7792015-03-03 17:35:57 -05001/*
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
17package android.media;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
John Spurlockb02c7442015-04-14 09:32:25 -040022import java.util.Objects;
23
John Spurlocka48d7792015-03-03 17:35:57 -050024/** @hide */
25public final class VolumePolicy implements Parcelable {
Beverly863e2772018-02-06 14:43:31 -050026 public static final VolumePolicy DEFAULT = new VolumePolicy(false, false, false, 400);
John Spurlocka48d7792015-03-03 17:35:57 -050027
Jean-Michel Triviac487672016-11-11 10:05:18 -080028 /**
29 * Accessibility volume policy where the STREAM_MUSIC volume (i.e. media volume) affects
30 * the STREAM_ACCESSIBILITY volume, and vice-versa.
31 */
32 public static final int A11Y_MODE_MEDIA_A11Y_VOLUME = 0;
33 /**
34 * Accessibility volume policy where the STREAM_ACCESSIBILITY volume is independent from
35 * any other volume.
36 */
37 public static final int A11Y_MODE_INDEPENDENT_A11Y_VOLUME = 1;
38
John Spurlock07e72432015-03-13 11:46:52 -040039 /** Allow volume adjustments lower from vibrate to enter ringer mode = silent */
John Spurlocka48d7792015-03-03 17:35:57 -050040 public final boolean volumeDownToEnterSilent;
John Spurlock07e72432015-03-13 11:46:52 -040041
42 /** Allow volume adjustments higher to exit ringer mode = silent */
John Spurlocka48d7792015-03-03 17:35:57 -050043 public final boolean volumeUpToExitSilent;
John Spurlock07e72432015-03-13 11:46:52 -040044
45 /** Automatically enter do not disturb when ringer mode = silent */
John Spurlocka48d7792015-03-03 17:35:57 -050046 public final boolean doNotDisturbWhenSilent;
47
John Spurlock07e72432015-03-13 11:46:52 -040048 /** Only allow volume adjustment from vibrate to silent after this
49 number of milliseconds since an adjustment from normal to vibrate. */
50 public final int vibrateToSilentDebounce;
51
John Spurlocka48d7792015-03-03 17:35:57 -050052 public VolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent,
John Spurlock07e72432015-03-13 11:46:52 -040053 boolean doNotDisturbWhenSilent, int vibrateToSilentDebounce) {
John Spurlocka48d7792015-03-03 17:35:57 -050054 this.volumeDownToEnterSilent = volumeDownToEnterSilent;
55 this.volumeUpToExitSilent = volumeUpToExitSilent;
56 this.doNotDisturbWhenSilent = doNotDisturbWhenSilent;
John Spurlock07e72432015-03-13 11:46:52 -040057 this.vibrateToSilentDebounce = vibrateToSilentDebounce;
John Spurlocka48d7792015-03-03 17:35:57 -050058 }
59
60 @Override
61 public String toString() {
62 return "VolumePolicy[volumeDownToEnterSilent=" + volumeDownToEnterSilent
63 + ",volumeUpToExitSilent=" + volumeUpToExitSilent
John Spurlock07e72432015-03-13 11:46:52 -040064 + ",doNotDisturbWhenSilent=" + doNotDisturbWhenSilent
65 + ",vibrateToSilentDebounce=" + vibrateToSilentDebounce + "]";
John Spurlocka48d7792015-03-03 17:35:57 -050066 }
67
68 @Override
John Spurlockb02c7442015-04-14 09:32:25 -040069 public int hashCode() {
70 return Objects.hash(volumeDownToEnterSilent, volumeUpToExitSilent, doNotDisturbWhenSilent,
71 vibrateToSilentDebounce);
72 }
73
74 @Override
75 public boolean equals(Object o) {
76 if (!(o instanceof VolumePolicy)) return false;
77 if (o == this) return true;
78 final VolumePolicy other = (VolumePolicy) o;
79 return other.volumeDownToEnterSilent == volumeDownToEnterSilent
80 && other.volumeUpToExitSilent == volumeUpToExitSilent
81 && other.doNotDisturbWhenSilent == doNotDisturbWhenSilent
82 && other.vibrateToSilentDebounce == vibrateToSilentDebounce;
83 }
84
85 @Override
John Spurlocka48d7792015-03-03 17:35:57 -050086 public int describeContents() {
87 return 0;
88 }
89
90 @Override
91 public void writeToParcel(Parcel dest, int flags) {
92 dest.writeInt(volumeDownToEnterSilent ? 1 : 0);
93 dest.writeInt(volumeUpToExitSilent ? 1 : 0);
94 dest.writeInt(doNotDisturbWhenSilent ? 1 : 0);
John Spurlock07e72432015-03-13 11:46:52 -040095 dest.writeInt(vibrateToSilentDebounce);
John Spurlocka48d7792015-03-03 17:35:57 -050096 }
97
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070098 public static final @android.annotation.NonNull Parcelable.Creator<VolumePolicy> CREATOR
John Spurlocka48d7792015-03-03 17:35:57 -050099 = new Parcelable.Creator<VolumePolicy>() {
100 @Override
101 public VolumePolicy createFromParcel(Parcel p) {
John Spurlock07e72432015-03-13 11:46:52 -0400102 return new VolumePolicy(p.readInt() != 0,
103 p.readInt() != 0,
104 p.readInt() != 0,
105 p.readInt());
John Spurlocka48d7792015-03-03 17:35:57 -0500106 }
107
108 @Override
109 public VolumePolicy[] newArray(int size) {
110 return new VolumePolicy[size];
111 }
112 };
113}