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

Commit 1179af39 authored by Patty's avatar Patty
Browse files

Disable le audio service if controller is not supported

Tag: #feature
Bug: 204148572
Bug: 150670922
Test: atest BluetoothInstrumentationTests
Change-Id: If28b559cba61bebcb0dcad248b4b03e781a83347
parent f5028672
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -931,6 +931,8 @@ class AdapterProperties {

                    case AbstractionLayer.BT_PROPERTY_LOCAL_LE_FEATURES:
                        updateFeatureSupport(val);
                        mService.updateLeAudioProfileServiceState(
                                mIsLeConnectedIsochronousStreamCentralSupported);
                        break;

                    case AbstractionLayer.BT_PROPERTY_DYNAMIC_AUDIO_BUFFER:
+17 −0
Original line number Diff line number Diff line
@@ -713,6 +713,23 @@ public class AdapterService extends Service {
        BluetoothAdapter.invalidateBluetoothGetStateCache();
    }

    void updateLeAudioProfileServiceState(boolean isCisCentralSupported) {
        if (isCisCentralSupported) {
            return;
        }

        // Remove the Le audio unicast profiles from the supported list
        // since the controller doesn't support
        Config.removeLeAudioUnicastProfilesFromSupportedList();
        HashSet<Class> leAudioUnicastProfiles = Config.geLeAudioUnicastProfiles();

        for (Class profileService : leAudioUnicastProfiles) {
            if (isStartedProfile(profileService.getSimpleName())){
                setProfileServiceState(profileService, BluetoothAdapter.STATE_OFF);
            }
        }
    }

    void updateAdapterState(int prevState, int newState) {
        mAdapterProperties.setState(newState);
        invalidateBluetoothGetStateCache();
+35 −0
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@ import com.android.bluetooth.sap.SapService;
import com.android.bluetooth.vc.VolumeControlService;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

public class Config {
@@ -68,6 +71,15 @@ public class Config {
        }
    }

    /**
     * List of profile services related to LE audio
     */
    private static final HashSet<Class> mLeAudioUnicastProfiles = new HashSet<Class>(
            Arrays.asList(LeAudioService.class,
                        VolumeControlService.class,
                        McpService.class,
                        CsipSetCoordinatorService.class));

    /**
     * List of profile services with the profile-supported resource flag and bit mask.
     */
@@ -157,6 +169,29 @@ public class Config {
        sIsGdEnabledUptoScanningLayer = resources.getBoolean(R.bool.enable_gd_up_to_scanning_layer);
    }

    /**
     * Remove LE audio unicast related profiles from the supported list.
     */
    static void removeLeAudioUnicastProfilesFromSupportedList() {
        ArrayList<Class> profilesList = new ArrayList<Class>(Arrays.asList(sSupportedProfiles));
        Iterator<Class> iter = profilesList.iterator();

        while (iter.hasNext()) {
            Class profileClass = iter.next();

            if (mLeAudioUnicastProfiles.contains(profileClass)) {
                iter.remove();
                Log.v(TAG, "Remove " + profileClass.getSimpleName() + " from supported list.");
            }
        }

        sSupportedProfiles = profilesList.toArray(new Class[profilesList.size()]);
    }

    static HashSet<Class> geLeAudioUnicastProfiles() {
        return mLeAudioUnicastProfiles;
    }

    static Class[] getSupportedProfiles() {
        return sSupportedProfiles;
    }