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

Commit 17dfcbc6 authored by Alice Kuo's avatar Alice Kuo
Browse files

LE audio unicast / broadcast dynamic switch refactor

Refactor LE audio dynamic switch logic. Add an new properties to
switch le audio mode as broadcast enabled to reduce to skip the broadcast
enabled without unicast enabled scenairo for simplicity

Bug: 316005152
Bug: 317516854
Test: m com.android.btservices
Change-Id: I4df9cb5f12fddfdc43ffc7bfd67f35565c9d7a59
parent 3ceb3d2d
Loading
Loading
Loading
Loading
+32 −17
Original line number Diff line number Diff line
@@ -57,11 +57,14 @@ public class Config {

    private static final String LE_AUDIO_DYNAMIC_SWITCH_PROPERTY =
            "ro.bluetooth.leaudio_switcher.supported";
    private static final String LE_AUDIO_BROADCAST_DYNAMIC_SWITCH_PROPERTY =
            "ro.bluetooth.leaudio_broadcast_switcher.supported";
    private static final String LE_AUDIO_SWITCHER_DISABLED_PROPERTY =
            "persist.bluetooth.leaudio_switcher.disabled";

    // Three modes, 1. "disabled" - all LE audio feature off. 2. "unicast" - Unicast enabled only.
    // 3. "broadcast" - Unicast + broadcast enabled
    private static final String LE_AUDIO_DYNAMIC_SWITCHER_MODE_PROPERTY =
            "persist.bluetooth.leaudio_dynamic_switcher.mode";

    private static class ProfileConfig {
        boolean mSupported;
        int mProfileId;
@@ -125,6 +128,20 @@ public class Config {
    }

    static void init(Context ctx) {
        if (LeAudioService.isBroadcastEnabled()) {
            final String leAudioSwitcherMode =
                    SystemProperties.get(LE_AUDIO_DYNAMIC_SWITCHER_MODE_PROPERTY, "none");
            if (leAudioSwitcherMode.equals("disabled")) {
                setLeAudioProfileStatus(false);
                setLeAudioBroadcastProfileStatus(false);
            } else if (leAudioSwitcherMode.equals("unicast")) {
                setLeAudioProfileStatus(true);
                setLeAudioBroadcastProfileStatus(false);
            } else if (leAudioSwitcherMode.equals("broadcast")) {
                setLeAudioProfileStatus(true);
                setLeAudioBroadcastProfileStatus(true);
            }
        } else if (LeAudioService.isEnabled()) {
            final boolean leAudioDynamicSwitchSupported =
                    SystemProperties.getBoolean(LE_AUDIO_DYNAMIC_SWITCH_PROPERTY, false);

@@ -137,6 +154,7 @@ public class Config {
                    setLeAudioProfileStatus(true);
                }
            }
        }

        // Disable ASHA on Automotive, TV, and Watch devices if the system property is not set
        // This means that the OS will not automatically enable ASHA on these platforms, but these
@@ -169,15 +187,12 @@ public class Config {
        setProfileEnabled(BluetoothProfile.LE_CALL_CONTROL, enable);
        setProfileEnabled(BluetoothProfile.MCP_SERVER, enable);
        setProfileEnabled(BluetoothProfile.VOLUME_CONTROL, enable);
    }

        final boolean broadcastDynamicSwitchSupported =
                SystemProperties.getBoolean(LE_AUDIO_BROADCAST_DYNAMIC_SWITCH_PROPERTY, false);

        if (broadcastDynamicSwitchSupported) {
    static void setLeAudioBroadcastProfileStatus(Boolean enable) {
        setProfileEnabled(BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT, enable);
        setProfileEnabled(BluetoothProfile.LE_AUDIO_BROADCAST, enable);
    }
    }

    static int[] getLeAudioUnicastProfiles() {
        return LE_AUDIO_UNICAST_PROFILES;