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

Commit 2bbe0da4 authored by Grace Jia's avatar Grace Jia
Browse files

Fix hearing aid device audio route switch issue.

Currently, audio switching from hearing aid device can't set
audio state in BluetoothRouteManager in proper disconnected state.
Which make the audio route can't switch back to hearing aid device
route since the BluetoothRouteManager don't know the audio route
is disconnected.

Bug: 229358080
Test: atest BluetoothDeviceManagerTest
Change-Id: Id3933942895d9a146e471c39bf0fe69ffe05d0ff
parent 0ade90bc
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ public class BluetoothDeviceManager {
    private BluetoothLeAudio mBluetoothLeAudioService;
    private boolean mLeAudioSetAsCommunicationDevice = false;
    private String mLeAudioDevice;
    private String mHearingAidDevice;
    private boolean mHearingAidSetAsCommunicationDevice = false;
    private BluetoothDevice mBluetoothHearingAidActiveDeviceCache;
    private BluetoothAdapter mBluetoothAdapter;
@@ -444,10 +445,17 @@ public class BluetoothDeviceManager {
    }

    public void clearHearingAidCommunicationDevice() {
        Log.i(this, "clearHearingAidCommunicationDevice: mHearingAidSetAsCommunicationDevice = "
                + mHearingAidSetAsCommunicationDevice);
        if (!mHearingAidSetAsCommunicationDevice) {
            return;
        }
        mHearingAidSetAsCommunicationDevice = false;
        if (mHearingAidDevice != null) {
            mBluetoothRouteManager.onAudioLost(mHearingAidDevice);
            mHearingAidDevice = null;
        }

        if (mAudioManager == null) {
            Log.i(this, "clearHearingAidCommunicationDevice: mAudioManager is null");
            return;
@@ -551,6 +559,7 @@ public class BluetoothDeviceManager {
            Log.w(this, " Could not set hearingAid device");
        } else {
            Log.i(this, " hearingAid device set");
            mHearingAidDevice = hearingAid.getAddress();
            mHearingAidSetAsCommunicationDevice = true;
        }
        return result;
+2 −1
Original line number Diff line number Diff line
@@ -491,7 +491,8 @@ public class BluetoothRouteManager extends StateMachine {
            SomeArgs args = (SomeArgs) msg.obj;

            Log.continueSession(((Session) args.arg1), "BRM.pM_" + msg.what);
            Log.i(LOG_TAG, "Message received: %s.", MESSAGE_CODE_TO_NAME.get(msg.what));
            Log.i(LOG_TAG, "%s received message: %s.", this,
                    MESSAGE_CODE_TO_NAME.get(msg.what));
        } else if (msg.what == RUN_RUNNABLE && msg.obj instanceof Runnable) {
            Log.i(LOG_TAG, "Running runnable for testing");
        } else {
+4 −0
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ import java.util.List;

@RunWith(JUnit4.class)
public class BluetoothDeviceManagerTest extends TelecomTestCase {
    private static final String DEVICE_ADDRESS_1 = "00:00:00:00:00:01";

    @Mock BluetoothRouteManager mRouteManager;
    @Mock BluetoothHeadset mBluetoothHeadset;
    @Mock BluetoothAdapter mAdapter;
@@ -492,6 +494,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
    @Test
    public void testClearHearingAidCommunicationDevice() {
        AudioDeviceInfo mockAudioDeviceInfo = mock(AudioDeviceInfo.class);
        when(mockAudioDeviceInfo.getAddress()).thenReturn(DEVICE_ADDRESS_1);
        when(mockAudioDeviceInfo.getType()).thenReturn(AudioDeviceInfo.TYPE_HEARING_AID);
        List<AudioDeviceInfo> devices = new ArrayList<>();
        devices.add(mockAudioDeviceInfo);
@@ -504,6 +507,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        mBluetoothDeviceManager.setHearingAidCommunicationDevice();
        when(mockAudioManager.getCommunicationDevice()).thenReturn(mSpeakerInfo);
        mBluetoothDeviceManager.clearHearingAidCommunicationDevice();
        verify(mRouteManager).onAudioLost(eq(DEVICE_ADDRESS_1));
        assertFalse(mBluetoothDeviceManager.isHearingAidSetAsCommunicationDevice());
    }