Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dbcd0dd8 authored by Yiyi Shen's avatar Yiyi Shen
Browse files

[Audiosharing] Fix primary device summary in call

During call, BT stack will keep the broadcast in a hysteresis mode,
however BT stack will remove the fallback group id, which leads the
primary device summary shows "Active (media only) even though it is listening to the call.

Here we check if there is active device on LE_AUDIO
profile when the fallback group id is removed. The active device on
LE_AUDIO profile should be the primary device in call.

Test: atest
Bug: 355222285
Bug: 362714470
Flag: com.android.settingslib.flags.enable_le_audio_sharing
Change-Id: I7d32c1951aca22bbc3087985389f983eea45cc94
parent 2c52955a
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import android.os.Looper;
import android.os.Message;
import android.os.ParcelUuid;
import android.os.SystemClock;
import android.provider.Settings;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
@@ -1291,12 +1290,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        if (BluetoothUtils.hasConnectedBroadcastSource(this, mBluetoothManager)) {
            // Gets summary for the buds which are in the audio sharing.
            int groupId = BluetoothUtils.getGroupId(this);
            if (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
                    && groupId
                            == Settings.Secure.getInt(
                                    mContext.getContentResolver(),
                                    "bluetooth_le_broadcast_fallback_active_group_id",
                                    BluetoothCsipSetCoordinator.GROUP_ID_INVALID)) {
            int primaryGroupId = BluetoothUtils.getPrimaryGroupIdForBroadcast(
                    mContext.getContentResolver());
            if ((primaryGroupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID)
                    ? (groupId == primaryGroupId) : isActiveDevice(BluetoothProfile.LE_AUDIO)) {
                // The buds are primary buds
                return getSummaryWithBatteryInfo(
                        R.string.bluetooth_active_battery_level_untethered,
+27 −9
Original line number Diff line number Diff line
@@ -1977,12 +1977,12 @@ public class CachedBluetoothDeviceTest {
    }

    @Test
    public void getConnectionSummary_isBroadcastPrimary_returnActive() {
    public void getConnectionSummary_isBroadcastPrimary_fallbackDevice_returnActive() {
        when(mBroadcast.isEnabled(any())).thenReturn(true);
        when(mCachedDevice.getDevice()).thenReturn(mDevice);
        Settings.Secure.putInt(
                mContext.getContentResolver(),
                "bluetooth_le_broadcast_fallback_active_group_id",
                BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
                1);

        List<Long> bisSyncState = new ArrayList<>();
@@ -1992,12 +1992,30 @@ public class CachedBluetoothDeviceTest {
        sourceList.add(mLeBroadcastReceiveState);
        when(mAssistant.getAllSources(any())).thenReturn(sourceList);

        when(mCachedDevice.getGroupId())
                .thenReturn(
                        Settings.Secure.getInt(
        when(mCachedDevice.getGroupId()).thenReturn(1);

        assertThat(mCachedDevice.getConnectionSummary(false))
                .isEqualTo(mContext.getString(R.string.bluetooth_active_no_battery_level));
    }

    @Test
    public void getConnectionSummary_isBroadcastPrimary_activeDevice_returnActive() {
        when(mBroadcast.isEnabled(any())).thenReturn(true);
        when(mCachedDevice.getDevice()).thenReturn(mDevice);
        Settings.Secure.putInt(
                mContext.getContentResolver(),
                                "bluetooth_le_broadcast_fallback_active_group_id",
                                BluetoothCsipSetCoordinator.GROUP_ID_INVALID));
                BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
                BluetoothCsipSetCoordinator.GROUP_ID_INVALID);

        List<Long> bisSyncState = new ArrayList<>();
        bisSyncState.add(1L);
        when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState);
        List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>();
        sourceList.add(mLeBroadcastReceiveState);
        when(mAssistant.getAllSources(any())).thenReturn(sourceList);

        when(mCachedDevice.getGroupId()).thenReturn(1);
        when(mCachedDevice.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);

        assertThat(mCachedDevice.getConnectionSummary(false))
                .isEqualTo(mContext.getString(R.string.bluetooth_active_no_battery_level));
@@ -2009,7 +2027,7 @@ public class CachedBluetoothDeviceTest {
        when(mCachedDevice.getDevice()).thenReturn(mDevice);
        Settings.Secure.putInt(
                mContext.getContentResolver(),
                "bluetooth_le_broadcast_fallback_active_group_id",
                BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
                1);

        List<Long> bisSyncState = new ArrayList<>();