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

Commit de0984d8 authored by Yiyi Shen's avatar Yiyi Shen Committed by Android (Google) Code Review
Browse files

Merge "[Audiosharing] Fix primary device summary in call" into main

parents 1d4edc60 dbcd0dd8
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<>();