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

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

Merge "ActiveDeviceManager: Fix A2DP or HFP Active device changes to null" into main

parents 5018b899 72d19393
Loading
Loading
Loading
Loading
+43 −16
Original line number Diff line number Diff line
@@ -614,13 +614,26 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                if (device != null) {
                    setHearingAidActiveDevice(null, true);
                }
                if (Utils.isDualModeAudioEnabled()
                        && mAdapterService.isAllSupportedClassicAudioProfilesActive(device)) {

                if (Utils.isDualModeAudioEnabled()) {
                    if (device != null) {
                        boolean isDualModeDevice =
                                mAdapterService.isAllSupportedClassicAudioProfilesActive(device);
                        if (isDualModeDevice) {
                            setLeAudioActiveDevice(device);
                        }
                    } else {
                        boolean wasDualModeDevice =
                                mAdapterService.isAllSupportedClassicAudioProfilesActive(
                                        mA2dpActiveDevice);
                        if (wasDualModeDevice) {
                            // remove LE audio active device when it was actived as dual mode device
                            // before
                            setLeAudioActiveDevice(null, true);
                        }
                    }
                }
            }
            // Just assign locally the new value
            mA2dpActiveDevice = device;

@@ -677,28 +690,42 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                            + device
                            + ", mHfpActiveDevice="
                            + mHfpActiveDevice);

            if (!Objects.equals(mHfpActiveDevice, device)) {
                if (device != null) {
                    setHearingAidActiveDevice(null, true);
                }
                if (Utils.isDualModeAudioEnabled()
                        && mAdapterService.isAllSupportedClassicAudioProfilesActive(device)) {

                if (Utils.isDualModeAudioEnabled()) {
                    if (device != null) {
                        boolean isDualModeDevice =
                                mAdapterService.isAllSupportedClassicAudioProfilesActive(device);
                        if (isDualModeDevice) {
                            setLeAudioActiveDevice(device);
                        }
                    } else {
                    if (device != null) {
                        // remove LE audio active device when it is not null, and not dual mode
                        boolean wasDualModeDevice =
                                mAdapterService.isAllSupportedClassicAudioProfilesActive(
                                        mA2dpActiveDevice);
                        if (wasDualModeDevice) {
                            // remove LE audio active device when it was actived as dual mode device
                            // before
                            setLeAudioActiveDevice(null, true);
                    } else {
                        Log.d(
                                TAG,
                                "HFP active device is null. Try to fallback to le audio active"
                                        + " device");
                        }

                        Log.d(TAG, "HFP active device is null. Try to fallback to le audio device");
                        synchronized (mLock) {
                            setFallbackDeviceActiveLocked(device);
                            setFallbackDeviceActiveLocked(null);
                        }
                    }
                } else {
                    Log.d(TAG, "HFP active device is null. Try to fallback to le audio device");
                    synchronized (mLock) {
                        setFallbackDeviceActiveLocked(null);
                    }
                }
            }

            // Just assign locally the new value
            mHfpActiveDevice = device;

+16 −3
Original line number Diff line number Diff line
@@ -644,6 +644,20 @@ public class ActiveDeviceManagerTest {
        verify(mHeadsetService, never()).setActiveDevice(any());
    }

    @Test
    public void a2dpDeactivated_makeSureToNotRemoveLeAudioDevice() {
        a2dpActiveDeviceChanged(null);
        mTestLooper.dispatchAll();
        verify(mLeAudioService, never()).removeActiveDevice(anyBoolean());
    }

    @Test
    public void hfpDeactivated_makeSureToNotRemoveLeAudioDevice() {
        headsetActiveDeviceChanged(null);
        mTestLooper.dispatchAll();
        verify(mLeAudioService, never()).removeActiveDevice(anyBoolean());
    }

    @Test
    public void a2dpActivated_whileActivatingA2dpHeadset() {
        a2dpConnected(mA2dpDevice, false);
@@ -1477,9 +1491,8 @@ public class ActiveDeviceManagerTest {
        headsetActiveDeviceChanged(mDualModeAudioDevice);
        mTestLooper.dispatchAll();

        // When A2DP device is getting active, first LeAudio device is removed from active devices
        // and later added
        verify(mLeAudioService).removeActiveDevice(anyBoolean());
        // When Hfp device is getting active and it is dual mode device LeAudioDevice will be added.
        verify(mLeAudioService, never()).removeActiveDevice(anyBoolean());
        verify(mLeAudioService).setActiveDevice(mDualModeAudioDevice);

        Assert.assertEquals(mDualModeAudioDevice, mActiveDeviceManager.getA2dpActiveDevice());