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

Commit a2e5fc08 authored by chelseahao's avatar chelseahao
Browse files

Show share audio button only when assistant profile is connected.

Flag: com.android.settingslib.flags.enable_le_audio_sharing
Test: atest
Bug: 400367079
Change-Id: I13168dd54cef6b8d3f60d491a0971ae72731c20f
parent c10e66c9
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ constructor(
        combine(
                bluetoothStateInteractor.bluetoothStateUpdate,
                deviceItemInteractor.deviceItemUpdate,
                audioSharingInteractor.isAudioSharingOn
                audioSharingInteractor.isAudioSharingOn,
            ) { bluetoothState, deviceItem, audioSharingOn ->
                getButtonState(bluetoothState, deviceItem, audioSharingOn)
            }
@@ -70,7 +70,7 @@ constructor(
    private fun getButtonState(
        bluetoothState: Boolean,
        deviceItem: List<DeviceItem>,
        audioSharingOn: Boolean
        audioSharingOn: Boolean,
    ): AudioSharingButtonState {
        return when {
            // Don't show button when bluetooth is off
@@ -79,20 +79,22 @@ constructor(
            audioSharingOn ->
                AudioSharingButtonState.Visible(
                    R.string.quick_settings_bluetooth_audio_sharing_button_sharing,
                    isActive = true
                    isActive = true,
                )
            // When not broadcasting, don't show button if there's connected source in any device
            deviceItem.any {
                BluetoothUtils.hasConnectedBroadcastSource(
                    it.cachedBluetoothDevice,
                    localBluetoothManager
                    localBluetoothManager,
                )
            } -> AudioSharingButtonState.Gone
            // Show audio sharing when there's a connected LE audio device
            deviceItem.any { BluetoothUtils.isActiveLeAudioDevice(it.cachedBluetoothDevice) } ->
            // Show audio sharing when there's a device connecting to the LE audio assistant profile
            deviceItem.any {
                it.cachedBluetoothDevice.isConnectedLeAudioBroadcastAssistantDevice
            } ->
                AudioSharingButtonState.Visible(
                    R.string.quick_settings_bluetooth_audio_sharing_button,
                    isActive = false
                    isActive = false,
                )
            else -> AudioSharingButtonState.Gone
        }
+2 −1
Original line number Diff line number Diff line
@@ -159,6 +159,8 @@ class AudioSharingButtonViewModelTest : SysuiTestCase() {
            val actual by
                collectLastValue(audioSharingButtonViewModel.audioSharingButtonStateUpdate)
            kosmos.bluetoothTileDialogAudioSharingRepository.setAudioSharingAvailable(true)
            whenever(cachedBluetoothDevice.isConnectedLeAudioBroadcastAssistantDevice)
                .thenReturn(true)
            whenever(deviceItem.cachedBluetoothDevice).thenReturn(cachedBluetoothDevice)
            whenever(
                    BluetoothUtils.hasConnectedBroadcastSource(
@@ -167,7 +169,6 @@ class AudioSharingButtonViewModelTest : SysuiTestCase() {
                    )
                )
                .thenReturn(false)
            whenever(BluetoothUtils.isActiveLeAudioDevice(cachedBluetoothDevice)).thenReturn(true)
            bluetoothState.value = true
            runCurrent()
            deviceItemUpdate.emit(listOf(deviceItem))