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

Commit d171b9a3 authored by Pawit Pornkitprasan's avatar Pawit Pornkitprasan Committed by Danesh M
Browse files

Option to use volume keys to control media volume anytime (2/2)

See Settings part for description

Fix forcing media stream control on tablet
There's option volume_keys_control_ring_stream (Volume keys control ringtone
volume / If on, volume keys control ringtone volume. If off, volume keys
control media volume.) in Settings which is also available on tablets but it
doesn't work on these devices (I didn't find reported issue).
As I like this option and think it may be even more wanted on media devices
such as tablets, here's a fix.

Change-Id: I2f6ebfcbb4ea6e092e4cd29c5acf5f0dbe769718
parent 46a77b33
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -3461,6 +3461,13 @@ public final class Settings {
         */
        public static final String VOICE_LAUNCH_INTENT = "voice_launch_intent";

        /**
         * Volume key controls ringtone or media sound stream
         * @hide
         */
        public static final String VOLUME_KEYS_CONTROL_RING_STREAM =
                "volume_keys_control_ring_stream";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+29 −4
Original line number Diff line number Diff line
@@ -126,6 +126,8 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;

import cyanogenmod.providers.CMSettings;

/**
 * The implementation of the volume manager service.
 * <p>
@@ -590,6 +592,7 @@ public class AudioService extends IAudioService.Stub {
    private AudioManagerInternal.RingerModeDelegate mRingerModeDelegate;
    private VolumePolicy mVolumePolicy = VolumePolicy.DEFAULT;
    private long mLoweredFromNormalToVibrateTime;
    private boolean mVolumeKeysControlRingStream;

    // Intent "extra" data keys.
    public static final String CONNECT_INTENT_KEY_PORT_NAME = "portName";
@@ -1166,6 +1169,10 @@ public class AudioService extends IAudioService.Stub {

            updateRingerModeAffectedStreams();
            readDockAudioSettings(cr);

            mVolumeKeysControlRingStream = CMSettings.System.getIntForUser(cr,
                    CMSettings.System.VOLUME_KEYS_CONTROL_RING_STREAM, 1,
                    UserHandle.USER_CURRENT) == 1;
        }

        mLinkNotificationWithVolume = Settings.Secure.getInt(cr,
@@ -3608,9 +3615,15 @@ public class AudioService extends IAudioService.Stub {
                        Log.v(TAG, "getActiveStreamType: Forcing STREAM_MUSIC stream active");
                    return AudioSystem.STREAM_MUSIC;
                } else {
                    if (mVolumeKeysControlRingStream) {
                        if (DEBUG_VOL)
                            Log.v(TAG, "getActiveStreamType: Forcing STREAM_RING b/c default");
                        return AudioSystem.STREAM_RING;
                    } else {
                        if (DEBUG_VOL)
                            Log.v(TAG, "getActiveStreamType: Forcing STREAM_MUSIC b/c default");
                        return AudioSystem.STREAM_MUSIC;
                    }
                }
            } else if (isAfMusicActiveRecently(0)) {
                if (DEBUG_VOL)
@@ -3645,9 +3658,16 @@ public class AudioService extends IAudioService.Stub {
                    if (DEBUG_VOL) Log.v(TAG, "getActiveStreamType: forcing STREAM_MUSIC");
                    return AudioSystem.STREAM_MUSIC;
                } else {
                    if (DEBUG_VOL) Log.v(TAG,
                    if (mVolumeKeysControlRingStream) {
                        if (DEBUG_VOL)
                            Log.v(TAG,
                                    "getActiveStreamType: using STREAM_NOTIFICATION as default");
                        return AudioSystem.STREAM_NOTIFICATION;
                    } else {
                        if (DEBUG_VOL)
                            Log.v(TAG, "getActiveStreamType: Forcing STREAM_MUSIC b/c default");
                        return AudioSystem.STREAM_MUSIC;
                    }
                }
            }
            break;
@@ -4726,6 +4746,8 @@ public class AudioService extends IAudioService.Stub {
                Settings.Global.DOCK_AUDIO_MEDIA_ENABLED), false, this);
            mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
                Settings.Secure.VOLUME_LINK_NOTIFICATION), false, this);
            mContentResolver.registerContentObserver(CMSettings.System.getUriFor(
                CMSettings.System.VOLUME_KEYS_CONTROL_RING_STREAM), false, this);
        }

        @Override
@@ -4752,6 +4774,9 @@ public class AudioService extends IAudioService.Stub {
                    createStreamStates();
                    updateStreamVolumeAlias(true, TAG);
                }
                mVolumeKeysControlRingStream = CMSettings.System.getIntForUser(mContentResolver,
                        CMSettings.System.VOLUME_KEYS_CONTROL_RING_STREAM, 1,
                        UserHandle.USER_CURRENT) == 1;
            }
        }
    }