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

Commit d7aa2e00 authored by Rahul Sabnis's avatar Rahul Sabnis
Browse files

Suspend LE Audio media streaming whenever we suspend A2DP

Tag: #feature
Bug: 265077756
Test: Manual
Change-Id: I844f36e00c1d1e47dea988f6111285e344e6f5d2
parent 9b6ad125
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1849,6 +1849,7 @@ public class HeadsetService extends ProfileService {
            if (mActiveDevice != null && callState != HeadsetHalConstants.CALL_STATE_DISCONNECTED
                    && !mSystemInterface.isCallIdle() && isCallIdleBefore) {
                mSystemInterface.getAudioManager().setA2dpSuspended(true);
                mSystemInterface.getAudioManager().setLeAudioSuspended(true);
            }
        });
        doForEachConnectedStateMachine(
@@ -1859,6 +1860,7 @@ public class HeadsetService extends ProfileService {
                    && mSystemInterface.isCallIdle() && !isAudioOn()) {
                // Resume A2DP when call ended and SCO is not connected
                mSystemInterface.getAudioManager().setA2dpSuspended(false);
                mSystemInterface.getAudioManager().setLeAudioSuspended(false);
            }
        });
        if (callState == HeadsetHalConstants.CALL_STATE_IDLE) {
@@ -2094,6 +2096,7 @@ public class HeadsetService extends ProfileService {
                // Unsuspend A2DP when SCO connection is gone and call state is idle
                if (mSystemInterface.isCallIdle()) {
                    mSystemInterface.getAudioManager().setA2dpSuspended(false);
                    mSystemInterface.getAudioManager().setLeAudioSuspended(false);
                }
            }
        }
+2 −0
Original line number Diff line number Diff line
@@ -1113,8 +1113,10 @@ public class HeadsetStateMachine extends StateMachine {
                case CONNECT_AUDIO:
                    stateLogD("CONNECT_AUDIO, device=" + mDevice);
                    mSystemInterface.getAudioManager().setA2dpSuspended(true);
                    mSystemInterface.getAudioManager().setLeAudioSuspended(true);
                    if (!mNativeInterface.connectAudio(mDevice)) {
                        mSystemInterface.getAudioManager().setA2dpSuspended(false);
                        mSystemInterface.getAudioManager().setLeAudioSuspended(false);
                        stateLogE("Failed to connect SCO audio for " + mDevice);
                        // No state change involved, fire broadcast immediately
                        broadcastAudioState(mDevice, BluetoothHeadset.STATE_AUDIO_DISCONNECTED,
+5 −0
Original line number Diff line number Diff line
@@ -942,6 +942,7 @@ public class HeadsetServiceAndStateMachineTest {
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).atResponseCode(deviceA,
                HeadsetHalConstants.AT_RESPONSE_OK, 0);
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setA2dpSuspended(true);
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setLeAudioSuspended(true);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).connectAudio(deviceA);
        verifyNoMoreInteractions(mNativeInterface);
    }
@@ -997,6 +998,7 @@ public class HeadsetServiceAndStateMachineTest {
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).atResponseCode(deviceA,
                HeadsetHalConstants.AT_RESPONSE_OK, 0);
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setA2dpSuspended(true);
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setLeAudioSuspended(true);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).connectAudio(deviceA);
        verifyNoMoreInteractions(mNativeInterface);
    }
