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

Commit 7cca4be0 authored by Grace Jia's avatar Grace Jia
Browse files

Ignore SPEAKER_OFF in ActiveSpeakerRoute after BT become active.

Currently, ActiveSpeakerRoute will handle SPEAKER_OFF by re-evaluate
baseline route of the device. In the case that the SPEAKER_OFF triggered
by a BT connection request, we may mistakenly switch the BT connection to
another unexpected device. Fix this by ignore the SPEAKER_OFF message in
this case.

Bug: 283198536
Test: CallAudioRouteStateMachineTest
Change-Id: I9823173281431c1ff0f39984e1d3237e58bbf23d
Merged-In: I9823173281431c1ff0f39984e1d3237e58bbf23d
parent fc82152c
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -1215,7 +1215,13 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    // Expected, since we just transitioned here
                    return HANDLED;
                case SPEAKER_OFF:
                    // Check if we already requested to connect to other devices and just waiting
                    // for their response. In some cases, this SPEAKER_OFF message may come in
                    // before the response, we can just ignore the message here to not re-evaluate
                    // the baseline route incorrectly
                    if (!mBluetoothRouteManager.isBluetoothAudioConnectedOrPending()) {
                        sendInternalMessage(SWITCH_BASELINE_ROUTE, INCLUDE_BLUETOOTH_IN_BASELINE);
                    }
                    return HANDLED;
                case SWITCH_FOCUS:
                    if (msg.arg1 == NO_FOCUS) {
+42 −11
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
@@ -173,7 +174,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_AUTO_DETECT,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);

@@ -219,7 +219,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);
        CallAudioState initState = new CallAudioState(false, CallAudioState.ROUTE_SPEAKER,
@@ -263,7 +262,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);

        when(mockBluetoothRouteManager.isBluetoothAudioConnectedOrPending()).thenReturn(false);
@@ -309,7 +307,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);

@@ -354,7 +351,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);
        Collection<BluetoothDevice> availableDevices = Collections.singleton(bluetoothDevice1);
@@ -433,7 +429,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);

@@ -470,7 +465,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);
        setInBandRing(false);
@@ -526,7 +520,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);
        List<BluetoothDevice> availableDevices =
@@ -577,7 +570,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);
        when(mockAudioManager.isSpeakerphoneOn()).thenReturn(false);
@@ -609,7 +601,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);

@@ -644,7 +635,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);
        List<BluetoothDevice> availableDevices =
@@ -798,6 +788,47 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
        assertEquals(initState, stateMachine.getCurrentCallAudioState());
    }

    @SmallTest
    @Test
    public void testIgnoreSpeakerOffMessage() {
        when(mockBluetoothRouteManager.isInbandRingingEnabled()).thenReturn(true);
        when(mockBluetoothRouteManager.getBluetoothAudioConnectedDevice())
                .thenReturn(bluetoothDevice1);
        when(mockBluetoothRouteManager.isBluetoothAudioConnectedOrPending()).thenReturn(true);
        CallAudioRouteStateMachine stateMachine = new CallAudioRouteStateMachine(
                mContext,
                mockCallsManager,
                mockBluetoothRouteManager,
                mockWiredHeadsetManager,
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);

        CallAudioState initState = new CallAudioState(false, CallAudioState.ROUTE_SPEAKER,
                CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER
                        | CallAudioState.ROUTE_BLUETOOTH);
        stateMachine.initialize(initState);

        doAnswer(
                (address) -> {
                    stateMachine.sendMessageWithSessionInfo(CallAudioRouteStateMachine.SPEAKER_OFF);
                    stateMachine.sendMessageDelayed(CallAudioRouteStateMachine.BT_AUDIO_CONNECTED,
                            5000L);
                    return null;
        }).when(mockBluetoothRouteManager).connectBluetoothAudio(anyString());
        stateMachine.sendMessageWithSessionInfo(CallAudioRouteStateMachine.SWITCH_FOCUS,
                CallAudioRouteStateMachine.ACTIVE_FOCUS);
        stateMachine.sendMessageWithSessionInfo(CallAudioRouteStateMachine.USER_SWITCH_BLUETOOTH);

        CallAudioState expectedState = new CallAudioState(false, CallAudioState.ROUTE_SPEAKER,
                CallAudioState.ROUTE_SPEAKER | CallAudioState.ROUTE_BLUETOOTH
                        | CallAudioState.ROUTE_EARPIECE);
        assertEquals(expectedState, stateMachine.getCurrentCallAudioState());
    }

    private void initializationTestHelper(CallAudioState expectedState,
            int earpieceControl) {
        when(mockWiredHeadsetManager.isPluggedIn()).thenReturn(