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

Commit c2746643 authored by Tyler Gunn's avatar Tyler Gunn Committed by Android (Google) Code Review
Browse files

Merge "Ignore SPEAKER_OFF in ActiveSpeakerRoute after BT become active." into udc-d1-dev

parents 9d490353 7cca4be0
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -1215,7 +1215,13 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    // Expected, since we just transitioned here
                    // Expected, since we just transitioned here
                    return HANDLED;
                    return HANDLED;
                case SPEAKER_OFF:
                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);
                        sendInternalMessage(SWITCH_BASELINE_ROUTE, INCLUDE_BLUETOOTH_IN_BASELINE);
                    }
                    return HANDLED;
                    return HANDLED;
                case SWITCH_FOCUS:
                case SWITCH_FOCUS:
                    if (msg.arg1 == NO_FOCUS) {
                    if (msg.arg1 == NO_FOCUS) {
+42 −11
Original line number Original line Diff line number Diff line
@@ -60,6 +60,7 @@ import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.any;
@@ -173,7 +174,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mockStatusBarNotifier,
                mAudioServiceFactory,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_AUTO_DETECT,
                CallAudioRouteStateMachine.EARPIECE_AUTO_DETECT,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);
        stateMachine.setCallAudioManager(mockCallAudioManager);


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


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


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


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


@@ -644,7 +635,6 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
                mockStatusBarNotifier,
                mockStatusBarNotifier,
                mAudioServiceFactory,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED,
                mThreadHandler.getLooper(),
                Runnable::run /** do async stuff sync for test purposes */);
                Runnable::run /** do async stuff sync for test purposes */);
        stateMachine.setCallAudioManager(mockCallAudioManager);
        stateMachine.setCallAudioManager(mockCallAudioManager);
        List<BluetoothDevice> availableDevices =
        List<BluetoothDevice> availableDevices =
@@ -798,6 +788,47 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
        assertEquals(initState, stateMachine.getCurrentCallAudioState());
        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,
    private void initializationTestHelper(CallAudioState expectedState,
            int earpieceControl) {
            int earpieceControl) {
        when(mockWiredHeadsetManager.isPluggedIn()).thenReturn(
        when(mockWiredHeadsetManager.isPluggedIn()).thenReturn(