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

Commit a7473624 authored by Rahul Sabnis's avatar Rahul Sabnis Committed by Automerger Merge Worker
Browse files

Set the connection policy directly in the database when we receive profile...

Set the connection policy directly in the database when we receive profile uuids for a device to avoid connecting am: 1a9b437c

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

Change-Id: I783500218a7435b02952bf361de555212c9aad26
parents e262cc96 1a9b437c
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -261,7 +261,8 @@ class PhonePolicy {
                || ArrayUtils.contains(uuids, BluetoothUuid.HOGP)) && (
                hidService.getConnectionPolicy(device)
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
            hidService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    BluetoothProfile.HID_HOST, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        }

        // If we do not have a stored priority for HFP/A2DP (all roles) then default to on.
@@ -269,14 +270,16 @@ class PhonePolicy {
                || ArrayUtils.contains(uuids, BluetoothUuid.HFP)) && (
                headsetService.getConnectionPolicy(device)
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN))) {
            headsetService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    BluetoothProfile.HEADSET, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        }

        if ((a2dpService != null) && (ArrayUtils.contains(uuids, BluetoothUuid.A2DP_SINK)
                || ArrayUtils.contains(uuids, BluetoothUuid.ADV_AUDIO_DIST)) && (
                a2dpService.getConnectionPolicy(device)
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
            a2dpService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    BluetoothProfile.A2DP, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        }

        if ((panService != null) && (ArrayUtils.contains(uuids, BluetoothUuid.PANU) && (
@@ -284,15 +287,16 @@ class PhonePolicy {
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)
                && mAdapterService.getResources()
                .getBoolean(R.bool.config_bluetooth_pan_enable_autoconnect))) {
            panService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    BluetoothProfile.PAN, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        }

        if ((hearingAidService != null) && ArrayUtils.contains(uuids,
                BluetoothUuid.HEARING_AID) && (hearingAidService.getConnectionPolicy(device)
                == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
            debugLog("setting hearing aid profile priority for device " + device);
            hearingAidService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    BluetoothProfile.HEARING_AID, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        }
    }

+8 −4
Original line number Diff line number Diff line
@@ -114,6 +114,8 @@ public class PhonePolicyTest {
        when(mA2dpService.getConnectionPolicy(device))
                .thenReturn(BluetoothProfile.CONNECTION_POLICY_UNKNOWN);

        when(mAdapterService.getDatabase()).thenReturn(mDatabaseManager);

        // Inject an event for UUIDs updated for a remote device with only HFP enabled
        Intent intent = new Intent(BluetoothDevice.ACTION_UUID);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
@@ -124,10 +126,12 @@ public class PhonePolicyTest {
        mPhonePolicy.getBroadcastReceiver().onReceive(null /* context */, intent);

        // Check that the priorities of the devices for preferred profiles are set to ON
        verify(mHeadsetService, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setConnectionPolicy(eq(device),
                eq(BluetoothProfile.CONNECTION_POLICY_ALLOWED));
        verify(mA2dpService, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setConnectionPolicy(eq(device),
                eq(BluetoothProfile.CONNECTION_POLICY_ALLOWED));
        verify(mDatabaseManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .setProfileConnectionPolicy(device, BluetoothProfile.HEADSET,
                        BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        verify(mDatabaseManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .setProfileConnectionPolicy(device, BluetoothProfile.A2DP,
                        BluetoothProfile.CONNECTION_POLICY_ALLOWED);
    }

    /**