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

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

Switch to active BT route when changing focus

Send a BT_AUDIO_CONNECTED message right away if we try to connect to BT
audio and we find that it's already connected. This way we don't get
stuck in a quiescent state.

Change-Id: Idbfb4b77a243d300d47703643e22d5f1d8a2474c
Fixes: 79501344
Test: added a unit test.
parent 0a88abbb
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -56,8 +56,8 @@ public class BluetoothHeadsetProxy {
        return mBluetoothHeadset.getConnectionState(device);
    }

    public boolean isAudioConnected(BluetoothDevice device) {
        return mBluetoothHeadset.isAudioConnected(device);
    public int getAudioState(BluetoothDevice device) {
        return mBluetoothHeadset.getAudioState(device);
    }

    public boolean connectAudio() {
+5 −2
Original line number Diff line number Diff line
@@ -1452,7 +1452,10 @@ public class CallAudioRouteStateMachine extends StateMachine {
            BluetoothDevice connectedDevice =
                    mBluetoothRouteManager.getBluetoothAudioConnectedDevice();
            if (address == null && connectedDevice != null) {
                // null means connect to any device, so don't bother reconnecting
                // null means connect to any device, so don't bother reconnecting. Also, send a
                // message to ourselves telling us that BT audio is already connected.
                Log.i(this, "HFP audio already on. Skipping connecting.");
                sendInternalMessage(BT_AUDIO_CONNECTED);
                return;
            }
            if (connectedDevice == null || !Objects.equals(address, connectedDevice.getAddress())) {
@@ -1630,7 +1633,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
        return UserHandle.USER_OWNER;
    }

    private boolean isInActiveState() {
    public boolean isInActiveState() {
        AudioState currentState = (AudioState) getCurrentState();
        if (currentState == null) {
            Log.w(this, "Current state is null, assuming inactive state");
+3 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.telecom.bluetooth;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.content.Context;
import android.os.Message;
import android.telecom.Log;
@@ -653,7 +654,8 @@ public class BluetoothRouteManager extends StateMachine {

        for (int i = 0; i < deviceList.size(); i++) {
            BluetoothDevice device = deviceList.get(i);
            boolean isAudioOn = bluetoothHeadset.isAudioConnected(device);
            boolean isAudioOn = bluetoothHeadset.getAudioState(device)
                    != BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
            Log.v(this, "isBluetoothAudioConnected: ==> isAudioOn = " + isAudioOn
                    + "for headset: " + device);
            if (isAudioOn) {
+3 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.telecom.tests;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.content.ContentResolver;
import android.os.Parcel;
import android.telecom.Log;
@@ -130,7 +131,8 @@ public class BluetoothRouteManagerTest extends TelecomTestCase {
        when(mDeviceManager.getConnectedDevices()).thenReturn(Arrays.asList(devices));
        when(mHeadsetProxy.getConnectedDevices()).thenReturn(Arrays.asList(devices));
        if (activeDevice != null) {
            when(mHeadsetProxy.isAudioConnected(eq(activeDevice))).thenReturn(true);
            when(mHeadsetProxy.getAudioState(eq(activeDevice)))
                    .thenReturn(BluetoothHeadset.STATE_AUDIO_CONNECTED);
        }
        doAnswer(invocation -> {
            BluetoothDevice first = getFirstExcluding(devices,
+3 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.telecom.tests;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.content.ContentResolver;
import android.test.suitebuilder.annotation.SmallTest;

@@ -306,7 +307,8 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase {
        when(mHeadsetProxy.getConnectedDevices()).thenReturn(Arrays.asList(devices));
        when(mHeadsetProxy.getActiveDevice()).thenReturn(activeDevice);
        if (audioOnDevice != null) {
            when(mHeadsetProxy.isAudioConnected(eq(audioOnDevice))).thenReturn(true);
            when(mHeadsetProxy.getAudioState(eq(audioOnDevice)))
                    .thenReturn(BluetoothHeadset.STATE_AUDIO_CONNECTED);
        }
        doAnswer(invocation -> {
            BluetoothDevice first = getFirstExcluding(devices,
Loading