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

Commit c696a53d authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Bring back the old-style Ring/Vibrate/Silent states when using volume keys.

In order to completely mute the ringer (no vibrate), introduce an extra
state beyond mute, which mutes the vibrator as well, if it was enabled.

Bug: 5530217

Change-Id: Ib1f299ee6bbca56c1aa7e1100662591362d08307
parent fe9a2a54
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -352,6 +352,10 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        sc.seekbarView.setProgress(mAudioManager.getLastAudibleStreamVolume(sc.streamType));
        final boolean muted = isMuted(sc.streamType);
        sc.icon.setImageResource(muted ? sc.iconMuteRes : sc.iconRes);
        if (sc.streamType == AudioManager.STREAM_RING && muted
                && mAudioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)) {
            sc.icon.setImageResource(R.drawable.ic_audio_ring_notif_vibrate);
        }
        sc.seekbarView.setEnabled(!muted);
    }

@@ -695,8 +699,14 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
            expand();
        } else if (v.getTag() instanceof StreamControl) {
            StreamControl sc = (StreamControl) v.getTag();
            mAudioManager.setRingerMode(mAudioManager.isSilentMode()
                    ? AudioManager.RINGER_MODE_NORMAL : AudioManager.RINGER_MODE_SILENT);
            boolean vibeInSilent = Settings.System.getInt(mContext.getContentResolver(),
                    System.VIBRATE_IN_SILENT, 1) == 1;
            int newMode = mAudioManager.isSilentMode()
                    ? AudioManager.RINGER_MODE_NORMAL
                    : (vibeInSilent
                            ? AudioManager.RINGER_MODE_VIBRATE 
                            : AudioManager.RINGER_MODE_SILENT);
            mAudioManager.setRingerMode(newMode);
            // Expand the dialog if it hasn't been expanded yet.
            if (mShowCombinedVolumes && !isExpanded()) expand();
        }
+1.28 KiB
Loading image diff...
+905 B
Loading image diff...
+1.8 KiB
Loading image diff...
+22 −8
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package android.media;

import static android.media.AudioManager.RINGER_MODE_NORMAL;
import static android.media.AudioManager.RINGER_MODE_SILENT;
import static android.media.AudioManager.RINGER_MODE_VIBRATE;

import android.app.ActivityManagerNative;
import android.app.KeyguardManager;
import android.app.PendingIntent;
@@ -528,8 +532,8 @@ public class AudioService extends IAudioService.Stub {
             (!mVoiceCapable && streamType != AudioSystem.STREAM_VOICE_CALL &&
               streamType != AudioSystem.STREAM_BLUETOOTH_SCO) ||
                (mVoiceCapable && streamTypeAlias == AudioSystem.STREAM_RING)) {
            //  do not vibrate if already in silent mode
            if (mRingerMode != AudioManager.RINGER_MODE_NORMAL) {
            // do not vibrate if already in vibrate mode
            if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
                flags &= ~AudioManager.FLAG_VIBRATE;
            }
            // Check if the ringer mode changes with this volume adjustment. If
@@ -1621,26 +1625,36 @@ public class AudioService extends IAudioService.Stub {
        boolean adjustVolumeIndex = true;
        int newRingerMode = mRingerMode;
        int uiIndex = (oldIndex + 5) / 10;
        boolean vibeInSilent = System.getInt(mContentResolver, System.VIBRATE_IN_SILENT, 1) == 1;

        if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
        if (mRingerMode == RINGER_MODE_NORMAL) {
            if ((direction == AudioManager.ADJUST_LOWER) && (uiIndex <= 1)) {
                // enter silent mode if current index is the last audible one and not repeating a
                // volume key down
                if (mPrevVolDirection != AudioManager.ADJUST_LOWER) {
                if (vibeInSilent || mPrevVolDirection != AudioManager.ADJUST_LOWER) {
                    // "silent mode", but which one?
                    newRingerMode = System.getInt(mContentResolver, System.VIBRATE_IN_SILENT, 1) == 1
                        ? AudioManager.RINGER_MODE_VIBRATE
                        : AudioManager.RINGER_MODE_SILENT;
                    newRingerMode = vibeInSilent ? RINGER_MODE_VIBRATE : RINGER_MODE_SILENT;
                }
                if (uiIndex == 0 || (mPrevVolDirection == AudioManager.ADJUST_LOWER &&
                        mVoiceCapable && streamType == AudioSystem.STREAM_RING)) {
                    adjustVolumeIndex = false;
                }
            }
        } else if (mRingerMode == RINGER_MODE_VIBRATE) {
            if ((direction == AudioManager.ADJUST_LOWER)) {
                // Set it to silent, if it wasn't a long-press
                if (mPrevVolDirection != AudioManager.ADJUST_LOWER) {
                    newRingerMode = RINGER_MODE_SILENT;
                }
            } else if (direction == AudioManager.ADJUST_RAISE) {
                newRingerMode = RINGER_MODE_NORMAL;
            }
            adjustVolumeIndex = false;
        } else {
            if (direction == AudioManager.ADJUST_RAISE) {
                // exiting silent mode
                newRingerMode = AudioManager.RINGER_MODE_NORMAL;
                // If VIBRATE_IN_SILENT, then go into vibrate mode
                newRingerMode = vibeInSilent ? RINGER_MODE_VIBRATE : RINGER_MODE_NORMAL;
            }
            adjustVolumeIndex = false;
        }
Loading