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

Commit 7c7d1182 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

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



Change-Id: If5189a64478bf84e6f2d9bfb21b5660ff65246e0
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 046a6676 6b33e62e
Loading
Loading
Loading
Loading
+32 −2
Original line number Original line Diff line number Diff line
@@ -94,6 +94,7 @@ import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.time.Duration;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.List;
import java.util.List;
@@ -217,6 +218,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
    private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock();
    private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock();
    private boolean mBinding;
    private boolean mBinding;
    private boolean mUnbinding;
    private boolean mUnbinding;
    private List<Integer> mSupportedProfileList = new ArrayList<>();


    private BluetoothModeChangeHelper mBluetoothModeChangeHelper;
    private BluetoothModeChangeHelper mBluetoothModeChangeHelper;


@@ -871,6 +873,25 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
        recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
        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
     * 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.
     * 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));
            ProfileServiceConnections psc = mProfileServices.get(new Integer(bluetoothProfile));
            Intent intent;
            Intent intent;
            if (bluetoothProfile == BluetoothProfile.HEADSET
            if (bluetoothProfile == BluetoothProfile.HEADSET
                    && BluetoothProperties.isProfileHfpAgEnabled().orElse(false)) {
                    && mSupportedProfileList.contains(BluetoothProfile.HEADSET)) {
                intent = new Intent(IBluetoothHeadset.class.getName());
                intent = new Intent(IBluetoothHeadset.class.getName());
            } else if (bluetoothProfile == BluetoothProfile.LE_CALL_CONTROL
            } else if (bluetoothProfile == BluetoothProfile.LE_CALL_CONTROL
                    && BluetoothProperties.isProfileCcpServerEnabled().orElse(false)) {
                    && mSupportedProfileList.contains(BluetoothProfile.LE_CALL_CONTROL)) {
                intent = new Intent(IBluetoothLeCallControl.class.getName());
                intent = new Intent(IBluetoothLeCallControl.class.getName());
            } else {
            } else {
                return false;
                return false;
@@ -2240,6 +2261,14 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                        //Inform BluetoothAdapter instances that service is up
                        //Inform BluetoothAdapter instances that service is up
                        sendBluetoothServiceUpCallback();
                        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
                        //Do enable request
                        try {
                        try {
                            if (!synchronousEnable(mQuietEnable, mContext.getAttributionSource())) {
                            if (!synchronousEnable(mQuietEnable, mContext.getAttributionSource())) {
@@ -2318,6 +2347,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                                break;
                                break;
                            }
                            }
                            mBluetooth = null;
                            mBluetooth = null;
                            mSupportedProfileList.clear();
                        } else if (msg.arg1 == SERVICE_IBLUETOOTHGATT) {
                        } else if (msg.arg1 == SERVICE_IBLUETOOTHGATT) {
                            mBluetoothGatt = null;
                            mBluetoothGatt = null;
                            break;
                            break;