Merge "settingslib/media: Add LeAudio support"
This commit is contained in:
@@ -21,6 +21,7 @@ import static android.media.MediaRoute2Info.TYPE_DOCK;
|
|||||||
import static android.media.MediaRoute2Info.TYPE_GROUP;
|
import static android.media.MediaRoute2Info.TYPE_GROUP;
|
||||||
import static android.media.MediaRoute2Info.TYPE_HDMI;
|
import static android.media.MediaRoute2Info.TYPE_HDMI;
|
||||||
import static android.media.MediaRoute2Info.TYPE_HEARING_AID;
|
import static android.media.MediaRoute2Info.TYPE_HEARING_AID;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_BLE_HEADSET;
|
||||||
import static android.media.MediaRoute2Info.TYPE_REMOTE_SPEAKER;
|
import static android.media.MediaRoute2Info.TYPE_REMOTE_SPEAKER;
|
||||||
import static android.media.MediaRoute2Info.TYPE_REMOTE_TV;
|
import static android.media.MediaRoute2Info.TYPE_REMOTE_TV;
|
||||||
import static android.media.MediaRoute2Info.TYPE_UNKNOWN;
|
import static android.media.MediaRoute2Info.TYPE_UNKNOWN;
|
||||||
@@ -481,6 +482,7 @@ public class InfoMediaManager extends MediaManager {
|
|||||||
break;
|
break;
|
||||||
case TYPE_HEARING_AID:
|
case TYPE_HEARING_AID:
|
||||||
case TYPE_BLUETOOTH_A2DP:
|
case TYPE_BLUETOOTH_A2DP:
|
||||||
|
case TYPE_BLE_HEADSET:
|
||||||
final BluetoothDevice device =
|
final BluetoothDevice device =
|
||||||
BluetoothAdapter.getDefaultAdapter().getRemoteDevice(route.getAddress());
|
BluetoothAdapter.getDefaultAdapter().getRemoteDevice(route.getAddress());
|
||||||
final CachedBluetoothDevice cachedDevice =
|
final CachedBluetoothDevice cachedDevice =
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
|||||||
import com.android.settingslib.bluetooth.HearingAidProfile;
|
import com.android.settingslib.bluetooth.HearingAidProfile;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothProfile;
|
import com.android.settingslib.bluetooth.LocalBluetoothProfile;
|
||||||
|
import com.android.settingslib.bluetooth.LeAudioProfile;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
@@ -440,6 +441,7 @@ public class LocalMediaManager implements BluetoothCallback {
|
|||||||
private boolean isActiveDevice(CachedBluetoothDevice device) {
|
private boolean isActiveDevice(CachedBluetoothDevice device) {
|
||||||
boolean isActiveDeviceA2dp = false;
|
boolean isActiveDeviceA2dp = false;
|
||||||
boolean isActiveDeviceHearingAid = false;
|
boolean isActiveDeviceHearingAid = false;
|
||||||
|
boolean isActiveLeAudio = false;
|
||||||
final A2dpProfile a2dpProfile = mLocalBluetoothManager.getProfileManager().getA2dpProfile();
|
final A2dpProfile a2dpProfile = mLocalBluetoothManager.getProfileManager().getA2dpProfile();
|
||||||
if (a2dpProfile != null) {
|
if (a2dpProfile != null) {
|
||||||
isActiveDeviceA2dp = device.getDevice().equals(a2dpProfile.getActiveDevice());
|
isActiveDeviceA2dp = device.getDevice().equals(a2dpProfile.getActiveDevice());
|
||||||
@@ -453,7 +455,15 @@ public class LocalMediaManager implements BluetoothCallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return isActiveDeviceA2dp || isActiveDeviceHearingAid;
|
if (!isActiveDeviceA2dp && !isActiveDeviceHearingAid) {
|
||||||
|
final LeAudioProfile leAudioProfile = mLocalBluetoothManager.getProfileManager()
|
||||||
|
.getLeAudioProfile();
|
||||||
|
if (leAudioProfile != null) {
|
||||||
|
isActiveLeAudio = leAudioProfile.getActiveDevices().contains(device.getDevice());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return isActiveDeviceA2dp || isActiveDeviceHearingAid || isActiveLeAudio;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<DeviceCallback> getCallbacks() {
|
private Collection<DeviceCallback> getCallbacks() {
|
||||||
@@ -526,7 +536,7 @@ public class LocalMediaManager implements BluetoothCallback {
|
|||||||
if (cachedDevice != null) {
|
if (cachedDevice != null) {
|
||||||
if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED
|
if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED
|
||||||
&& !cachedDevice.isConnected()
|
&& !cachedDevice.isConnected()
|
||||||
&& isA2dpOrHearingAidDevice(cachedDevice)) {
|
&& isMediaDevice(cachedDevice)) {
|
||||||
deviceCount++;
|
deviceCount++;
|
||||||
cachedBluetoothDeviceList.add(cachedDevice);
|
cachedBluetoothDeviceList.add(cachedDevice);
|
||||||
if (deviceCount >= MAX_DISCONNECTED_DEVICE_NUM) {
|
if (deviceCount >= MAX_DISCONNECTED_DEVICE_NUM) {
|
||||||
@@ -550,9 +560,10 @@ public class LocalMediaManager implements BluetoothCallback {
|
|||||||
return new ArrayList<>(mDisconnectedMediaDevices);
|
return new ArrayList<>(mDisconnectedMediaDevices);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isA2dpOrHearingAidDevice(CachedBluetoothDevice device) {
|
private boolean isMediaDevice(CachedBluetoothDevice device) {
|
||||||
for (LocalBluetoothProfile profile : device.getConnectableProfiles()) {
|
for (LocalBluetoothProfile profile : device.getConnectableProfiles()) {
|
||||||
if (profile instanceof A2dpProfile || profile instanceof HearingAidProfile) {
|
if (profile instanceof A2dpProfile || profile instanceof HearingAidProfile ||
|
||||||
|
profile instanceof LeAudioProfile) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import static android.media.MediaRoute2Info.TYPE_USB_DEVICE;
|
|||||||
import static android.media.MediaRoute2Info.TYPE_USB_HEADSET;
|
import static android.media.MediaRoute2Info.TYPE_USB_HEADSET;
|
||||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
||||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
||||||
|
import static android.media.MediaRoute2Info.TYPE_BLE_HEADSET;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
@@ -122,6 +123,7 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
|||||||
break;
|
break;
|
||||||
case TYPE_HEARING_AID:
|
case TYPE_HEARING_AID:
|
||||||
case TYPE_BLUETOOTH_A2DP:
|
case TYPE_BLUETOOTH_A2DP:
|
||||||
|
case TYPE_BLE_HEADSET:
|
||||||
mType = MediaDeviceType.TYPE_BLUETOOTH_DEVICE;
|
mType = MediaDeviceType.TYPE_BLUETOOTH_DEVICE;
|
||||||
break;
|
break;
|
||||||
case TYPE_UNKNOWN:
|
case TYPE_UNKNOWN:
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public class BluetoothMediaDeviceTest {
|
|||||||
|
|
||||||
when(mDevice.isActiveDevice(BluetoothProfile.A2DP)).thenReturn(true);
|
when(mDevice.isActiveDevice(BluetoothProfile.A2DP)).thenReturn(true);
|
||||||
when(mDevice.isActiveDevice(BluetoothProfile.HEARING_AID)).thenReturn(true);
|
when(mDevice.isActiveDevice(BluetoothProfile.HEARING_AID)).thenReturn(true);
|
||||||
|
when(mDevice.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
|
||||||
|
|
||||||
mBluetoothMediaDevice = new BluetoothMediaDevice(mContext, mDevice, null, null, null);
|
mBluetoothMediaDevice = new BluetoothMediaDevice(mContext, mDevice, null, null, null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user