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

Commit cfc4060f authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Use 1/2 Device max volume when pairing with a new remote device

Instead of using the current system volume which will most often be the
speaker volume when connecting to a device we don't have a remembered
volume for, use 1/2 the device max volume instead.

Bug: 109995379
Test: Pair new device and see volume was 1/2 max
Change-Id: Ib3a3963a17faf2fab1b03d47f471780446d2269d
parent 91e37de0
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -34,11 +34,12 @@ class AvrcpVolumeManager {
    public static final boolean DEBUG = true;

    // All volumes are stored at system volume values, not AVRCP values
    public static final String VOLUME_MAP = "bluetooth_volume_map";
    public static final String VOLUME_BLACKLIST = "absolute_volume_blacklist";
    public static final int AVRCP_MAX_VOL = 127;
    public static int sDeviceMaxVolume = 0;
    public static final int STREAM_MUSIC = AudioManager.STREAM_MUSIC;
    private static final String VOLUME_MAP = "bluetooth_volume_map";
    private static final String VOLUME_BLACKLIST = "absolute_volume_blacklist";
    private static final int AVRCP_MAX_VOL = 127;
    private static final int STREAM_MUSIC = AudioManager.STREAM_MUSIC;
    private static int sDeviceMaxVolume = 0;
    private static int sNewDeviceVolume = 0;

    Context mContext;
    AudioManager mAudioManager;
@@ -70,10 +71,9 @@ class AvrcpVolumeManager {
        mAudioManager.avrcpSupportsAbsoluteVolume(device.getAddress(), mDeviceMap.get(device));

        // Get the current system volume and try to get the preference volume
        int currVolume = mAudioManager.getStreamVolume(STREAM_MUSIC);
        int savedVolume = getVolume(device, currVolume);
        int savedVolume = getVolume(device, sNewDeviceVolume);

        d("switchVolumeDevice: currVolume=" + currVolume + " savedVolume=" + savedVolume);
        d("switchVolumeDevice: savedVolume=" + savedVolume);

        // If absolute volume for the device is supported, set the volume for the device
        if (mDeviceMap.get(device)) {
@@ -89,6 +89,7 @@ class AvrcpVolumeManager {
        mAudioManager = audioManager;
        mNativeInterface = nativeInterface;
        sDeviceMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        sNewDeviceVolume = sDeviceMaxVolume / 2;

        // Load the stored volume preferences into a hash map since shared preferences are slow
        // to poll and update. If the device has been unbonded since last start remove it from