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

Commit c1f3eb83 authored by chelseahao's avatar chelseahao
Browse files

Return empty set instead of `UNKNOWN_CHANNEL` when selected channel is empty.

Flag: com.android.settingslib.flags.audio_stream_play_pause_by_modify_source
Test: atest
Bug: 384976631
Change-Id: I7700ef379217a9b84ac9323b4ecb584d4ff0a94d
parent 7499b8a6
Loading
Loading
Loading
Loading
+3 −11
Original line number Diff line number Diff line
@@ -61,7 +61,6 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
@@ -1338,16 +1337,9 @@ public class BluetoothUtils {
            Log.d(TAG, "getSelectedChannelIndex(): subgroup is null or empty");
            return UNKNOWN_CHANNEL;
        }
        Set<Integer> selectedChannels =
                subgroups.getFirst().getChannels().stream().filter(
        return subgroups.getFirst().getChannels().stream().filter(
                BluetoothLeBroadcastChannel::isSelected).map(
                        BluetoothLeBroadcastChannel::getChannelIndex).collect(
                        toSet());
        if (selectedChannels == null || selectedChannels.isEmpty()) {
            Log.d(TAG, "getSelectedChannelIndex(): selected channel is null or empty");
            return UNKNOWN_CHANNEL;
        }
        return new HashSet<>(selectedChannels);
                BluetoothLeBroadcastChannel::getChannelIndex).collect(toSet());
    }

    /**
+3 −3
Original line number Diff line number Diff line
@@ -447,8 +447,8 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                    var sourceState = sourceStateAndSelectedChannel.first;
                    var selectedChannel = sourceStateAndSelectedChannel.second;
                    if (sourceState == STREAMING || sourceState == DECRYPTION_FAILED
                            || (mHysteresisModeFixAvailable && sourceState == PAUSED) ||
                            (Flags.audioStreamPlayPauseByModifySource()
                            || (mHysteresisModeFixAvailable && sourceState == PAUSED)
                            || (Flags.audioStreamPlayPauseByModifySource()
                            && sourceState == PAUSED_BY_RECEIVER)) {
                        List<BluetoothLeAudioContentMetadata> subgroupMetadata =
                                state.getSubgroupMetadata();
+3 −3
Original line number Diff line number Diff line
@@ -645,12 +645,12 @@ public class LocalBluetoothLeBroadcastAssistant implements LocalBluetoothProfile
        Set<Integer> selectedChannelIndex = BluetoothUtils.getSelectedChannelIndex(
                profileManager, sink, sourceId);
        if (localSourceState == LocalBluetoothLeBroadcastSourceState.PAUSED
                && selectedChannelIndex.equals(UNKNOWN_CHANNEL)) {
                && selectedChannelIndex.isEmpty()) {
            // No channel selected meaning the user decided to de-sync to the source, we return
            // `RECEIVER_PAUSED`. In contrast, having any channel selected meaning the source
            // `PAUSED_BY_RECEIVER`. In contrast, having any channel selected meaning the source
            // paused itself, we return `PAUSED`.
            return Pair.create(LocalBluetoothLeBroadcastSourceState.PAUSED_BY_RECEIVER,
                    UNKNOWN_CHANNEL);
                    selectedChannelIndex);
        }
        return Pair.create(localSourceState, selectedChannelIndex);
    }
+2 −2
Original line number Diff line number Diff line
@@ -1569,7 +1569,7 @@ public class BluetoothUtilsTest {
        when(mockMetadata.getSubgroups()).thenReturn(singletonList(mockSubgroup));
        when(mAssistant.getSourceMetadata(mBluetoothDevice, 1)).thenReturn(mockMetadata);
        Set<Integer> result = getSelectedChannelIndex(mProfileManager, mBluetoothDevice, 1);
        assertEquals(UNKNOWN_CHANNEL, result);
        assertThat(result).isEmpty();
    }

    @Test
@@ -1583,7 +1583,7 @@ public class BluetoothUtilsTest {
        when(mockMetadata.getSubgroups()).thenReturn(singletonList(mockSubgroup));
        when(mAssistant.getSourceMetadata(mBluetoothDevice, 1)).thenReturn(mockMetadata);
        Set<Integer> result = getSelectedChannelIndex(mProfileManager, mBluetoothDevice, 1);
        assertEquals(UNKNOWN_CHANNEL, result);
        assertThat(result).isEmpty();
    }

    @Test