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

Commit eb071f81 authored by Hall Liu's avatar Hall Liu
Browse files

Fix the audio-on device detection logic

Earlier change had broken the logic that we use to detect where audio
was being routed to in the BT stack. Fix that by checking to see whether
the HFP device is actually routing audio.

Fixes: 128813699
Test: manual, unit
Change-Id: I4be99c192cd5a7cc80c26339b599ece6e525cffe
parent 1fe06dda
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -694,7 +694,7 @@ public class BluetoothRouteManager extends StateMachine {
        BluetoothHeadsetProxy bluetoothHeadset = mDeviceManager.getHeadsetService();
        BluetoothHearingAid bluetoothHearingAid = mDeviceManager.getHearingAidService();

        BluetoothDevice hfpActiveDevice = null;
        BluetoothDevice hfpAudioOnDevice = null;
        BluetoothDevice hearingAidActiveDevice = null;

        if (bluetoothHeadset == null && bluetoothHearingAid == null) {
@@ -703,7 +703,12 @@ public class BluetoothRouteManager extends StateMachine {
        }

        if (bluetoothHeadset != null) {
            hfpActiveDevice = bluetoothHeadset.getActiveDevice();
            hfpAudioOnDevice = bluetoothHeadset.getActiveDevice();

            if (bluetoothHeadset.getAudioState(hfpAudioOnDevice)
                    == BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
                hfpAudioOnDevice = null;
            }
        }

        if (bluetoothHearingAid != null) {
@@ -717,13 +722,13 @@ public class BluetoothRouteManager extends StateMachine {

        // Return the active device reported by either HFP or hearing aid. If both are reporting
        // active devices, go with the most recent one as reported by the receiver.
        if (hfpActiveDevice != null) {
        if (hfpAudioOnDevice != null) {
            if (hearingAidActiveDevice != null) {
                Log.i(this, "Both HFP and hearing aid are reporting active devices. Going with"
                        + " the most recently reported active device: %s");
                return mMostRecentlyReportedActiveDevice;
            }
            return hfpActiveDevice;
            return hfpAudioOnDevice;
        }
        return hearingAidActiveDevice;
    }
+18 −0
Original line number Diff line number Diff line
@@ -112,6 +112,22 @@ public class BluetoothRouteManagerTest extends TelecomTestCase {
        sm.quitNow();
    }

    @SmallTest
    @Test
    public void testAudioOnDeviceWithScoOffActiveDevice() {
        BluetoothRouteManager sm = setupStateMachine(
                BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX, DEVICE1);
        setupConnectedDevices(new BluetoothDevice[]{DEVICE1}, null, DEVICE1, null);
        when(mHeadsetProxy.getAudioState(DEVICE1))
                .thenReturn(BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
        executeRoutingAction(sm, BluetoothRouteManager.BT_AUDIO_LOST, DEVICE1.getAddress());

        verifyConnectionAttempt(DEVICE1, 0);
        assertEquals(BluetoothRouteManager.AUDIO_OFF_STATE_NAME,
                sm.getCurrentState().getName());
        sm.quitNow();
    }

    @SmallTest
    @Test
    public void testConnectHfpRetryWhileConnectedToAnotherDevice() {
@@ -164,6 +180,8 @@ public class BluetoothRouteManagerTest extends TelecomTestCase {
        when(mDeviceManager.getConnectedDevices()).thenReturn(allDevices);
        when(mHeadsetProxy.getConnectedDevices()).thenReturn(Arrays.asList(hfpDevices));
        when(mHeadsetProxy.getActiveDevice()).thenReturn(hfpActiveDevice);
        when(mHeadsetProxy.getAudioState(hfpActiveDevice))
                .thenReturn(BluetoothHeadset.STATE_AUDIO_CONNECTED);

        when(mBluetoothHearingAid.getConnectedDevices())
                .thenReturn(Arrays.asList(hearingAidDevices));
+2 −0
Original line number Diff line number Diff line
@@ -341,6 +341,8 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase {
        when(mHeadsetProxy.getActiveDevice()).thenReturn(activeDevice);
        if (audioOnDevice != null) {
            when(mHeadsetProxy.getActiveDevice()).thenReturn(audioOnDevice);
            when(mHeadsetProxy.getAudioState(audioOnDevice))
                    .thenReturn(BluetoothHeadset.STATE_AUDIO_CONNECTED);
        }
    }