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

Commit e227417c authored by Eran's avatar Eran Committed by Steve Kondik
Browse files

Add selection of silent mode with volume control.

Allows volume buttons to control "silent <-> vibrate <-> volume",
when the appropriate setting is enabled.

Patch by Alex Hofbauer.
Original patch and small fix by Eran Mizrahi.

Change-Id: Iaec151e24c07129406ab7ce003cdccd409dffed7
parent 4cecacb0
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1525,6 +1525,14 @@ public final class Settings {
         */
        public static final String VIBRATE_IN_SILENT = "vibrate_in_silent";

        /**
         * Whether volume button should also set complete silence after
         * vibration.
         *
         * @hide
         */
        public static final String VOLUME_CONTROL_SILENT = "volume_contol_silent";

        /**
         * The mapping of stream type (integer) to its setting.
         */
@@ -2352,6 +2360,7 @@ public final class Settings {
            VOLUME_NOTIFICATION + APPEND_FOR_LAST_AUDIBLE,
            VOLUME_BLUETOOTH_SCO + APPEND_FOR_LAST_AUDIBLE,
            VIBRATE_IN_SILENT,
            VOLUME_CONTROL_SILENT,
            TEXT_AUTO_REPLACE,
            TEXT_AUTO_CAPS,
            TEXT_AUTO_PUNCTUATE,
+27 −7
Original line number Diff line number Diff line
@@ -1129,6 +1129,10 @@ public class AudioService extends IAudioService.Stub {
     * indices on the stream states.
     */
    private boolean checkForRingerModeChange(int oldIndex, int direction) {
        boolean mVolumeControlSilent = Settings.System.getInt(mContentResolver,
                Settings.System.VOLUME_CONTROL_SILENT, 0) != 0;
        boolean vibrateInSilent = System.getInt(mContentResolver,
                System.VIBRATE_IN_SILENT, 1) == 1;
        boolean adjustVolumeIndex = true;
        int newRingerMode = mRingerMode;

@@ -1136,19 +1140,35 @@ public class AudioService extends IAudioService.Stub {
            // audible mode, at the bottom of the scale
            if (direction == AudioManager.ADJUST_LOWER
                    && (oldIndex + 5) / 10 == 1) {
                // "silent mode", but which one?
                newRingerMode = System.getInt(mContentResolver, System.VIBRATE_IN_SILENT, 1) == 1
                    ? AudioManager.RINGER_MODE_VIBRATE
                    : AudioManager.RINGER_MODE_SILENT;
            }
                if (vibrateInSilent) {
                    newRingerMode = AudioManager.RINGER_MODE_VIBRATE;
                } else {
                    newRingerMode = AudioManager.RINGER_MODE_SILENT;
                }
            }
        } else if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
            if (direction == AudioManager.ADJUST_RAISE) {
                // exiting silent mode
                newRingerMode = AudioManager.RINGER_MODE_NORMAL;
            } else if (direction == AudioManager.ADJUST_LOWER
                    && mVolumeControlSilent) {
                newRingerMode = AudioManager.RINGER_MODE_SILENT;
            } else {
                // prevent last audible index to reach 0
                adjustVolumeIndex = false;
            }
        } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
            if (direction == AudioManager.ADJUST_RAISE) {
                if (vibrateInSilent) {
                    newRingerMode = AudioManager.RINGER_MODE_VIBRATE;
                } else {
                    newRingerMode = AudioManager.RINGER_MODE_NORMAL;
                }
            } else {
                adjustVolumeIndex = false;
            }
        } else {
            // is this fallback needed?
            newRingerMode = AudioManager.RINGER_MODE_NORMAL;
        }

        if (newRingerMode != mRingerMode) {