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

Commit 48cb582e authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Enable sink absolute volume based on flag" into main am: 6aab16a0

parents ec338dca 6aab16a0
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -750,7 +750,11 @@ public class AvrcpControllerService extends ProfileService {

    protected AvrcpControllerStateMachine getOrCreateStateMachine(BluetoothDevice device) {
        AvrcpControllerStateMachine newStateMachine =
                new AvrcpControllerStateMachine(device, this, mNativeInterface);
                new AvrcpControllerStateMachine(
                        device,
                        this,
                        mNativeInterface,
                        Utils.isAutomotive(getApplicationContext()));
        AvrcpControllerStateMachine existingStateMachine =
                mDeviceStateMap.putIfAbsent(device, newStateMachine);
        // Given null is not a valid value in our map, ConcurrentHashMap will return null if the
+12 −4
Original line number Diff line number Diff line
@@ -147,7 +147,8 @@ class AvrcpControllerStateMachine extends StateMachine {
    AvrcpControllerStateMachine(
            BluetoothDevice device,
            AvrcpControllerService service,
            AvrcpControllerNativeInterface nativeInterface) {
            AvrcpControllerNativeInterface nativeInterface,
            boolean isControllerAbsoluteVolumeEnabled) {
        super(TAG);
        mDevice = device;
        mDeviceAddress = Utils.getByteAddress(mDevice);
@@ -184,7 +185,7 @@ class AvrcpControllerStateMachine extends StateMachine {
        mGetFolderList = new GetFolderList();
        addState(mGetFolderList, mConnected);
        mAudioManager = service.getSystemService(AudioManager.class);
        mIsVolumeFixed = mAudioManager.isVolumeFixed();
        mIsVolumeFixed = mAudioManager.isVolumeFixed() || isControllerAbsoluteVolumeEnabled;

        setInitialState(mDisconnected);

@@ -1171,8 +1172,15 @@ class AvrcpControllerStateMachine extends StateMachine {
        int maxLocalVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        int curLocalVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        int reqLocalVolume = (maxLocalVolume * absVol) / ABS_VOL_BASE;
        debug("setAbsVolme: absVol = " + absVol + ", reqLocal = " + reqLocalVolume
                + ", curLocal = " + curLocalVolume + ", maxLocal = " + maxLocalVolume);
        debug(
                "setAbsVolume: absVol = "
                        + absVol
                        + ", reqLocal = "
                        + reqLocalVolume
                        + ", curLocal = "
                        + curLocalVolume
                        + ", maxLocal = "
                        + maxLocalVolume);

        /*
         * In some cases change in percentage is not sufficient enough to warrant
+51 −1
Original line number Diff line number Diff line
@@ -152,7 +152,8 @@ public class AvrcpControllerStateMachineTest {
     */
    private AvrcpControllerStateMachine makeStateMachine(BluetoothDevice device) {
        AvrcpControllerStateMachine sm =
                new AvrcpControllerStateMachine(device, mAvrcpControllerService, mNativeInterface);
                new AvrcpControllerStateMachine(
                        device, mAvrcpControllerService, mNativeInterface, false);
        sm.start();
        return sm;
    }
@@ -1119,6 +1120,55 @@ public class AvrcpControllerStateMachineTest {
                .sendRegisterAbsVolRsp(any(), anyByte(), eq(127), eq((int) label));
    }

    /** Test that set absolute volume is working */
    @Test
    public void testSetAbsoluteVolume_volumeIsFixed_setsAbsVolumeBase() {
        byte label = 42;
        setUpConnectedState(true, true);
        mAvrcpStateMachine.sendMessage(
                AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD, 20, label);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendAbsVolRsp(any(), eq(127), eq((int) label));
    }

    /** Test that set absolute volume is working */
    @Test
    public void testSetAbsoluteVolume_volumeIsNotFixed_setsAbsVolumeBase() {
        doReturn(false).when(mAudioManager).isVolumeFixed();
        mAvrcpStateMachine =
                new AvrcpControllerStateMachine(
                        mTestDevice, mAvrcpControllerService, mNativeInterface, false);
        mAvrcpStateMachine.start();
        byte label = 42;
        setUpConnectedState(true, true);
        doReturn(100).when(mAudioManager).getStreamMaxVolume(eq(AudioManager.STREAM_MUSIC));
        doReturn(25).when(mAudioManager).getStreamVolume(eq(AudioManager.STREAM_MUSIC));
        mAvrcpStateMachine.sendMessage(
                AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD, 20, label);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendAbsVolRsp(any(), eq(20), eq((int) label));
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .setStreamVolume(
                        eq(AudioManager.STREAM_MUSIC), eq(15), eq(AudioManager.FLAG_SHOW_UI));
    }

    /** Test that set absolute volume is working */
    @Test
    public void
            testSetAbsoluteVolume_volumeIsNotFixedSinkAbsoluteVolumeEnabled_setsAbsVolumeBase() {
        doReturn(false).when(mAudioManager).isVolumeFixed();
        mAvrcpStateMachine =
                new AvrcpControllerStateMachine(
                        mTestDevice, mAvrcpControllerService, mNativeInterface, true);
        mAvrcpStateMachine.start();
        byte label = 42;
        setUpConnectedState(true, true);
        mAvrcpStateMachine.sendMessage(
                AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD, 20, label);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendAbsVolRsp(any(), eq(127), eq((int) label));
    }

    /**
     * Test playback does not request focus when another app is playing music.
     */