Update Telecom code to account for updated Bluetooth HFP audio state

APIs

Bug: 195156304
Test: Manual
AOSP: aosp/1932965
Change-Id: Ie2699a6f5dc769c459e2ede1e1145fd968cbc7d4
This commit is contained in:
Rahul Sabnis 2021-12-23 17:31:31 -08:00
parent 21c3018403
commit 5225f2063e
5 changed files with 15 additions and 11 deletions

View File

@ -31,6 +31,7 @@
<uses-permission android:name="android.permission.BIND_INCALL_SERVICE"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED"/>
<uses-permission android:name="android.permission.BROADCAST_CALLLOG_INFO"/>
<uses-permission android:name="android.permission.BROADCAST_PHONE_ACCOUNT_REGISTRATION"/>
<uses-permission android:name="android.permission.CALL_PRIVILEGED"/>

View File

@ -22,6 +22,7 @@ import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.content.Context;
import android.telecom.Log;
import android.util.LocalLog;
@ -414,10 +415,9 @@ public class BluetoothDeviceManager {
Log.w(this, "Couldn't set active device to %s", address);
return false;
}
if (!mBluetoothHeadset.isAudioOn()) {
return mBluetoothHeadset.connectAudio();
}
return true;
int scoConnectionRequest = mBluetoothHeadset.connectAudio();
return scoConnectionRequest == BluetoothStatusCodes.SUCCESS ||
scoConnectionRequest == BluetoothStatusCodes.ERROR_AUDIO_DEVICE_ALREADY_CONNECTED;
} else {
Log.w(this, "Attempting to turn on audio for a disconnected device");
return false;

View File

@ -754,7 +754,8 @@ public class BluetoothRouteManager extends StateMachine {
hfpAudioOnDevice = device;
break;
}
if (bluetoothHeadset.getAudioState(hfpAudioOnDevice)
if (hfpAudioOnDevice != null && bluetoothHeadset.getAudioState(hfpAudioOnDevice)
== BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
hfpAudioOnDevice = null;
} else {

View File

@ -20,8 +20,9 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.content.ContentResolver;
import android.os.Parcel;
import android.telecom.Log;
@ -90,7 +91,7 @@ public class BluetoothRouteManagerTest extends TelecomTestCase {
setupConnectedDevices(new BluetoothDevice[]{DEVICE1}, null, null, null, null, null);
when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
nullable(ContentResolver.class))).thenReturn(0L);
when(mBluetoothHeadset.connectAudio()).thenReturn(false);
when(mBluetoothHeadset.connectAudio()).thenReturn(BluetoothStatusCodes.ERROR_UNKNOWN);
executeRoutingAction(sm, BluetoothRouteManager.CONNECT_HFP, DEVICE1.getAddress());
// Wait 3 times: for the first connection attempt, the retry attempt,
// the second retry, and once more to make sure there are only three attempts.
@ -152,7 +153,7 @@ public class BluetoothRouteManagerTest extends TelecomTestCase {
null);
when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
nullable(ContentResolver.class))).thenReturn(0L);
when(mBluetoothHeadset.connectAudio()).thenReturn(false);
when(mBluetoothHeadset.connectAudio()).thenReturn(BluetoothStatusCodes.ERROR_UNKNOWN);
executeRoutingAction(sm, BluetoothRouteManager.CONNECT_HFP, DEVICE2.getAddress());
// Wait 3 times: the first connection attempt is accounted for in executeRoutingAction,
// so wait twice for the retry attempt, again to make sure there are only three attempts,
@ -234,7 +235,7 @@ public class BluetoothRouteManagerTest extends TelecomTestCase {
when(mDeviceManager.getBluetoothHearingAid()).thenReturn(mBluetoothHearingAid);
when(mDeviceManager.getBluetoothAdapter()).thenReturn(mBluetoothAdapter);
when(mDeviceManager.getLeAudioService()).thenReturn(mBluetoothLeAudio);
when(mBluetoothHeadset.connectAudio()).thenReturn(true);
when(mBluetoothHeadset.connectAudio()).thenReturn(BluetoothStatusCodes.SUCCESS);
when(mBluetoothHeadset.setActiveDevice(nullable(BluetoothDevice.class))).thenReturn(true);
when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
nullable(ContentResolver.class))).thenReturn(100000L);

View File

@ -20,8 +20,9 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.content.ContentResolver;
import android.telecom.Log;
import android.test.suitebuilder.annotation.SmallTest;
@ -299,7 +300,7 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase {
when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.HEADSET)))
.thenReturn(Arrays.asList((BluetoothDevice) null));
sm.sendMessage(BluetoothRouteManager.BT_AUDIO_LOST, args);
return true;
return BluetoothStatusCodes.SUCCESS;
}).when(mDeviceManager).disconnectAudio();
}