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

Commit 3dd526f7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Fix not fallback to LE Audio when HFP removed active device" into main

parents 066933a9 2677bba3
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
@@ -382,6 +382,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);