Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 07e72432 authored by John Spurlock's avatar John Spurlock
Browse files

VolumePolicy: Debounce adjustments from vibrate->silent.

Disallows volume adjustments (lower) from vibrate to silent
until a small period of time after an adjustment from normal
to vibrate.

This provides for enough time for the user to see the state change
to vibrate and feel the associated haptic feedback before yet
another state change to silent.

Bug: 19260237
Change-Id: I5843a1c144d56146a83db194f352832c8d85159d
parent d5a62227
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -21,24 +21,35 @@ import android.os.Parcelable;

/** @hide */
public final class VolumePolicy implements Parcelable {
    public static final VolumePolicy DEFAULT = new VolumePolicy(false, false, true);
    public static final VolumePolicy DEFAULT = new VolumePolicy(false, false, true, 400);

    /** Allow volume adjustments lower from vibrate to enter ringer mode = silent */
    public final boolean volumeDownToEnterSilent;

    /** Allow volume adjustments higher to exit ringer mode = silent */
    public final boolean volumeUpToExitSilent;

    /** Automatically enter do not disturb when ringer mode = silent */
    public final boolean doNotDisturbWhenSilent;

    /** Only allow volume adjustment from vibrate to silent after this
        number of milliseconds since an adjustment from normal to vibrate. */
    public final int vibrateToSilentDebounce;

    public VolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent,
            boolean doNotDisturbWhenSilent) {
            boolean doNotDisturbWhenSilent, int vibrateToSilentDebounce) {
        this.volumeDownToEnterSilent = volumeDownToEnterSilent;
        this.volumeUpToExitSilent = volumeUpToExitSilent;
        this.doNotDisturbWhenSilent = doNotDisturbWhenSilent;
        this.vibrateToSilentDebounce = vibrateToSilentDebounce;
    }

    @Override
    public String toString() {
        return "VolumePolicy[volumeDownToEnterSilent=" + volumeDownToEnterSilent
                + ",volumeUpToExitSilent=" + volumeUpToExitSilent
                + ",doNotDisturbWhenSilent=" + doNotDisturbWhenSilent + "]";
                + ",doNotDisturbWhenSilent=" + doNotDisturbWhenSilent
                + ",vibrateToSilentDebounce=" + vibrateToSilentDebounce + "]";
    }

    @Override
@@ -51,13 +62,17 @@ public final class VolumePolicy implements Parcelable {
        dest.writeInt(volumeDownToEnterSilent ? 1 : 0);
        dest.writeInt(volumeUpToExitSilent ? 1 : 0);
        dest.writeInt(doNotDisturbWhenSilent ? 1 : 0);
        dest.writeInt(vibrateToSilentDebounce);
    }

    public static final Parcelable.Creator<VolumePolicy> CREATOR
            = new Parcelable.Creator<VolumePolicy>() {
        @Override
        public VolumePolicy createFromParcel(Parcel p) {
            return new VolumePolicy(p.readInt() != 0, p.readInt() != 0, p.readInt() != 0);
            return new VolumePolicy(p.readInt() != 0,
                    p.readInt() != 0,
                    p.readInt() != 0,
                    p.readInt());
        }

        @Override
+7 −4
Original line number Diff line number Diff line
@@ -140,9 +140,6 @@ public class AudioService extends IAudioService.Stub {
    /** Debug volumes */
    protected static final boolean DEBUG_VOL = Log.isLoggable(TAG + ".VOL", Log.DEBUG);

    /** debug calls to media session apis */
    private static final boolean DEBUG_SESSIONS = Log.isLoggable(TAG + ".SESSIONS", Log.DEBUG);

    /** debug calls to devices APIs */
    protected static final boolean DEBUG_DEVICES = Log.isLoggable(TAG + ".DEVICES", Log.DEBUG);

@@ -544,6 +541,7 @@ public class AudioService extends IAudioService.Stub {

    private AudioManagerInternal.RingerModeDelegate mRingerModeDelegate;
    private VolumePolicy mVolumePolicy = VolumePolicy.DEFAULT;
    private long mLoweredFromNormalToVibrateTime;

    // Intent "extra" data keys.
    public static final String CONNECT_INTENT_KEY_PORT_NAME = "portName";
@@ -2975,6 +2973,7 @@ public class AudioService extends IAudioService.Stub {
                    //   (step <= oldIndex < 2 * step) is equivalent to: (old UI index == 1)
                    if (step <= oldIndex && oldIndex < 2 * step) {
                        ringerMode = RINGER_MODE_VIBRATE;
                        mLoweredFromNormalToVibrateTime = SystemClock.uptimeMillis();
                    }
                } else {
                    // (oldIndex < step) is equivalent to (old UI index == 0)
@@ -3007,7 +3006,11 @@ public class AudioService extends IAudioService.Stub {
                    ringerMode = RINGER_MODE_NORMAL;
                } else if (mPrevVolDirection != AudioManager.ADJUST_LOWER) {
                    if (mVolumePolicy.volumeDownToEnterSilent) {
                        final long diff = SystemClock.uptimeMillis()
                                - mLoweredFromNormalToVibrateTime;
                        if (diff > mVolumePolicy.vibrateToSilentDebounce) {
                            ringerMode = RINGER_MODE_SILENT;
                        }
                    } else {
                        result |= AudioManager.FLAG_SHOW_VIBRATE_HINT;
                    }