[Audiosharing] Use LE audio profile as fallback to get group id.

For non-CSIP LE audio device, use LE audio profile to get group id.

Also, did some refinement in this change.
1. Add more log
2. Use context#getMainExecutor instead, since postOnMainThread is
   deprecated.

Test: manual
Bug: 305620450
Bug: 319723439
Change-Id: I8056b2e7b6ab37915a518ad2290a0a7fb7671c18
This commit is contained in:
Yiyi Shen
2024-01-22 15:33:19 +08:00
parent a4cf715181
commit b3331f3ea4
3 changed files with 94 additions and 25 deletions

View File

@@ -418,7 +418,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
if (isBroadcasting()) {
// Show stop audio sharing dialog when an ineligible (non LE audio) remote device
// connected during a sharing session.
ThreadUtils.postOnMainThread(
postOnMainThread(
() -> {
closeOpeningDialogs();
AudioSharingStopDialogFragment.show(
@@ -442,8 +442,9 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
Map<Integer, List<CachedBluetoothDevice>> groupedDevices =
AudioSharingUtils.fetchConnectedDevicesByGroupId(mLocalBtManager);
if (isBroadcasting()) {
if (groupedDevices.containsKey(cachedDevice.getGroupId())
&& groupedDevices.get(cachedDevice.getGroupId()).stream()
int groupId = AudioSharingUtils.getGroupId(cachedDevice);
if (groupedDevices.containsKey(groupId)
&& groupedDevices.get(groupId).stream()
.anyMatch(
device ->
AudioSharingUtils.hasBroadcastSource(
@@ -463,7 +464,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
// Show audio sharing switch dialog when the third eligible (LE audio) remote device
// connected during a sharing session.
if (deviceItemsInSharingSession.size() >= 2) {
ThreadUtils.postOnMainThread(
postOnMainThread(
() -> {
closeOpeningDialogs();
AudioSharingDisconnectDialogFragment.show(
@@ -494,7 +495,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
} else {
// Show audio sharing join dialog when the first or second eligible (LE audio)
// remote device connected during a sharing session.
ThreadUtils.postOnMainThread(
postOnMainThread(
() -> {
closeOpeningDialogs();
AudioSharingJoinDialogFragment.show(
@@ -515,7 +516,8 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
for (List<CachedBluetoothDevice> devices : groupedDevices.values()) {
// Use random device in the group within the sharing session to represent the group.
CachedBluetoothDevice device = devices.get(0);
if (device.getGroupId() == cachedDevice.getGroupId()) {
if (AudioSharingUtils.getGroupId(device)
== AudioSharingUtils.getGroupId(cachedDevice)) {
continue;
}
deviceItems.add(AudioSharingUtils.buildAudioSharingDeviceItem(device));
@@ -523,7 +525,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
// Show audio sharing join dialog when the second eligible (LE audio) remote
// device connect and no sharing session.
if (deviceItems.size() == 1) {
ThreadUtils.postOnMainThread(
postOnMainThread(
() -> {
closeOpeningDialogs();
AudioSharingJoinDialogFragment.show(
@@ -599,4 +601,8 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
}
}
}
private void postOnMainThread(@NonNull Runnable runnable) {
mContext.getMainExecutor().execute(runnable);
}
}