[Audiosharing] Sort sharing candidates in Utils.

The active device is placed before the inactive one.
The bonded device is placed before the unbonded one.
The device with earlier bond timestamp is placed before the later one.
Otherwise, the device is ordered by name.

Flagged with enable_le_audio_sharing

Bug: 305620450
Test: Manual
Change-Id: Ie1eea7361fbed1635313b92790cec034cf669bbf
This commit is contained in:
Yiyi Shen
2023-11-21 15:24:29 +08:00
parent 6bb2c73579
commit 1e71a03e65
3 changed files with 175 additions and 43 deletions

View File

@@ -62,14 +62,6 @@ public class CallsAndAlarmsPreferenceController extends AudioSharingBasePreferen
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
updateDeviceItemsInSharingSession();
// mDeviceItemsInSharingSession is ordered. The active device is the first place if exits.
if (!mDeviceItemsInSharingSession.isEmpty()
&& mDeviceItemsInSharingSession.get(0).isActive()) {
mPreference.setSummary(mDeviceItemsInSharingSession.get(0).getName());
} else {
mPreference.setSummary("");
}
mPreference.setOnPreferenceClickListener(
preference -> {
if (mFragment == null) {
@@ -106,6 +98,22 @@ public class CallsAndAlarmsPreferenceController extends AudioSharingBasePreferen
}
}
@Override
public void updateVisibility(boolean isVisible) {
super.updateVisibility(isVisible);
if (isVisible && mPreference != null) {
updateDeviceItemsInSharingSession();
// mDeviceItemsInSharingSession is ordered. The active device is the first place if
// exits.
if (!mDeviceItemsInSharingSession.isEmpty()
&& mDeviceItemsInSharingSession.get(0).isActive()) {
mPreference.setSummary(mDeviceItemsInSharingSession.get(0).getName());
} else {
mPreference.setSummary("");
}
}
}
@Override
public void onActiveDeviceChanged(
@Nullable CachedBluetoothDevice activeDevice, int bluetoothProfile) {
@@ -129,7 +137,7 @@ public class CallsAndAlarmsPreferenceController extends AudioSharingBasePreferen
mGroupedConnectedDevices =
AudioSharingUtils.fetchConnectedDevicesByGroupId(mLocalBtManager);
mDeviceItemsInSharingSession =
AudioSharingUtils.buildOrderedDeviceItemsInSharingSession(
mGroupedConnectedDevices, mLocalBtManager);
AudioSharingUtils.buildOrderedConnectedLeadAudioSharingDeviceItem(
mLocalBtManager, mGroupedConnectedDevices, /* filterByInSharing= */ true);
}
}