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

Commit a4d6a97d authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Resolve call audio focus not abandoned

If a BT device is connected and an incoming call is placed and rejected,
if the inband ringing is disabled, the audio routing never goes active.
The logic in handling a focus switch to NO_FOCUS currently only abandons
audio focus if the audio routing was active. Looking back at this code,
we really should just reinitialize all of the audio routing state
regardless of whether or not the audio routing was active. A lot of
these operations would be unaffected when performing them over an
inactive audio route but it's good to just reset the controller state
once the call ends.

Bug: 376820227
Flag: EXEMPT bugfix
Test: CallAudioRouteControllerTest#testAbandonCallAudioFocusAfterCallEnd
Change-Id: I3657cb8797d1a15eecf7254b9ceec9ea3851fde4
parent c5b6918a
Loading
Loading
Loading
Loading
+16 −18
Original line number Diff line number Diff line
@@ -878,12 +878,11 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
        mFocusType = focus;
        switch (focus) {
            case NO_FOCUS -> {
                if (mIsActive) {
                // Notify the CallAudioModeStateMachine that audio operations are complete so
                // that we can relinquish audio focus.
                mCallAudioManager.notifyAudioOperationsComplete();

                    // Reset mute state after call ends.
                // Reset mute state after call ends. This should remain unaffected if audio routing
                // never went active.
                handleMuteChanged(false);
                // Ensure we reset call audio state at the end of the call (i.e. if we're on
                // speaker, route back to earpiece). If we're on BT, remain on BT if it's still
@@ -896,7 +895,6 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
                mPendingAudioRoute.clearPendingMessages();
                clearRingingBluetoothAddress();
            }
            }
            case ACTIVE_FOCUS -> {
                // Route to active baseline route (we may need to change audio route in the case
                // when a video call is put on hold). Ignore route changes if we're handling playing
+32 −0
Original line number Diff line number Diff line
@@ -1099,6 +1099,38 @@ public class CallAudioRouteControllerTest extends TelecomTestCase {
                any(CallAudioState.class), eq(expectedState));
    }

    @Test
    @SmallTest
    public void testAbandonCallAudioFocusAfterCallEnd() {
        // Make sure in-band ringing is disabled so that route never becomes active
        when(mBluetoothRouteManager.isInbandRingEnabled(eq(BLUETOOTH_DEVICE_1))).thenReturn(false);

        mController.initialize();
        mController.sendMessageWithSessionInfo(BT_DEVICE_ADDED, AudioRoute.TYPE_BLUETOOTH_SCO,
                BLUETOOTH_DEVICE_1);

        CallAudioState expectedState = new CallAudioState(false, CallAudioState.ROUTE_BLUETOOTH,
                CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_BLUETOOTH
                        | CallAudioState.ROUTE_SPEAKER, BLUETOOTH_DEVICE_1, BLUETOOTH_DEVICES);
        mController.sendMessageWithSessionInfo(BT_ACTIVE_DEVICE_PRESENT,
                AudioRoute.TYPE_BLUETOOTH_SCO, BT_ADDRESS_1);
        verify(mCallsManager, timeout(TEST_TIMEOUT)).onCallAudioStateChanged(
                any(CallAudioState.class), eq(expectedState));
        assertFalse(mController.isActive());

        // Verify route never went active due to in-band ringing being disabled.
        mController.sendMessageWithSessionInfo(SWITCH_FOCUS, RINGING_FOCUS, 0);
        assertFalse(mController.isActive());

        // Emulate scenario of rejecting an incoming call so that call focus is lost and verify
        // that we abandon the call audio focus that was gained from when the call went to
        // ringing state.
        mController.sendMessageWithSessionInfo(SWITCH_FOCUS, NO_FOCUS, 0);
        // Ensure we tell the CallAudioManager that audio operations are done so that we can ensure
        // audio focus is relinquished.
        verify(mCallAudioManager, timeout(TEST_TIMEOUT)).notifyAudioOperationsComplete();
    }

    private void verifyConnectBluetoothDevice(int audioType) {
        mController.initialize();
        mController.setActive(true);