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

Commit 41792644 authored by John Spurlock's avatar John Spurlock Committed by Android Git Automerger
Browse files

am bfea31fd: VolumeZen: Prevent raising ringer volume in silent mode.

* commit 'bfea31fd6dd88c94deae1122874b4e0737380d25':
  VolumeZen: Prevent raising ringer volume in silent mode.
parents c2e97779 a11b4aff
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -338,6 +338,12 @@ public class AudioManager {
     */
    public static final int FLAG_BLUETOOTH_ABS_VOLUME = 1 << 6;

    /**
     * Adjusting the volume was prevented due to silent mode, display a hint in the UI.
     * @hide
     */
    public static final int FLAG_SHOW_SILENT_HINT = 1 << 7;

    /**
     * Ringer mode that will be silent and will not vibrate. (This overrides the
     * vibrate setting.)
+26 −9
Original line number Diff line number Diff line
@@ -115,6 +115,9 @@ public class AudioService extends IAudioService.Stub {
    /** Allow volume changes to set ringer mode to silent? */
    private static final boolean VOLUME_SETS_RINGER_MODE_SILENT = false;

    /** In silent mode, are volume adjustments (raises) prevented? */
    private static final boolean PREVENT_VOLUME_ADJUSTMENT_IF_SILENT = true;

    /** How long to delay before persisting a change in volume/ringer mode. */
    private static final int PERSIST_DELAY = 500;

@@ -126,6 +129,11 @@ public class AudioService extends IAudioService.Stub {
     */
    public static final int PLAY_SOUND_DELAY = 300;

    /**
     * Only used in the result from {@link #checkForRingerModeChange(int, int, int)}
     */
    private static final int FLAG_ADJUST_VOLUME = 1;

    private final Context mContext;
    private final ContentResolver mContentResolver;
    private final AppOpsManager mAppOps;
@@ -942,7 +950,12 @@ public class AudioService extends IAudioService.Stub {
            }
            // Check if the ringer mode changes with this volume adjustment. If
            // it does, it will handle adjusting the volume, so we won't below
            adjustVolume = checkForRingerModeChange(aliasIndex, direction, step);
            final int result = checkForRingerModeChange(aliasIndex, direction, step);
            adjustVolume = (result & FLAG_ADJUST_VOLUME) != 0;
            // If suppressing a volume adjustment in silent mode, display the UI hint
            if ((result & AudioManager.FLAG_SHOW_SILENT_HINT) != 0) {
                flags |= AudioManager.FLAG_SHOW_SILENT_HINT;
            }
        }

        int oldIndex = mStreamStates[streamType].getIndex(device);
@@ -2564,8 +2577,8 @@ public class AudioService extends IAudioService.Stub {
     * adjusting volume. If so, this will set the proper ringer mode and volume
     * indices on the stream states.
     */
    private boolean checkForRingerModeChange(int oldIndex, int direction,  int step) {
        boolean adjustVolumeIndex = true;
    private int checkForRingerModeChange(int oldIndex, int direction,  int step) {
        int result = FLAG_ADJUST_VOLUME;
        int ringerMode = getRingerMode();

        switch (ringerMode) {
@@ -2604,17 +2617,21 @@ public class AudioService extends IAudioService.Stub {
            } else if (direction == AudioManager.ADJUST_RAISE) {
                ringerMode = RINGER_MODE_NORMAL;
            }
            adjustVolumeIndex = false;
            result &= ~FLAG_ADJUST_VOLUME;
            break;
        case RINGER_MODE_SILENT:
            if (direction == AudioManager.ADJUST_RAISE) {
                if (PREVENT_VOLUME_ADJUSTMENT_IF_SILENT) {
                    result |= AudioManager.FLAG_SHOW_SILENT_HINT;
                } else {
                  if (mHasVibrator) {
                      ringerMode = RINGER_MODE_VIBRATE;
                  } else {
                      ringerMode = RINGER_MODE_NORMAL;
                  }
                }
            adjustVolumeIndex = false;
            }
            result &= ~FLAG_ADJUST_VOLUME;
            break;
        default:
            Log.e(TAG, "checkForRingerModeChange() wrong ringer mode: "+ringerMode);
@@ -2625,7 +2642,7 @@ public class AudioService extends IAudioService.Stub {

        mPrevVolDirection = direction;

        return adjustVolumeIndex;
        return result;
    }

    @Override
+5 −0
Original line number Diff line number Diff line
@@ -898,6 +898,11 @@ public class VolumePanel extends Handler {
                mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
            sendMessageDelayed(obtainMessage(MSG_VIBRATE), VIBRATE_DELAY);
        }

        // Pulse the slider icon if an adjustment was suppressed due to silent mode.
        if (sc != null && (flags & AudioManager.FLAG_SHOW_SILENT_HINT) != 0) {
            pulseIcon(sc.icon);
        }
    }

    private boolean isShowing() {