Merge "Replacing getActiveDevice by btAdapter.getActiveDevices()"
This commit is contained in:
@@ -173,8 +173,10 @@ public class A2dpProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BluetoothDevice getActiveDevice() {
|
public BluetoothDevice getActiveDevice() {
|
||||||
if (mService == null) return null;
|
if (mBluetoothAdapter == null) return null;
|
||||||
return mService.getActiveDevice();
|
final List<BluetoothDevice> activeDevices = mBluetoothAdapter
|
||||||
|
.getActiveDevices(BluetoothProfile.A2DP);
|
||||||
|
return (activeDevices.size() > 0) ? activeDevices.get(0) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -132,10 +132,12 @@ public class HeadsetProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BluetoothDevice getActiveDevice() {
|
public BluetoothDevice getActiveDevice() {
|
||||||
if (mService == null) {
|
if (mBluetoothAdapter == null) {
|
||||||
return 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() {
|
public boolean isAudioOn() {
|
||||||
|
|||||||
@@ -168,8 +168,10 @@ public class HearingAidProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<BluetoothDevice> getActiveDevices() {
|
public List<BluetoothDevice> getActiveDevices() {
|
||||||
if (mService == null) return new ArrayList<>();
|
if (mBluetoothAdapter == null) {
|
||||||
return mService.getActiveDevices();
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
return mBluetoothAdapter.getActiveDevices(BluetoothProfile.HEARING_AID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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_ALLOWED;
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
|
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothLeAudio;
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothCodecConfig;
|
import android.bluetooth.BluetoothCodecConfig;
|
||||||
import android.bluetooth.BluetoothCodecStatus;
|
import android.bluetooth.BluetoothCodecStatus;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothLeAudio;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.bluetooth.BluetoothUuid;
|
import android.bluetooth.BluetoothUuid;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -177,10 +177,10 @@ public class LeAudioProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<BluetoothDevice> getActiveDevices() {
|
public List<BluetoothDevice> getActiveDevices() {
|
||||||
if (mService == null) {
|
if (mBluetoothAdapter == null) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
return mService.getActiveDevices();
|
return mBluetoothAdapter.getActiveDevices(BluetoothProfile.LE_AUDIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ public class A2dpProfileTest {
|
|||||||
private BluetoothDevice mDevice;
|
private BluetoothDevice mDevice;
|
||||||
@Mock
|
@Mock
|
||||||
private BluetoothA2dp mBluetoothA2dp;
|
private BluetoothA2dp mBluetoothA2dp;
|
||||||
|
@Mock
|
||||||
|
private BluetoothAdapter mBluetoothAdapter;
|
||||||
private BluetoothProfile.ServiceListener mServiceListener;
|
private BluetoothProfile.ServiceListener mServiceListener;
|
||||||
|
|
||||||
private A2dpProfile mProfile;
|
private A2dpProfile mProfile;
|
||||||
@@ -72,7 +74,8 @@ public class A2dpProfileTest {
|
|||||||
mProfile = new A2dpProfile(mContext, mDeviceManager, mProfileManager);
|
mProfile = new A2dpProfile(mContext, mDeviceManager, mProfileManager);
|
||||||
mServiceListener = mShadowBluetoothAdapter.getServiceListener();
|
mServiceListener = mShadowBluetoothAdapter.getServiceListener();
|
||||||
mServiceListener.onServiceConnected(BluetoothProfile.A2DP, mBluetoothA2dp);
|
mServiceListener.onServiceConnected(BluetoothProfile.A2DP, mBluetoothA2dp);
|
||||||
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mDevice);
|
when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
|
||||||
|
.thenReturn(Arrays.asList(mDevice));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user