[LE Audio] Add LE Audio Devices in Sound Settings
- When connected to the LE Audio Device, it will display "Play XXX on LEAduioDeviceName" in Sound Settings. - When connected to the LE Audio Device, it will display the LE Audio device name in the "Take call on" list for you having a active call(Hands Free). - Remove the @Ignore annotation for all the tests and make test cases pass. Bug: 240911615 Bug: 243494881 Test: manual test Test: make RunSettingsRoboTests ROBOTEST_FILTER=AudioOutputSwitchPreferenceControllerTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=HandsFreeProfileOutputPreferenceControllerTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=MediaOutputPreferenceControllerTest Change-Id: I10db59b33623495a9e9933556c78e20d81e405ea
This commit is contained in:
@@ -45,6 +45,7 @@ import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.HeadsetProfile;
|
||||
import com.android.settingslib.bluetooth.HearingAidProfile;
|
||||
import com.android.settingslib.bluetooth.LeAudioProfile;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
@@ -214,6 +215,25 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
|
||||
return a2dpProfile.getConnectedDevices();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get LE Audio profile connected devices
|
||||
*/
|
||||
protected List<BluetoothDevice> getConnectedLeAudioDevices() {
|
||||
final List<BluetoothDevice> connectedDevices = new ArrayList<>();
|
||||
final LeAudioProfile leAudioProfile = mProfileManager.getLeAudioProfile();
|
||||
if (leAudioProfile == null) {
|
||||
Log.d(TAG, "LeAudioProfile is null");
|
||||
return connectedDevices;
|
||||
}
|
||||
final List<BluetoothDevice> devices = leAudioProfile.getConnectedDevices();
|
||||
for (BluetoothDevice device : devices) {
|
||||
if (device.isConnected()) {
|
||||
connectedDevices.add(device);
|
||||
}
|
||||
}
|
||||
return connectedDevices;
|
||||
}
|
||||
|
||||
/**
|
||||
* get hearing aid profile connected device, exclude other devices with same hiSyncId.
|
||||
*/
|
||||
@@ -259,6 +279,24 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find active LE Audio device
|
||||
*/
|
||||
protected BluetoothDevice findActiveLeAudioDevice() {
|
||||
final LeAudioProfile leAudioProfile = mProfileManager.getLeAudioProfile();
|
||||
|
||||
if (leAudioProfile != null) {
|
||||
List<BluetoothDevice> activeDevices = leAudioProfile.getActiveDevices();
|
||||
for (BluetoothDevice leAudioDevice : activeDevices) {
|
||||
if (leAudioDevice != null) {
|
||||
return leAudioDevice;
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "There is no LE audio profile or no active LE audio device");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the active device from the corresponding profile.
|
||||
*
|
||||
|
@@ -103,6 +103,7 @@ public class HandsFreeProfileOutputPreferenceController extends AudioSwitchPrefe
|
||||
mConnectedDevices.clear();
|
||||
mConnectedDevices.addAll(getConnectedHfpDevices());
|
||||
mConnectedDevices.addAll(getConnectedHearingAidDevices());
|
||||
mConnectedDevices.addAll(getConnectedLeAudioDevices());
|
||||
|
||||
final int numDevices = mConnectedDevices.size();
|
||||
if (numDevices == 0) {
|
||||
@@ -181,12 +182,22 @@ public class HandsFreeProfileOutputPreferenceController extends AudioSwitchPrefe
|
||||
|
||||
@Override
|
||||
public BluetoothDevice findActiveDevice() {
|
||||
BluetoothDevice activeDevice = findActiveHearingAidDevice();
|
||||
BluetoothDevice haActiveDevice = findActiveHearingAidDevice();
|
||||
BluetoothDevice leAudioActiveDevice = findActiveLeAudioDevice();
|
||||
final HeadsetProfile headsetProfile = mProfileManager.getHeadsetProfile();
|
||||
|
||||
if (activeDevice == null && headsetProfile != null) {
|
||||
activeDevice = headsetProfile.getActiveDevice();
|
||||
if (haActiveDevice != null) {
|
||||
return haActiveDevice;
|
||||
}
|
||||
return activeDevice;
|
||||
|
||||
if (leAudioActiveDevice != null) {
|
||||
return leAudioActiveDevice;
|
||||
}
|
||||
|
||||
if (headsetProfile != null && headsetProfile.getActiveDevice() != null) {
|
||||
return headsetProfile.getActiveDevice();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -88,9 +88,11 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
|
||||
// Find active device and set its name as the preference's summary
|
||||
List<BluetoothDevice> connectedA2dpDevices = getConnectedA2dpDevices();
|
||||
List<BluetoothDevice> connectedHADevices = getConnectedHearingAidDevices();
|
||||
List<BluetoothDevice> connectedLeAudioDevices = getConnectedLeAudioDevices();
|
||||
if (mAudioManager.getMode() == AudioManager.MODE_NORMAL
|
||||
&& ((connectedA2dpDevices != null && !connectedA2dpDevices.isEmpty())
|
||||
|| (connectedHADevices != null && !connectedHADevices.isEmpty()))) {
|
||||
|| (connectedHADevices != null && !connectedHADevices.isEmpty())
|
||||
|| (connectedLeAudioDevices != null && !connectedLeAudioDevices.isEmpty()))) {
|
||||
activeDevice = findActiveDevice();
|
||||
}
|
||||
mPreference.setTitle(mContext.getString(R.string.media_output_label_title,
|
||||
@@ -103,13 +105,23 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
|
||||
|
||||
@Override
|
||||
public BluetoothDevice findActiveDevice() {
|
||||
BluetoothDevice activeDevice = findActiveHearingAidDevice();
|
||||
BluetoothDevice haActiveDevice = findActiveHearingAidDevice();
|
||||
BluetoothDevice leAudioActiveDevice = findActiveLeAudioDevice();
|
||||
final A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile();
|
||||
|
||||
if (activeDevice == null && a2dpProfile != null) {
|
||||
activeDevice = a2dpProfile.getActiveDevice();
|
||||
if (haActiveDevice != null) {
|
||||
return haActiveDevice;
|
||||
}
|
||||
return activeDevice;
|
||||
|
||||
if (leAudioActiveDevice != null) {
|
||||
return leAudioActiveDevice;
|
||||
}
|
||||
|
||||
if (a2dpProfile != null && a2dpProfile.getActiveDevice() != null) {
|
||||
return a2dpProfile.getActiveDevice();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user