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

Commit d9fe924d authored by Patty Huang's avatar Patty Huang
Browse files

Check the service is in the supported profile list instead of using system property

The value of system property will not be overridden if user enable
the LE Audio related service via developer option. Checks the service
is enabled or not by the supported list instead of the system property.

Bug: 236553729
Tag: #refactor
Test: manual
Ignore-AOSP-First: will be cherry-picked

Change-Id: I6c40123a390513bf905f3dd531cabd5609064fdd
parent d0fe24b7
Loading
Loading
Loading
Loading
+32 −2
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -217,6 +218,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
    private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock();
    private boolean mBinding;
    private boolean mUnbinding;
    private List<Integer> mSupportedProfileList = new ArrayList<>();

    private BluetoothModeChangeHelper mBluetoothModeChangeHelper;

@@ -871,6 +873,25 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
        recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
    }

    @GuardedBy("mBluetoothLock")
    private List<Integer> synchronousGetSupportedProfiles(AttributionSource attributionSource)
            throws RemoteException, TimeoutException {
        final ArrayList<Integer> supportedProfiles = new ArrayList<Integer>();
        if (mBluetooth == null) return supportedProfiles;
        final SynchronousResultReceiver<Long> recv = SynchronousResultReceiver.get();
        mBluetooth.getSupportedProfiles(attributionSource, recv);
        final long supportedProfilesBitMask =
                recv.awaitResultNoInterrupt(getSyncTimeout()).getValue((long) 0);

        for (int i = 0; i <= BluetoothProfile.MAX_PROFILE_ID; i++) {
            if ((supportedProfilesBitMask & (1 << i)) != 0) {
                supportedProfiles.add(i);
            }
        }

        return supportedProfiles;
    }

    /**
     * Sends the current foreground user id to the Bluetooth process. This user id is used to
     * determine if Binder calls are coming from the active user.
@@ -1448,10 +1469,10 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
            ProfileServiceConnections psc = mProfileServices.get(new Integer(bluetoothProfile));
            Intent intent;
            if (bluetoothProfile == BluetoothProfile.HEADSET
                    && BluetoothProperties.isProfileHfpAgEnabled().orElse(false)) {
                    && mSupportedProfileList.contains(BluetoothProfile.HEADSET)) {
                intent = new Intent(IBluetoothHeadset.class.getName());
            } else if (bluetoothProfile == BluetoothProfile.LE_CALL_CONTROL
                    && BluetoothProperties.isProfileCcpServerEnabled().orElse(false)) {
                    && mSupportedProfileList.contains(BluetoothProfile.LE_CALL_CONTROL)) {
                intent = new Intent(IBluetoothLeCallControl.class.getName());
            } else {
                return false;
@@ -2236,6 +2257,14 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                        //Inform BluetoothAdapter instances that service is up
                        sendBluetoothServiceUpCallback();

                        // Get the supported profiles list
                        try {
                            mSupportedProfileList = synchronousGetSupportedProfiles(
                                    mContext.getAttributionSource());
                        } catch (RemoteException | TimeoutException e) {
                            Log.e(TAG, "Unable to get the supported profiles list", e);
                        }

                        //Do enable request
                        try {
                            if (!synchronousEnable(mQuietEnable, mContext.getAttributionSource())) {
@@ -2314,6 +2343,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                                break;
                            }
                            mBluetooth = null;
                            mSupportedProfileList.clear();
                        } else if (msg.arg1 == SERVICE_IBLUETOOTHGATT) {
                            mBluetoothGatt = null;
                            break;