Merge "Replacing getActiveDevice by btAdapter.getActiveDevices()"

This commit is contained in:
Etienne Ruffieux 2022-02-02 20:35:50 +00:00 committed by Gerrit Code Review
commit fa9d5b2e03
5 changed files with 19 additions and 10 deletions

View File

@ -173,8 +173,10 @@ public class A2dpProfile implements LocalBluetoothProfile {
}
public BluetoothDevice getActiveDevice() {
if (mService == null) return null;
return mService.getActiveDevice();
if (mBluetoothAdapter == null) return null;
final List<BluetoothDevice> activeDevices = mBluetoothAdapter
.getActiveDevices(BluetoothProfile.A2DP);
return (activeDevices.size() > 0) ? activeDevices.get(0) : null;
}
@Override

View File

@ -132,10 +132,12 @@ public class HeadsetProfile implements LocalBluetoothProfile {
}
public BluetoothDevice getActiveDevice() {
if (mService == null) {
if (mBluetoothAdapter == null) {
return null;
}
return mService.getActiveDevice();
final List<BluetoothDevice> activeDevices = mBluetoothAdapter
.getActiveDevices(BluetoothProfile.HEADSET);
return (activeDevices.size() > 0) ? activeDevices.get(0) : null;
}
public boolean isAudioOn() {

View File

@ -168,8 +168,10 @@ public class HearingAidProfile implements LocalBluetoothProfile {
}
public List<BluetoothDevice> getActiveDevices() {
if (mService == null) return new ArrayList<>();
return mService.getActiveDevices();
if (mBluetoothAdapter == null) {
return new ArrayList<>();
}
return mBluetoothAdapter.getActiveDevices(BluetoothProfile.HEARING_AID);
}
@Override

View File

@ -21,12 +21,12 @@ import static android.bluetooth.BluetoothAdapter.ACTIVE_DEVICE_ALL;
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED;
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.content.Context;
@ -177,10 +177,10 @@ public class LeAudioProfile implements LocalBluetoothProfile {
}
public List<BluetoothDevice> getActiveDevices() {
if (mService == null) {
if (mBluetoothAdapter == null) {
return new ArrayList<>();
}
return mService.getActiveDevices();
return mBluetoothAdapter.getActiveDevices(BluetoothProfile.LE_AUDIO);
}
@Override

View File

@ -60,6 +60,8 @@ public class A2dpProfileTest {
private BluetoothDevice mDevice;
@Mock
private BluetoothA2dp mBluetoothA2dp;
@Mock
private BluetoothAdapter mBluetoothAdapter;
private BluetoothProfile.ServiceListener mServiceListener;
private A2dpProfile mProfile;
@ -72,7 +74,8 @@ public class A2dpProfileTest {
mProfile = new A2dpProfile(mContext, mDeviceManager, mProfileManager);
mServiceListener = mShadowBluetoothAdapter.getServiceListener();
mServiceListener.onServiceConnected(BluetoothProfile.A2DP, mBluetoothA2dp);
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mDevice);
when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
.thenReturn(Arrays.asList(mDevice));
}
@Test