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

Commit 23fb85bb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Check the service is in the supported profile list instead of using...

Merge "Check the service is in the supported profile list instead of using system property" into tm-d1-dev am: 6b33e62e am: 7c7d1182

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/19065326



Change-Id: Ic795519f636f33cee661ff419528ec1a69bc8032
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents f6b7aad0 7c7d1182
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;
@@ -2240,6 +2261,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())) {
@@ -2318,6 +2347,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                                break;
                            }
                            mBluetooth = null;
                            mSupportedProfileList.clear();
                        } else if (msg.arg1 == SERVICE_IBLUETOOTHGATT) {
                            mBluetoothGatt = null;
                            break;