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

Commit 3cc5e479 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Gerrit Code Review
Browse files

Merge "VolumeControl: Fix volume for the activated device"

parents 663ff0c1 f0e34592
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -415,7 +415,7 @@ public class LeAudioService extends ProfileService {
        sLeAudioService = instance;
    }

    private int getGroupVolume(int groupId) {
    private int getAudioDeviceGroupVolume(int groupId) {
        if (mVolumeControlService == null) {
            mVolumeControlService = mServiceFactory.getVolumeControlService();
            if (mVolumeControlService == null) {
@@ -424,7 +424,7 @@ public class LeAudioService extends ProfileService {
            }
        }

        return mVolumeControlService.getGroupVolume(groupId);
        return mVolumeControlService.getAudioDeviceGroupVolume(groupId);
    }

    public boolean connect(BluetoothDevice device) {
@@ -926,7 +926,7 @@ public class LeAudioService extends ProfileService {
            }
            int volume = IBluetoothVolumeControl.VOLUME_CONTROL_UNKNOWN_VOLUME;
            if (mActiveAudioOutDevice != null) {
                volume = getGroupVolume(groupId);
                volume = getAudioDeviceGroupVolume(groupId);
            }

            mAudioManager.handleBluetoothActiveDeviceChanged(mActiveAudioOutDevice,
+14 −0
Original line number Diff line number Diff line
@@ -586,6 +586,11 @@ public class VolumeControlService extends ProfileService {
     * {@hide}
     */
    public void setGroupVolume(int groupId, int volume) {
        if (volume < 0) {
            Log.w(TAG, "Tried to set invalid volume " + volume + ". Ignored.");
            return;
        }

        mGroupVolumeCache.put(groupId, volume);
        mVolumeControlNativeInterface.setGroupVolume(groupId, volume);
    }
@@ -683,6 +688,15 @@ public class VolumeControlService extends ProfileService {
        }
    }

    /**
     * {@hide}
     */
    public int getAudioDeviceGroupVolume(int groupId) {
        int volume = getGroupVolume(groupId);
        if (volume == IBluetoothVolumeControl.VOLUME_CONTROL_UNKNOWN_VOLUME) return -1;
        return getDeviceVolume(getBluetoothContextualVolumeStream(), volume);
    }

    int getDeviceVolume(int streamType, int bleVolume) {
        int deviceMaxVolume = mAudioManager.getStreamMaxVolume(streamType);

+2 −2
Original line number Diff line number Diff line
@@ -1431,7 +1431,7 @@ public class LeAudioServiceTest {
        //Add location support.
        injectAudioConfChanged(groupId, availableContexts);

        doReturn(-1).when(mVolumeControlService).getGroupVolume(groupId);
        doReturn(-1).when(mVolumeControlService).getAudioDeviceGroupVolume(groupId);
        //Set group and device as active.
        injectGroupStatusChange(groupId, LeAudioStackEvent.GROUP_STATUS_ACTIVE);

@@ -1448,7 +1448,7 @@ public class LeAudioServiceTest {
        verify(mAudioManager, times(1)).handleBluetoothActiveDeviceChanged(eq(null), any(),
                        any(BluetoothProfileConnectionInfo.class));

        doReturn(100).when(mVolumeControlService).getGroupVolume(groupId);
        doReturn(100).when(mVolumeControlService).getAudioDeviceGroupVolume(groupId);

        //Set back to active and check if last volume is restored.
        injectGroupStatusChange(groupId, LeAudioStackEvent.GROUP_STATUS_ACTIVE);