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

Commit e4238588 authored by Hall Liu's avatar Hall Liu
Browse files

Add updates for the BT route for the UI.

Update the BT route for the UI when the BT stack reports an audio state
change in any device, not just the device whose route we're currently
on.

Change-Id: I87352f0564901eff870fe22e04463210d4e38546
Fixes: 122359801
Test: unit
parent 42f5f46b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -75,6 +75,12 @@ public class CallAudioRoutePeripheralAdapter implements WiredHeadsetManager.List
                CallAudioRouteStateMachine.BT_AUDIO_DISCONNECTED);
    }

    @Override
    public void onUnexpectedBluetoothStateChange() {
        mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
                CallAudioRouteStateMachine.UPDATE_SYSTEM_AUDIO_ROUTE);
    }

    /**
      * Updates the audio route when the headset plugged in state changes. For example, if audio is
      * being routed over speakerphone and a headset is plugged in then switch to wired headset.
+9 −0
Original line number Diff line number Diff line
@@ -75,6 +75,12 @@ public class BluetoothRouteManager extends StateMachine {
        void onBluetoothActiveDeviceGone();
        void onBluetoothAudioConnected();
        void onBluetoothAudioDisconnected();
        /**
         * This gets called when we get an unexpected state change from Bluetooth. Their stack does
         * weird things sometimes, so this is really a signal for the listener to refresh their
         * internal state and make sure it matches up with what the BT stack is doing.
         */
        void onUnexpectedBluetoothStateChange();
    }

    /**
@@ -186,6 +192,7 @@ public class BluetoothRouteManager extends StateMachine {
                    case BT_AUDIO_LOST:
                        Log.i(LOG_TAG, "Received HFP off for device %s while HFP off.",
                                (String) args.arg2);
                        mListener.onUnexpectedBluetoothStateChange();
                        break;
                    case GET_CURRENT_STATE:
                        BlockingQueue<IState> sink = (BlockingQueue<IState>) args.arg3;
@@ -303,6 +310,7 @@ public class BluetoothRouteManager extends StateMachine {
                        } else {
                            Log.w(LOG_TAG, "Got HFP lost message for device %s while" +
                                    " connecting to %s.", address, mDeviceAddress);
                            mListener.onUnexpectedBluetoothStateChange();
                        }
                        break;
                    case GET_CURRENT_STATE:
@@ -412,6 +420,7 @@ public class BluetoothRouteManager extends StateMachine {
                        } else {
                            Log.w(LOG_TAG, "Got HFP lost message for device %s while" +
                                    " connected to %s.", address, mDeviceAddress);
                            mListener.onUnexpectedBluetoothStateChange();
                        }
                        break;
                    case GET_CURRENT_STATE:
+14 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ import static org.mockito.Mockito.when;
public class BluetoothRouteTransitionTests extends TelecomTestCase {
    private enum ListenerUpdate {
        DEVICE_LIST_CHANGED, ACTIVE_DEVICE_PRESENT, ACTIVE_DEVICE_GONE,
        AUDIO_CONNECTED, AUDIO_DISCONNECTED
        AUDIO_CONNECTED, AUDIO_DISCONNECTED, UNEXPECTED_STATE_CHANGE
    }

    private static class BluetoothRouteTestParametersBuilder {
@@ -563,6 +563,19 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase {
                .setExpectedFinalStateName(BluetoothRouteManager.AUDIO_OFF_STATE_NAME)
                .build());

        result.add(new BluetoothRouteTestParametersBuilder()
                .setName("Device gets audio-off while in another device's audio on state")
                .setInitialBluetoothState(BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX)
                .setInitialDevice(DEVICE2)
                .setConnectedDevices(DEVICE2, DEVICE1)
                .setMessageType(BluetoothRouteManager.BT_AUDIO_LOST)
                .setMessageDevice(DEVICE1)
                .setExpectedListenerUpdates(ListenerUpdate.UNEXPECTED_STATE_CHANGE)
                .setExpectedBluetoothInteraction(NONE)
                .setExpectedFinalStateName(BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX
                        + ":" + DEVICE2)
                .build());

        result.add(new BluetoothRouteTestParametersBuilder()
                .setName("Audio routing requests HFP disconnection while a device is active")
                .setInitialBluetoothState(BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX)