Merge "[Audiosharing] Use getBroadcastToUnicastFallbackGroup to get primary" into main

This commit is contained in:
Yiyi Shen
2025-03-16 22:15:17 -07:00
committed by Android (Google) Code Review
6 changed files with 416 additions and 55 deletions

View File

@@ -207,7 +207,7 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
(AudioSharingDeviceItem item) -> {
int currentCallAudioGroupId =
BluetoothUtils.getPrimaryGroupIdForBroadcast(
mContext.getContentResolver());
mContext.getContentResolver(), mBtManager);
int clickedGroupId = item.getGroupId();
if (clickedGroupId == currentCallAudioGroupId) {
Log.d(TAG, "Skip set call audio device: unchanged");
@@ -414,7 +414,8 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
private Pair<Integer, AudioSharingDeviceItem> getActiveItemWithIndex() {
List<AudioSharingDeviceItem> deviceItems = new ArrayList<>(mDeviceItemsInSharingSession);
int fallbackActiveGroupId =
BluetoothUtils.getPrimaryGroupIdForBroadcast(mContext.getContentResolver());
BluetoothUtils.getPrimaryGroupIdForBroadcast(mContext.getContentResolver(),
mBtManager);
if (fallbackActiveGroupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
for (AudioSharingDeviceItem item : deviceItems) {
if (item.getGroupId() == fallbackActiveGroupId) {

View File

@@ -418,7 +418,8 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre
int groupId = BluetoothUtils.getGroupId(cachedDevice);
// The fallback device rank first among the audio sharing device list.
return (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
&& groupId == BluetoothUtils.getPrimaryGroupIdForBroadcast(mContentResolver))
&& groupId == BluetoothUtils.getPrimaryGroupIdForBroadcast(mContentResolver,
mBtManager))
? 0
: 1;
}

View File

@@ -46,6 +46,7 @@ public class AudioSharingDeviceVolumePreference extends SeekBarPreference {
private final Context mContext;
private final CachedBluetoothDevice mCachedDevice;
@Nullable private final LocalBluetoothManager mBtManager;
@Nullable protected SeekBar mSeekBar;
private Boolean mTrackingTouch = false;
private MetricsFeatureProvider mMetricsFeatureProvider =
@@ -57,6 +58,7 @@ public class AudioSharingDeviceVolumePreference extends SeekBarPreference {
setLayoutResource(R.layout.preference_volume_slider);
mContext = context;
mCachedDevice = device;
mBtManager = Utils.getLocalBtManager(mContext);
}
@NonNull
@@ -110,7 +112,7 @@ public class AudioSharingDeviceVolumePreference extends SeekBarPreference {
if (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
&& groupId
== BluetoothUtils.getPrimaryGroupIdForBroadcast(
mContext.getContentResolver())) {
mContext.getContentResolver(), mBtManager)) {
// Set media stream volume for primary buds, audio manager will
// update all buds volume in the audio sharing.
setAudioManagerStreamVolume(progress);
@@ -126,9 +128,8 @@ public class AudioSharingDeviceVolumePreference extends SeekBarPreference {
Log.d(TAG, "Skip set device volume, device is null");
return;
}
LocalBluetoothManager btManager = Utils.getLocalBtManager(mContext);
VolumeControlProfile vc =
btManager == null ? null : btManager.getProfileManager().getVolumeControlProfile();
VolumeControlProfile vc = mBtManager == null ? null
: mBtManager.getProfileManager().getVolumeControlProfile();
if (vc != null) {
vc.setDeviceVolume(device, progress, /* isGroupOp= */ true);
mMetricsFeatureProvider.action(