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

Commit 3bd3d06b authored by xiaotonj's avatar xiaotonj
Browse files

Add bluetooth as a supported route when we actually eneted a bluetooth

route.

Sometimes we can't add bluetooth as a supported route when it connected,
so the device actually audio connected, we failed to update call audio
state correctly. Fix this by also updating support route mask of the
call audio when the current route changed.

Bug: b/301695370
Test: atest CallAudioRouteStateMachineTest
Change-Id: I22b37ba8483ef8cc427aaa10b6c7d70fb31c8245
parent ec2e6728
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -48,3 +48,10 @@ flag {
  description: "Protect set/clear communication device operation with lock to avoid race condition."
  bug: "303001133"
}

flag {
  name: "update_route_mask_when_bt_connected"
  namespace: "telecom"
  description: "Update supported route mask when Bluetooth devices audio connected."
  bug: "301695370"
}
+3 −0
Original line number Diff line number Diff line
@@ -840,6 +840,9 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
            if (mFeatureFlags.callAudioCommunicationDeviceRefactor()) {
                setBluetoothOn(null);
            }
            if (mFeatureFlags.updateRouteMaskWhenBtConnected()) {
                mAvailableRoutes |= ROUTE_BLUETOOTH;
            }
            CallAudioState newState = new CallAudioState(mIsMuted, ROUTE_BLUETOOTH,
                    mAvailableRoutes, mBluetoothRouteManager.getBluetoothAudioConnectedDevice(),
                    mBluetoothRouteManager.getConnectedDevices());
+31 −0
Original line number Diff line number Diff line
@@ -1238,6 +1238,37 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase {
        assertEquals(expectedState, stateMachine.getCurrentCallAudioState());
    }

    @SmallTest
    @Test
    public void testSupportRouteMaskUpdateWhenBtAudioConnected() {
        when(mFeatureFlags.updateRouteMaskWhenBtConnected()).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 */,
                mCommunicationDeviceTracker,
                mFeatureFlags);
        stateMachine.setCallAudioManager(mockCallAudioManager);

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

        stateMachine.sendMessageWithSessionInfo(CallAudioRouteStateMachine.BT_AUDIO_CONNECTED);
        waitForHandlerAction(stateMachine.getAdapterHandler(), TEST_TIMEOUT);
        CallAudioState expectedState = new CallAudioState(false, CallAudioState.ROUTE_BLUETOOTH,
                CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER
                        | CallAudioState.ROUTE_BLUETOOTH);
        assertEquals(expectedState, stateMachine.getCurrentCallAudioState());
    }

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