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

Commit 55933b8e authored by Chelsea Hao's avatar Chelsea Hao Committed by Android (Google) Code Review
Browse files

Merge "Add `AvailableAudioSharingMediaDeviceItem` for devices that could...

Merge "Add `AvailableAudioSharingMediaDeviceItem` for devices that could either do audio sharing, or be set as an active media device." into main
parents 53ee1ff0 380c1769
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -740,6 +740,8 @@
    <string name="quick_settings_bluetooth_device_connected">Connected</string>
    <!-- QuickSettings: Bluetooth dialog device in audio sharing default summary [CHAR LIMIT=50]-->
    <string name="quick_settings_bluetooth_device_audio_sharing">Audio Sharing</string>
    <!-- QuickSettings: Bluetooth dialog device summary for devices that are capable of audio sharing and switching to active[CHAR LIMIT=NONE]-->
    <string name="quick_settings_bluetooth_device_audio_sharing_or_switch_active">Tap to switch or share audio</string>
    <!-- QuickSettings: Bluetooth dialog device saved default summary [CHAR LIMIT=NONE]-->
    <string name="quick_settings_bluetooth_device_saved">Saved</string>
    <!-- QuickSettings: Accessibility label to disconnect a device [CHAR LIMIT=NONE]-->
+9 −1
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ enum class BluetoothTileDialogUiEvent(val metricId: Int) : UiEventLogger.UiEvent
    @UiEvent(doc = "Saved clicked to connect") SAVED_DEVICE_CONNECT(1500),
    @UiEvent(doc = "Active device clicked to disconnect") ACTIVE_DEVICE_DISCONNECT(1507),
    @UiEvent(doc = "Audio sharing device clicked, do nothing") AUDIO_SHARING_DEVICE_CLICKED(1699),
    @UiEvent(doc = "Available audio sharing device clicked, do nothing")
    AVAILABLE_AUDIO_SHARING_DEVICE_CLICKED(1880),
    @UiEvent(doc = "Connected other device clicked to disconnect")
    CONNECTED_OTHER_DEVICE_DISCONNECT(1508),
    @UiEvent(doc = "The auto on toggle is clicked") BLUETOOTH_AUTO_ON_TOGGLE_CLICKED(1617),