@@ -1076,6 +1078,7 @@ public class HeadsetServiceAndStateMachineTest {
        Assert.assertEquals(deviceA, mHeadsetService.getActiveDevice());
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).startVoiceRecognition(deviceA);
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setA2dpSuspended(true);
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setLeAudioSuspended(true);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).connectAudio(deviceA);
        waitAndVerifyAudioStateIntent(ASYNC_CALL_TIMEOUT_MILLIS, deviceA,
                BluetoothHeadset.STATE_AUDIO_CONNECTING, BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
@@ -1124,6 +1127,7 @@ public class HeadsetServiceAndStateMachineTest {
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).atResponseCode(device,
                HeadsetHalConstants.AT_RESPONSE_OK, 0);
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setA2dpSuspended(true);
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setLeAudioSuspended(true);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).connectAudio(device);
        waitAndVerifyAudioStateIntent(ASYNC_CALL_TIMEOUT_MILLIS, device,
                BluetoothHeadset.STATE_AUDIO_CONNECTING, BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
@@ -1141,6 +1145,7 @@ public class HeadsetServiceAndStateMachineTest {
        Assert.assertTrue(mHeadsetService.startVoiceRecognition(device));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).startVoiceRecognition(device);
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setA2dpSuspended(true);
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setLeAudioSuspended(true);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).connectAudio(device);
        waitAndVerifyAudioStateIntent(ASYNC_CALL_TIMEOUT_MILLIS, device,
                BluetoothHeadset.STATE_AUDIO_CONNECTING, BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
+7 −3
Original line number Diff line number Diff line
@@ -719,6 +719,7 @@ public class HeadsetServiceTest {
        TestUtils.waitForLooperToFinishScheduledTask(
                mHeadsetService.getStateMachinesThreadLooper());
        verify(mAudioManager, never()).setA2dpSuspended(true);
        verify(mAudioManager, never()).setLeAudioSuspended(true);
        HeadsetTestUtils.verifyPhoneStateChangeSetters(mPhoneState, headsetCallState,
                ASYNC_CALL_TIMEOUT_MILLIS);
    }
@@ -776,8 +777,9 @@ public class HeadsetServiceTest {
        TestUtils.waitForLooperToFinishScheduledTask(
                mHeadsetService.getStateMachinesThreadLooper());

        // Should not ask Audio HAL to suspend A2DP without active device
        // Should not ask Audio HAL to suspend A2DP or LE Audio without active device
        verify(mAudioManager, never()).setA2dpSuspended(true);
        verify(mAudioManager, never()).setLeAudioSuspended(true);
        // Make sure we notify device about this change
        verify(mStateMachines.get(mCurrentDevice)).sendMessage(
                HeadsetStateMachine.CALL_STATE_CHANGED, headsetCallState);
@@ -794,8 +796,9 @@ public class HeadsetServiceTest {
                headsetCallState.mType, headsetCallState.mName, false);
        TestUtils.waitForLooperToFinishScheduledTask(
                mHeadsetService.getStateMachinesThreadLooper());
        // Ask Audio HAL to suspend A2DP
        // Ask Audio HAL to suspend A2DP and LE Audio
        verify(mAudioManager).setA2dpSuspended(true);
        verify(mAudioManager).setLeAudioSuspended(true);
        // Make sure state is updated
        verify(mStateMachines.get(mCurrentDevice)).sendMessage(
                HeadsetStateMachine.CALL_STATE_CHANGED, headsetCallState);
@@ -858,8 +861,9 @@ public class HeadsetServiceTest {
        mHeadsetService.phoneStateChanged(headsetCallState.mNumActive,
                headsetCallState.mNumHeld, headsetCallState.mCallState, headsetCallState.mNumber,
                headsetCallState.mType, headsetCallState.mName, false);
        // Ask Audio HAL to suspend A2DP
        // Ask Audio HAL to suspend A2DP and LE Audio
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setA2dpSuspended(true);
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setLeAudioSuspended(true);
        // Make sure we notify devices about this change
        for (BluetoothDevice device : connectedDevices) {
            verify(mStateMachines.get(device)).sendMessage(HeadsetStateMachine.CALL_STATE_CHANGED,
+2 −1
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@ static int adev_set_parameters(struct audio_hw_device* dev,

  LOG(VERBOSE) << __func__ << ": ParamsMap=[" << GetAudioParamString(params)
               << "]";
  if (params.find("A2dpSuspended") == params.end()) {
  if (params.find("A2dpSuspended") == params.end() &&
      params.find("LeAudioSuspended") == params.end()) {
    return -ENOSYS;
  }