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

Commit 72d19393 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

ActiveDeviceManager: Fix A2DP or HFP Active device changes to null

When A2DP or HFP devices is removed from the Active Devices, it shall
not inactivate LeAudioDevice when not needed.

This is regression after:
7cdf85a0 Updates active device policy to support dual mode audio

Note: HFP case there is similar logic which also was fixed

Bug: 367917846
Flag: Exempt, Obvious fix, regression tested with unit tests
Test: atest ActiveDeviceManagerTest
Change-Id: I6bb71abb746e68ec9a833f0756e4a3109bd101db
parent a411fa9a
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());