@@ -44,8 +46,14 @@ enum class BluetoothTileDialogUiEvent(val metricId: Int) : UiEventLogger.UiEvent
        doc = "Not broadcasting, having one connected, another saved LE audio device is clicked"
    )
    LAUNCH_SETTINGS_NOT_SHARING_SAVED_LE_DEVICE_CLICKED(1719),
    @Deprecated(
        "Use case no longer needed",
        ReplaceWith("LAUNCH_SETTINGS_NOT_SHARING_ACTIVE_LE_DEVICE_CLICKED")
    )
    @UiEvent(doc = "Not broadcasting, one of the two connected LE audio devices is clicked")
    LAUNCH_SETTINGS_NOT_SHARING_CONNECTED_LE_DEVICE_CLICKED(1720);
    LAUNCH_SETTINGS_NOT_SHARING_CONNECTED_LE_DEVICE_CLICKED(1720),
    @UiEvent(doc = "Not broadcasting, having two connected, the active LE audio devices is clicked")
    LAUNCH_SETTINGS_NOT_SHARING_ACTIVE_LE_DEVICE_CLICKED(1881);

    override fun getId() = metricId
}
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice
enum class DeviceItemType {
    ACTIVE_MEDIA_BLUETOOTH_DEVICE,
    AUDIO_SHARING_MEDIA_BLUETOOTH_DEVICE,
    AVAILABLE_AUDIO_SHARING_MEDIA_BLUETOOTH_DEVICE,
    AVAILABLE_MEDIA_BLUETOOTH_DEVICE,
    CONNECTED_BLUETOOTH_DEVICE,
    SAVED_BLUETOOTH_DEVICE,
+14 −10
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ constructor(
                    backgroundDispatcher,
                    logger
                ),
                NotSharingClickedConnected(
                NotSharingClickedActive(
                    leAudioProfile,
                    assistantProfile,
                    backgroundDispatcher,
@@ -106,6 +106,12 @@ constructor(
                    DeviceItemType.AUDIO_SHARING_MEDIA_BLUETOOTH_DEVICE -> {
                        uiEventLogger.log(BluetoothTileDialogUiEvent.AUDIO_SHARING_DEVICE_CLICKED)
                    }
                    DeviceItemType.AVAILABLE_AUDIO_SHARING_MEDIA_BLUETOOTH_DEVICE -> {
                        // TODO(b/360759048): pop up dialog
                        uiEventLogger.log(
                            BluetoothTileDialogUiEvent.AVAILABLE_AUDIO_SHARING_DEVICE_CLICKED
                        )
                    }
                    DeviceItemType.AVAILABLE_MEDIA_BLUETOOTH_DEVICE -> {
                        setActive()
                        uiEventLogger.log(BluetoothTileDialogUiEvent.CONNECTED_DEVICE_SET_ACTIVE)
@@ -238,14 +244,14 @@ constructor(
            BluetoothTileDialogUiEvent.LAUNCH_SETTINGS_NOT_SHARING_SAVED_LE_DEVICE_CLICKED
    }

    private class NotSharingClickedConnected(
    private class NotSharingClickedActive(
        private val leAudioProfile: LeAudioProfile?,
        private val assistantProfile: LocalBluetoothLeBroadcastAssistant?,
        @Background private val backgroundDispatcher: CoroutineDispatcher,
        private val logger: BluetoothTileDialogLogger,
    ) : LaunchSettingsCriteria {
        // If not broadcasting, having two device connected, clicked on any connected LE audio
        // devices
        // If not broadcasting, having two device connected, clicked on the active LE audio
        // device
        override suspend fun matched(inAudioSharing: Boolean, deviceItem: DeviceItem): Boolean {
            return withContext(backgroundDispatcher) {
                val matched =
@@ -259,7 +265,7 @@ constructor(
                                        logger
                                    )
                                    .size == 2 &&
                                deviceItem.isActiveOrConnectedLeAudioSupported
                                deviceItem.isActiveLeAudioSupported
                        }
                    } ?: false

@@ -275,7 +281,7 @@ constructor(
        }

        override suspend fun getClickUiEvent(deviceItem: DeviceItem) =
            BluetoothTileDialogUiEvent.LAUNCH_SETTINGS_NOT_SHARING_CONNECTED_LE_DEVICE_CLICKED
            BluetoothTileDialogUiEvent.LAUNCH_SETTINGS_NOT_SHARING_ACTIVE_LE_DEVICE_CLICKED
    }

    private companion object {
@@ -290,10 +296,8 @@ constructor(
        val DeviceItem.isNotConnectedLeAudioSupported: Boolean
            get() = type == DeviceItemType.SAVED_BLUETOOTH_DEVICE && isLeAudioSupported

        val DeviceItem.isActiveOrConnectedLeAudioSupported: Boolean
            get() =
                (type == DeviceItemType.ACTIVE_MEDIA_BLUETOOTH_DEVICE ||
                    type == DeviceItemType.AVAILABLE_MEDIA_BLUETOOTH_DEVICE) && isLeAudioSupported
        val DeviceItem.isActiveLeAudioSupported: Boolean
            get() = type == DeviceItemType.ACTIVE_MEDIA_BLUETOOTH_DEVICE && isLeAudioSupported

        val DeviceItem.isMediaDevice: Boolean
            get() =
+31 −0
Original line number Diff line number Diff line
@@ -125,6 +125,37 @@ internal class AudioSharingMediaDeviceItemFactory(
    }
}

internal class AvailableAudioSharingMediaDeviceItemFactory(
    private val localBluetoothManager: LocalBluetoothManager?
) : AvailableMediaDeviceItemFactory() {
    override fun isFilterMatched(
        context: Context,
        cachedDevice: CachedBluetoothDevice,
        audioManager: AudioManager
    ): Boolean {
        return BluetoothUtils.isAudioSharingEnabled() &&
            super.isFilterMatched(context, cachedDevice, audioManager) &&
            BluetoothUtils.isAvailableAudioSharingMediaBluetoothDevice(
                cachedDevice,
                localBluetoothManager
            )
    }

    override fun create(context: Context, cachedDevice: CachedBluetoothDevice): DeviceItem {
        return createDeviceItem(
            context,
            cachedDevice,
            DeviceItemType.AVAILABLE_AUDIO_SHARING_MEDIA_BLUETOOTH_DEVICE,
            context.getString(
                R.string.quick_settings_bluetooth_device_audio_sharing_or_switch_active
            ),
            if (cachedDevice.isBusy) backgroundOffBusy else backgroundOff,
            "",
            isActive = false
        )
    }
}

internal class ActiveHearingDeviceItemFactory : ActiveMediaDeviceItemFactory() {
    override fun isFilterMatched(
        context: Context,
Loading