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

Commit ed3264ed authored by Yuyang Huang's avatar Yuyang Huang
Browse files

Support LE Audio to HFP handover in non-idle call state

Previously handover is done when call is non-idle and in band ringtone is enabled. This miss a case for out band ringtone.
Also, move LE audio active before setLeAudioSuspended(false), this reduce the time on resume active device.

Bug: 317754458
Bug: 331468678
Test: atest HeadsetServiceTest
Change-Id: I8682f069756c8fec33cb75e26bc2f953ff9c853e
parent bbd13a86
Loading
Loading
Loading
Loading
+28 −11
Original line number Diff line number Diff line
@@ -1354,6 +1354,21 @@ public class HeadsetService extends ProfileService {
            }
            BluetoothDevice previousActiveDevice = mActiveDevice;
            mActiveDevice = device;

            /* If HFP is getting active for a phone call and there are active LE Audio devices,
             * Lets inactive LeAudio device as soon as possible so there is no CISes connected
             * when SCO is going to be created
             */
            if (mSystemInterface.isInCall() || mSystemInterface.isRinging()) {
                LeAudioService leAudioService = mFactory.getLeAudioService();
                if (leAudioService != null
                        && !leAudioService.getConnectedDevices().isEmpty()
                        && Flags.leaudioResumeActiveAfterHfpHandover()) {
                    Log.i(TAG, "Make sure no le audio device active for HFP handover.");
                    leAudioService.setInactiveForHfpHandover(mActiveDevice);
                }
            }

            if (getAudioState(previousActiveDevice) != BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
                int disconnectStatus = disconnectAudio(previousActiveDevice);
                if (disconnectStatus != BluetoothStatusCodes.SUCCESS) {
@@ -1383,7 +1398,7 @@ public class HeadsetService extends ProfileService {
                 * when SCO is created
                 */
                LeAudioService leAudioService = mFactory.getLeAudioService();
                if (leAudioService != null) {
                if (leAudioService != null && !Flags.leaudioResumeActiveAfterHfpHandover()) {
                    Log.i(TAG, "Make sure there is no le audio device active.");
                    leAudioService.setInactiveForHfpHandover(mActiveDevice);
                }
@@ -2151,21 +2166,23 @@ public class HeadsetService extends ProfileService {
                                + "voice call");
                    }
                }
                // Unsuspend A2DP when SCO connection is gone and call state is idle
                if (mSystemInterface.isCallIdle()) {
                    mSystemInterface.getAudioManager().setA2dpSuspended(false);
                    if (isAtLeastU()) {
                        mSystemInterface.getAudioManager().setLeAudioSuspended(false);

                // Resumes LE audio previous active device if HFP handover happened before.
                // Do it here because some controllers cannot handle SCO and CIS
                // co-existence see {@link LeAudioService#setInactiveForHfpHandover}
                if (Flags.leaudioResumeActiveAfterHfpHandover()) {
                    LeAudioService leAudioService = mFactory.getLeAudioService();
                            if (leAudioService != null) {
                    if (leAudioService != null
                            && !leAudioService.getConnectedDevices().isEmpty()
                            && leAudioService.getActiveDevices().get(0) == null) {
                        leAudioService.setActiveAfterHfpHandover();
                    }
                }

                // Unsuspend A2DP when SCO connection is gone and call state is idle
                if (mSystemInterface.isCallIdle()) {
                    mSystemInterface.getAudioManager().setA2dpSuspended(false);
                    if (isAtLeastU()) {
                        mSystemInterface.getAudioManager().setLeAudioSuspended(false);
                    }
                }
            }
+6 −1
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -1604,15 +1605,19 @@ public class HeadsetServiceAndStateMachineTest {

    @Test
    public void testHfpHandoverToLeAudioAfterScoDisconnect() {
        BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
        mSetFlagsRule.enableFlags(Flags.FLAG_LEAUDIO_RESUME_ACTIVE_AFTER_HFP_HANDOVER);

        Assert.assertNotNull(mHeadsetService.mFactory);
        doReturn(mLeAudioService).when(mServiceFactory).getLeAudioService();
        doReturn(List.of(device)).when(mLeAudioService).getConnectedDevices();
        List<BluetoothDevice> activeDeviceList = new ArrayList<>();
        activeDeviceList.add(null);
        doReturn(activeDeviceList).when(mLeAudioService).getActiveDevices();
        mHeadsetService.mFactory = mServiceFactory;
        doReturn(true).when(mSystemInterface).isCallIdle();

        // Connect HF
        BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
        connectTestDevice(device);
        // Make device active
        Assert.assertTrue(mHeadsetService.setActiveDevice(device));
+1 −1

File changed.

Contains only whitespace changes.