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

Commit 2677bba3 authored by Eric Shih's avatar Eric Shih
Browse files

Fix not fallback to LE Audio when HFP removed active device

If the device connects to an LE audio device and HFP device, when the HFP
active device is set to null, the ActvieDeviceManager should try to
fallback to the LE Audio device.

Bug: 359743806
Test: atest BluetoothInstrumentationTests
Flag: Exempt, trivial and obvious fix.
Change-Id: I7e42f9788ee53914fd010b09b745ae37c4921db5
parent c1bc65e3
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -688,6 +688,14 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                    if (device != null) {
                        // remove LE audio active device when it is not null, and not dual mode
                        setLeAudioActiveDevice(null, true);
                    } else {
                        Log.d(
                                TAG,
                                "HFP active device is null. Try to fallback to le audio active"
                                        + " device");
                        synchronized (mLock) {
                            setFallbackDeviceActiveLocked(device);
                        }
                    }
                }
            }
@@ -782,6 +790,13 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                mLeHearingAidActiveDevice = device;
            }

            if (device == null && !Utils.isDualModeAudioEnabled()) {
                Log.d(TAG, "LE audio active device is null. Try to fallback to hfp active device.");
                synchronized (mLock) {
                    setFallbackDeviceActiveLocked(device);
                }
            }

            mLeAudioActiveDevice = device;
        }
    }
+18 −0
Original line number Diff line number Diff line
@@ -377,6 +377,24 @@ public class ActiveDeviceManagerTest {
        verify(mHeadsetService).setActiveDevice(mHeadsetDevice);
    }

    @Test
    public void headsetRemoveActive_fallbackToLeAudio() {
        when(mHeadsetService.getFallbackDevice()).thenReturn(mHeadsetDevice);

        leAudioConnected(mLeAudioDevice);
        mTestLooper.dispatchAll();
        verify(mLeAudioService, times(1)).setActiveDevice(mLeAudioDevice);

        headsetConnected(mHeadsetDevice, false);
        mTestLooper.dispatchAll();
        verify(mHeadsetService).setActiveDevice(mHeadsetDevice);

        // HFP activce device to null. Expect to fallback to LeAudio.
        headsetActiveDeviceChanged(null);
        mTestLooper.dispatchAll();
        verify(mLeAudioService, times(2)).setActiveDevice(mLeAudioDevice);
    }

    @Test
    public void a2dpConnectedButHeadsetNotConnected_setA2dpActive() {
        when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_IN_CALL);