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

Commit f3f2a771 authored by Hall Liu's avatar Hall Liu Committed by Gerrit Code Review
Browse files

Merge "Check whether there's a BT active device on reset"

parents a4b3c042 cbbb2aab
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1624,7 +1624,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
        int supportedRouteMask = calculateSupportedRoutes() & getCurrentCallSupportedRoutes();
        final int route;

        if ((supportedRouteMask & ROUTE_BLUETOOTH) != 0) {
        if ((supportedRouteMask & ROUTE_BLUETOOTH) != 0
                && mBluetoothRouteManager.hasBtActiveDevice()) {
            route = ROUTE_BLUETOOTH;
        } else if ((supportedRouteMask & ROUTE_WIRED_HEADSET) != 0) {
            route = ROUTE_WIRED_HEADSET;
+4 −0
Original line number Diff line number Diff line
@@ -568,6 +568,10 @@ public class BluetoothRouteManager extends StateMachine {
        }
    }

    public boolean hasBtActiveDevice() {
        return mActiveDeviceCache != null;
    }

    public Collection<BluetoothDevice> getConnectedDevices() {
        return mDeviceManager.getConnectedDevices();
    }
+23 −0
Original line number Diff line number Diff line
@@ -538,12 +538,35 @@ public class CallAudioRouteStateMachineTest extends TelecomSystemTest {
        initializationTestHelper(expectedState, CallAudioRouteStateMachine.EARPIECE_FORCE_DISABLED);
    }

    @SmallTest
    @Test
    public void testInitializationWithAvailableButInactiveBtDevice() {
        CallAudioState expectedState = new CallAudioState(false, CallAudioState.ROUTE_EARPIECE,
                CallAudioState.ROUTE_SPEAKER | CallAudioState.ROUTE_BLUETOOTH
                        | CallAudioState.ROUTE_EARPIECE);
        when(mockBluetoothRouteManager.isBluetoothAvailable()).thenReturn(true);
        when(mockBluetoothRouteManager.hasBtActiveDevice()).thenReturn(false);

        CallAudioRouteStateMachine stateMachine = new CallAudioRouteStateMachine(
                mContext,
                mockCallsManager,
                mockBluetoothRouteManager,
                mockWiredHeadsetManager,
                mockStatusBarNotifier,
                mAudioServiceFactory,
                CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED);
        stateMachine.initialize();
        assertEquals(expectedState, stateMachine.getCurrentCallAudioState());
    }

    private void initializationTestHelper(CallAudioState expectedState,
            int earpieceControl) {
        when(mockWiredHeadsetManager.isPluggedIn()).thenReturn(
                (expectedState.getSupportedRouteMask() & CallAudioState.ROUTE_WIRED_HEADSET) != 0);
        when(mockBluetoothRouteManager.isBluetoothAvailable()).thenReturn(
                (expectedState.getSupportedRouteMask() & CallAudioState.ROUTE_BLUETOOTH) != 0);
        when(mockBluetoothRouteManager.hasBtActiveDevice()).thenReturn(
                (expectedState.getSupportedRouteMask() & CallAudioState.ROUTE_BLUETOOTH) != 0);

        CallAudioRouteStateMachine stateMachine = new CallAudioRouteStateMachine(
                mContext,