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

Commit 1bae9506 authored by Pawit Pornkitprasan's avatar Pawit Pornkitprasan Committed by Michael Bestas
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 4969f0d0
Loading
Loading
Loading
Loading
+31 −4
Original line number Diff line number Diff line
@@ -131,6 +131,8 @@ import com.android.server.pm.UserManagerService;

import org.xmlpull.v1.XmlPullParserException;

import lineageos.providers.LineageSettings;

import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
@@ -592,6 +594,7 @@ public class AudioService extends IAudioService.Stub
    private AudioManagerInternal.RingerModeDelegate mRingerModeDelegate;
    private VolumePolicy mVolumePolicy = VolumePolicy.DEFAULT;
    private long mLoweredFromNormalToVibrateTime;
    private boolean mVolumeKeysControlRingStream;

    // Array of Uids of valid accessibility services to check if caller is one of them
    private int[] mAccessibilityServiceUids;
@@ -1261,6 +1264,10 @@ public class AudioService extends IAudioService.Stub
            updateRingerModeAffectedStreams();
            readDockAudioSettings(cr);
            sendEncodedSurroundMode(cr, "readPersistedSettings");

            mVolumeKeysControlRingStream = LineageSettings.System.getIntForUser(mContentResolver,
                    LineageSettings.System.VOLUME_KEYS_CONTROL_RING_STREAM, 1,
                    UserHandle.USER_CURRENT) == 1;
        }

        mMuteAffectedStreams = System.getIntForUser(cr,
@@ -3911,9 +3918,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)
@@ -3942,9 +3955,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;
@@ -5117,6 +5137,9 @@ public class AudioService extends IAudioService.Stub
                    Settings.Global.ENCODED_SURROUND_OUTPUT_AUTO);
            mContentResolver.registerContentObserver(Settings.Global.getUriFor(
                    Settings.Global.ENCODED_SURROUND_OUTPUT), false, this);

            mContentResolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.VOLUME_KEYS_CONTROL_RING_STREAM), false, this);
        }

        @Override
@@ -5137,6 +5160,10 @@ public class AudioService extends IAudioService.Stub
                readDockAudioSettings(mContentResolver);
                updateMasterMono(mContentResolver);
                updateEncodedSurroundOutput();

                mVolumeKeysControlRingStream = LineageSettings.System.getIntForUser(mContentResolver,
                        LineageSettings.System.VOLUME_KEYS_CONTROL_RING_STREAM, 1,
                        UserHandle.USER_CURRENT) == 1;
            }
        }