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

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

Merge "Suspend A2DP only when HFP has the active device"

parents 1dbad522 6bd93b12
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1607,7 +1607,7 @@ public class HeadsetService extends ProfileService {
            mSystemInterface.getHeadsetPhoneState().setNumHeldCall(numHeld);
            mSystemInterface.getHeadsetPhoneState().setCallState(callState);
            // Suspend A2DP when call about is about to become active
            if (callState != HeadsetHalConstants.CALL_STATE_DISCONNECTED
            if (mActiveDevice != null && callState != HeadsetHalConstants.CALL_STATE_DISCONNECTED
                    && !mSystemInterface.isCallIdle() && isCallIdleBefore) {
                mSystemInterface.getAudioManager().setParameters("A2dpSuspended=true");
            }
+30 −2
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ public class HeadsetServiceTest {
        doNothing().when(mSystemInterface).stop();
        when(mSystemInterface.getHeadsetPhoneState()).thenReturn(mPhoneState);
        when(mSystemInterface.getAudioManager()).thenReturn(mAudioManager);
        when(mSystemInterface.isCallIdle()).thenReturn(true);
        when(mSystemInterface.isCallIdle()).thenReturn(true, false, true, false);
        // Mock methods in HeadsetNativeInterface
        mNativeInterface = spy(HeadsetNativeInterface.getInstance());
        doNothing().when(mNativeInterface).init(anyInt(), anyBoolean());
@@ -704,6 +704,9 @@ public class HeadsetServiceTest {
        mHeadsetServiceBinder.phoneStateChanged(headsetCallState.mNumActive,
                headsetCallState.mNumHeld, headsetCallState.mCallState, headsetCallState.mNumber,
                headsetCallState.mType, headsetCallState.mName);
        TestUtils.waitForLooperToFinishScheduledTask(
                mHeadsetService.getStateMachinesThreadLooper());
        verify(mAudioManager, never()).setParameters("A2dpSuspended=true");
        HeadsetTestUtils.verifyPhoneStateChangeSetters(mPhoneState, headsetCallState,
                ASYNC_CALL_TIMEOUT_MILLIS);
    }
@@ -717,7 +720,7 @@ public class HeadsetServiceTest {
    @Test
    public void testPhoneStateChange_oneDeviceSaveState() throws RemoteException {
        HeadsetCallState headsetCallState =
                new HeadsetCallState(1, 0, HeadsetHalConstants.CALL_STATE_ALERTING,
                new HeadsetCallState(0, 0, HeadsetHalConstants.CALL_STATE_IDLE,
                        TEST_PHONE_NUMBER, 128, "");
        when(mDatabaseManager.getProfileConnectionPolicy(any(BluetoothDevice.class),
                eq(BluetoothProfile.HEADSET)))
@@ -758,12 +761,33 @@ public class HeadsetServiceTest {
        mHeadsetServiceBinder.phoneStateChanged(headsetCallState.mNumActive,
                headsetCallState.mNumHeld, headsetCallState.mCallState, headsetCallState.mNumber,
                headsetCallState.mType, headsetCallState.mName);
        TestUtils.waitForLooperToFinishScheduledTask(
                mHeadsetService.getStateMachinesThreadLooper());

        // Should not ask Audio HAL to suspend A2DP without active device
        verify(mAudioManager, never()).setParameters("A2dpSuspended=true");
        // Make sure we notify device about this change
        verify(mStateMachines.get(mCurrentDevice)).sendMessage(
                HeadsetStateMachine.CALL_STATE_CHANGED, headsetCallState);
        // Make sure state is updated once in phone state holder
        HeadsetTestUtils.verifyPhoneStateChangeSetters(mPhoneState, headsetCallState,
                ASYNC_CALL_TIMEOUT_MILLIS);

        // Set the device first as the active device
        Assert.assertTrue(mHeadsetService.setActiveDevice(mCurrentDevice));
        // Change phone state
        headsetCallState.mCallState = HeadsetHalConstants.CALL_STATE_ALERTING;
        mHeadsetServiceBinder.phoneStateChanged(headsetCallState.mNumActive,
                headsetCallState.mNumHeld, headsetCallState.mCallState, headsetCallState.mNumber,
                headsetCallState.mType, headsetCallState.mName);
        TestUtils.waitForLooperToFinishScheduledTask(
                mHeadsetService.getStateMachinesThreadLooper());
        // Ask Audio HAL to suspend A2DP
        verify(mAudioManager).setParameters("A2dpSuspended=true");
        // Make sure state is updated
        verify(mStateMachines.get(mCurrentDevice)).sendMessage(
                HeadsetStateMachine.CALL_STATE_CHANGED, headsetCallState);
        verify(mPhoneState).setCallState(eq(headsetCallState.mCallState));
    }

    /**
@@ -816,11 +840,15 @@ public class HeadsetServiceTest {
                    Matchers.containsInAnyOrder(connectedDevices.toArray()));
            mHeadsetService.onConnectionStateChangedFromStateMachine(mCurrentDevice,
                    BluetoothProfile.STATE_CONNECTING, BluetoothProfile.STATE_CONNECTED);
            Assert.assertTrue(mHeadsetService.setActiveDevice(mCurrentDevice));
        }
        // Change phone state
        mHeadsetServiceBinder.phoneStateChanged(headsetCallState.mNumActive,
                headsetCallState.mNumHeld, headsetCallState.mCallState, headsetCallState.mNumber,
                headsetCallState.mType, headsetCallState.mName);
        // Ask Audio HAL to suspend A2DP
        verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .setParameters("A2dpSuspended=true");
        // Make sure we notify devices about this change
        for (BluetoothDevice device : connectedDevices) {
            verify(mStateMachines.get(device)).sendMessage(HeadsetStateMachine.CALL_STATE_CHANGED,