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

Commit f6d533be authored by Thomas Girardier's avatar Thomas Girardier Committed by Automerger Merge Worker
Browse files

Merge "ADM: fix active device fallback on handleHfpActiveDeviceChanged" into...

Merge "ADM: fix active device fallback on handleHfpActiveDeviceChanged" into main am: d4f6baad am: 36ed2dbe

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/3392579



Change-Id: Icf04fc47c075deef358000b7d7f694f1174e9dcd
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents c558b3e2 36ed2dbe
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -709,7 +709,6 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                            + device
                            + ", mHfpActiveDevice="
                            + mHfpActiveDevice);

            if (!Objects.equals(mHfpActiveDevice, device)) {
                if (device != null) {
                    setHearingAidActiveDevice(null, true);
@@ -717,7 +716,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac

                updateLeAudioActiveDeviceIfDualMode(mHfpActiveDevice, device);

                if (!Utils.isDualModeAudioEnabled() || device == null) {
                if ((!Utils.isDualModeAudioEnabled() && device == null)) {
                    Log.d(TAG, "HFP active device is null. Try to fallback to the active device.");
                    synchronized (mLock) {
                        setFallbackDeviceActiveLocked(null);
+37 −0
Original line number Diff line number Diff line
@@ -455,6 +455,43 @@ public class ActiveDeviceManagerTest {
        verify(mA2dpService, never()).setActiveDevice(mA2dpHeadsetDevice);
    }

    @Test
    public void switchActiveDeviceFromLeToHfp_noFallbackToLe() {
        // Turn off the dual mode audio flag
        Utils.setDualModeAudioStateForTesting(false);

        // Connect A2DP + HFP device, set it not active
        a2dpConnected(mA2dpHeadsetDevice, true);
        headsetConnected(mA2dpHeadsetDevice, true);
        a2dpActiveDeviceChanged(null);
        headsetActiveDeviceChanged(null);
        mTestLooper.dispatchAll();

        Mockito.clearInvocations(mHeadsetService);
        Mockito.clearInvocations(mA2dpService);
        Mockito.clearInvocations(mLeAudioService);

        // Connect LE Audio device, set it to inactive
        leAudioConnected(mLeAudioDevice);
        leAudioActiveDeviceChanged(mLeAudioDevice);
        mTestLooper.dispatchAll();
        verify(mLeAudioService).setActiveDevice(mLeAudioDevice);
        assertThat(mActiveDeviceManager.getLeAudioActiveDevice()).isEqualTo(mLeAudioDevice);

        Mockito.clearInvocations(mHeadsetService);
        Mockito.clearInvocations(mA2dpService);
        Mockito.clearInvocations(mLeAudioService);

        // Set LE Audio device to inactive
        // Set A2DP + HFP device to active
        leAudioActiveDeviceChanged(null);
        headsetActiveDeviceChanged(mA2dpHeadsetDevice);
        mTestLooper.dispatchAll();
        // A2DP + HFP should now be active
        verify(mLeAudioService, never()).setActiveDevice(mLeAudioDevice);
        verify(mA2dpService).setActiveDevice(mA2dpHeadsetDevice);
    }

    @Test
    public void hfpActivatedAfterTimeout_shouldActivateA2dpAgain() {
        a2dpConnected(mA2dpHeadsetDevice, true);