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

Commit 61d00cca authored by Hall Liu's avatar Hall Liu Committed by Android (Google) Code Review
Browse files

Merge "Switch to active BT route when changing focus" into pi-dev

parents 0482751c 74098958
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -56,8 +56,8 @@ public class BluetoothHeadsetProxy {
        return mBluetoothHeadset.getConnectionState(device);
        return mBluetoothHeadset.getConnectionState(device);
    }
    }


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


    public boolean connectAudio() {
    public boolean connectAudio() {
+5 −2
Original line number Original line Diff line number Diff line
@@ -1452,7 +1452,10 @@ public class CallAudioRouteStateMachine extends StateMachine {
            BluetoothDevice connectedDevice =
            BluetoothDevice connectedDevice =
                    mBluetoothRouteManager.getBluetoothAudioConnectedDevice();
                    mBluetoothRouteManager.getBluetoothAudioConnectedDevice();
            if (address == null && connectedDevice != null) {
            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;
                return;
            }
            }
            if (connectedDevice == null || !Objects.equals(address, connectedDevice.getAddress())) {
            if (connectedDevice == null || !Objects.equals(address, connectedDevice.getAddress())) {
@@ -1630,7 +1633,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
        return UserHandle.USER_OWNER;
        return UserHandle.USER_OWNER;
    }
    }


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


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


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


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


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


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