VolumePolicy.java revision 07e72432ac4a83f428d7f9ccf1e11594c67c1993
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
17package android.media;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/** @hide */
23public final class VolumePolicy implements Parcelable {
24    public static final VolumePolicy DEFAULT = new VolumePolicy(false, false, true, 400);
25
26    /** Allow volume adjustments lower from vibrate to enter ringer mode = silent */
27    public final boolean volumeDownToEnterSilent;
28
29    /** Allow volume adjustments higher to exit ringer mode = silent */
30    public final boolean volumeUpToExitSilent;
31
32    /** Automatically enter do not disturb when ringer mode = silent */
33    public final boolean doNotDisturbWhenSilent;
34
35    /** Only allow volume adjustment from vibrate to silent after this
36        number of milliseconds since an adjustment from normal to vibrate. */
37    public final int vibrateToSilentDebounce;
38
39    public VolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent,
40            boolean doNotDisturbWhenSilent, int vibrateToSilentDebounce) {
41        this.volumeDownToEnterSilent = volumeDownToEnterSilent;
42        this.volumeUpToExitSilent = volumeUpToExitSilent;
43        this.doNotDisturbWhenSilent = doNotDisturbWhenSilent;
44        this.vibrateToSilentDebounce = vibrateToSilentDebounce;
45    }
46
47    @Override
48    public String toString() {
49        return "VolumePolicy[volumeDownToEnterSilent=" + volumeDownToEnterSilent
50                + ",volumeUpToExitSilent=" + volumeUpToExitSilent
51                + ",doNotDisturbWhenSilent=" + doNotDisturbWhenSilent
52                + ",vibrateToSilentDebounce=" + vibrateToSilentDebounce + "]";
53    }
54
55    @Override
56    public int describeContents() {
57        return 0;
58    }
59
60    @Override
61    public void writeToParcel(Parcel dest, int flags) {
62        dest.writeInt(volumeDownToEnterSilent ? 1 : 0);
63        dest.writeInt(volumeUpToExitSilent ? 1 : 0);
64        dest.writeInt(doNotDisturbWhenSilent ? 1 : 0);
65        dest.writeInt(vibrateToSilentDebounce);
66    }
67
68    public static final Parcelable.Creator<VolumePolicy> CREATOR
69            = new Parcelable.Creator<VolumePolicy>() {
70        @Override
71        public VolumePolicy createFromParcel(Parcel p) {
72            return new VolumePolicy(p.readInt() != 0,
73                    p.readInt() != 0,
74                    p.readInt() != 0,
75                    p.readInt());
76        }
77
78        @Override
79        public VolumePolicy[] newArray(int size) {
80            return new VolumePolicy[size];
81        }
82    };
83}