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

Commit b6ae7bea authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "Add selection of silent mode with volume control." into gingerbread

parents 51f50b5b 8717c5fe
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1556,6 +1556,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.
         */
@@ -2329,6 +2337,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
@@ -1136,6 +1136,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;

@@ -1143,19 +1147,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) {