John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 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.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | |
John Spurlock | b02c744 | 2015-04-14 09:32:25 -0400 | [diff] [blame] | 22 | import java.util.Objects; |
| 23 | |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 24 | /** @hide */ |
| 25 | public final class VolumePolicy implements Parcelable { |
Beverly | 863e277 | 2018-02-06 14:43:31 -0500 | [diff] [blame] | 26 | public static final VolumePolicy DEFAULT = new VolumePolicy(false, false, false, 400); |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 27 | |
Jean-Michel Trivi | ac48767 | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 28 | /** |
| 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 Spurlock | 07e7243 | 2015-03-13 11:46:52 -0400 | [diff] [blame] | 39 | /** Allow volume adjustments lower from vibrate to enter ringer mode = silent */ |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 40 | public final boolean volumeDownToEnterSilent; |
John Spurlock | 07e7243 | 2015-03-13 11:46:52 -0400 | [diff] [blame] | 41 | |
| 42 | /** Allow volume adjustments higher to exit ringer mode = silent */ |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 43 | public final boolean volumeUpToExitSilent; |
John Spurlock | 07e7243 | 2015-03-13 11:46:52 -0400 | [diff] [blame] | 44 | |
| 45 | /** Automatically enter do not disturb when ringer mode = silent */ |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 46 | public final boolean doNotDisturbWhenSilent; |
| 47 | |
John Spurlock | 07e7243 | 2015-03-13 11:46:52 -0400 | [diff] [blame] | 48 | /** 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 Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 52 | public VolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent, |
John Spurlock | 07e7243 | 2015-03-13 11:46:52 -0400 | [diff] [blame] | 53 | boolean doNotDisturbWhenSilent, int vibrateToSilentDebounce) { |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 54 | this.volumeDownToEnterSilent = volumeDownToEnterSilent; |
| 55 | this.volumeUpToExitSilent = volumeUpToExitSilent; |
| 56 | this.doNotDisturbWhenSilent = doNotDisturbWhenSilent; |
John Spurlock | 07e7243 | 2015-03-13 11:46:52 -0400 | [diff] [blame] | 57 | this.vibrateToSilentDebounce = vibrateToSilentDebounce; |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public String toString() { |
| 62 | return "VolumePolicy[volumeDownToEnterSilent=" + volumeDownToEnterSilent |
| 63 | + ",volumeUpToExitSilent=" + volumeUpToExitSilent |
John Spurlock | 07e7243 | 2015-03-13 11:46:52 -0400 | [diff] [blame] | 64 | + ",doNotDisturbWhenSilent=" + doNotDisturbWhenSilent |
| 65 | + ",vibrateToSilentDebounce=" + vibrateToSilentDebounce + "]"; |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
John Spurlock | b02c744 | 2015-04-14 09:32:25 -0400 | [diff] [blame] | 69 | 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 Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 86 | 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 Spurlock | 07e7243 | 2015-03-13 11:46:52 -0400 | [diff] [blame] | 95 | dest.writeInt(vibrateToSilentDebounce); |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 96 | } |
| 97 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 98 | public static final @android.annotation.NonNull Parcelable.Creator<VolumePolicy> CREATOR |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 99 | = new Parcelable.Creator<VolumePolicy>() { |
| 100 | @Override |
| 101 | public VolumePolicy createFromParcel(Parcel p) { |
John Spurlock | 07e7243 | 2015-03-13 11:46:52 -0400 | [diff] [blame] | 102 | return new VolumePolicy(p.readInt() != 0, |
| 103 | p.readInt() != 0, |
| 104 | p.readInt() != 0, |
| 105 | p.readInt()); |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public VolumePolicy[] newArray(int size) { |
| 110 | return new VolumePolicy[size]; |
| 111 | } |
| 112 | }; |
| 113 | } |