Home | History | Annotate | Download | only in media
      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 
     22 import java.util.Objects;
     23 
     24 /** @hide */
     25 public final class VolumePolicy implements Parcelable {
     26     public static final VolumePolicy DEFAULT = new VolumePolicy(false, false, true, 400);
     27 
     28     /** Allow volume adjustments lower from vibrate to enter ringer mode = silent */
     29     public final boolean volumeDownToEnterSilent;
     30 
     31     /** Allow volume adjustments higher to exit ringer mode = silent */
     32     public final boolean volumeUpToExitSilent;
     33 
     34     /** Automatically enter do not disturb when ringer mode = silent */
     35     public final boolean doNotDisturbWhenSilent;
     36 
     37     /** Only allow volume adjustment from vibrate to silent after this
     38         number of milliseconds since an adjustment from normal to vibrate. */
     39     public final int vibrateToSilentDebounce;
     40 
     41     public VolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent,
     42             boolean doNotDisturbWhenSilent, int vibrateToSilentDebounce) {
     43         this.volumeDownToEnterSilent = volumeDownToEnterSilent;
     44         this.volumeUpToExitSilent = volumeUpToExitSilent;
     45         this.doNotDisturbWhenSilent = doNotDisturbWhenSilent;
     46         this.vibrateToSilentDebounce = vibrateToSilentDebounce;
     47     }
     48 
     49     @Override
     50     public String toString() {
     51         return "VolumePolicy[volumeDownToEnterSilent=" + volumeDownToEnterSilent
     52                 + ",volumeUpToExitSilent=" + volumeUpToExitSilent
     53                 + ",doNotDisturbWhenSilent=" + doNotDisturbWhenSilent
     54                 + ",vibrateToSilentDebounce=" + vibrateToSilentDebounce + "]";
     55     }
     56 
     57     @Override
     58     public int hashCode() {
     59         return Objects.hash(volumeDownToEnterSilent, volumeUpToExitSilent, doNotDisturbWhenSilent,
     60                 vibrateToSilentDebounce);
     61     }
     62 
     63     @Override
     64     public boolean equals(Object o) {
     65         if (!(o instanceof VolumePolicy)) return false;
     66         if (o == this) return true;
     67         final VolumePolicy other = (VolumePolicy) o;
     68         return other.volumeDownToEnterSilent == volumeDownToEnterSilent
     69                 && other.volumeUpToExitSilent == volumeUpToExitSilent
     70                 && other.doNotDisturbWhenSilent == doNotDisturbWhenSilent
     71                 && other.vibrateToSilentDebounce == vibrateToSilentDebounce;
     72     }
     73 
     74     @Override
     75     public int describeContents() {
     76         return 0;
     77     }
     78 
     79     @Override
     80     public void writeToParcel(Parcel dest, int flags) {
     81         dest.writeInt(volumeDownToEnterSilent ? 1 : 0);
     82         dest.writeInt(volumeUpToExitSilent ? 1 : 0);
     83         dest.writeInt(doNotDisturbWhenSilent ? 1 : 0);
     84         dest.writeInt(vibrateToSilentDebounce);
     85     }
     86 
     87     public static final Parcelable.Creator<VolumePolicy> CREATOR
     88             = new Parcelable.Creator<VolumePolicy>() {
     89         @Override
     90         public VolumePolicy createFromParcel(Parcel p) {
     91             return new VolumePolicy(p.readInt() != 0,
     92                     p.readInt() != 0,
     93                     p.readInt() != 0,
     94                     p.readInt());
     95         }
     96 
     97         @Override
     98         public VolumePolicy[] newArray(int size) {
     99             return new VolumePolicy[size];
    100         }
    101     };
    102 }