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, false, 400);
     27 
     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 
     39     /** Allow volume adjustments lower from vibrate to enter ringer mode = silent */
     40     public final boolean volumeDownToEnterSilent;
     41 
     42     /** Allow volume adjustments higher to exit ringer mode = silent */
     43     public final boolean volumeUpToExitSilent;
     44 
     45     /** Automatically enter do not disturb when ringer mode = silent */
     46     public final boolean doNotDisturbWhenSilent;
     47 
     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 
     52     public VolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent,
     53             boolean doNotDisturbWhenSilent, int vibrateToSilentDebounce) {
     54         this.volumeDownToEnterSilent = volumeDownToEnterSilent;
     55         this.volumeUpToExitSilent = volumeUpToExitSilent;
     56         this.doNotDisturbWhenSilent = doNotDisturbWhenSilent;
     57         this.vibrateToSilentDebounce = vibrateToSilentDebounce;
     58     }
     59 
     60     @Override
     61     public String toString() {
     62         return "VolumePolicy[volumeDownToEnterSilent=" + volumeDownToEnterSilent
     63                 + ",volumeUpToExitSilent=" + volumeUpToExitSilent
     64                 + ",doNotDisturbWhenSilent=" + doNotDisturbWhenSilent
     65                 + ",vibrateToSilentDebounce=" + vibrateToSilentDebounce + "]";
     66     }
     67 
     68     @Override
     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
     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);
     95         dest.writeInt(vibrateToSilentDebounce);
     96     }
     97 
     98     public static final Parcelable.Creator<VolumePolicy> CREATOR
     99             = new Parcelable.Creator<VolumePolicy>() {
    100         @Override
    101         public VolumePolicy createFromParcel(Parcel p) {
    102             return new VolumePolicy(p.readInt() != 0,
    103                     p.readInt() != 0,
    104                     p.readInt() != 0,
    105                     p.readInt());
    106         }
    107 
    108         @Override
    109         public VolumePolicy[] newArray(int size) {
    110             return new VolumePolicy[size];
    111         }
    112     };
    113 }