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

Commit 180bbdc7 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Hyundo Moon
Browse files

BassClient: Respect forbidden connection policy

Bug: 150670922
Bug: 230559809
Tag: #feature
Test: atest BluetoothInstrumentationTests
Change-Id: Icd5b27cbc47d7f5af5abe151708c76c7906a1989
parent 46e745e0
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.bluetooth.bass_client;
package com.android.bluetooth.bass_client;


import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.Manifest.permission.BLUETOOTH_CONNECT;

import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;
import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAdapter;
@@ -49,7 +50,6 @@ import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;


import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashMap;
@@ -394,8 +394,8 @@ public class BassClientService extends ProfileService {
            Log.e(TAG, "connect: device is null");
            Log.e(TAG, "connect: device is null");
            return false;
            return false;
        }
        }
        if (getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_UNKNOWN) {
        if (getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            Log.e(TAG, "connect: unknown connection policy");
            Log.e(TAG, "connect: connection policy set to forbidden");
            return false;
            return false;
        }
        }
        synchronized (mStateMachines) {
        synchronized (mStateMachines) {
+3 −3
Original line number Original line Diff line number Diff line
@@ -181,14 +181,14 @@ public class BassClientServiceTest {
    }
    }


    /**
    /**
     * Test connecting to a device when the connection policy is unknown.
     * Test connecting to a device when the connection policy is forbidden.
     *  - service.connect() should return false.
     *  - service.connect() should return false.
     */
     */
    @Test
    @Test
    public void testConnect_whenConnectionPolicyIsUnknown() {
    public void testConnect_whenConnectionPolicyIsForbidden() {
        when(mDatabaseManager.getProfileConnectionPolicy(any(BluetoothDevice.class),
        when(mDatabaseManager.getProfileConnectionPolicy(any(BluetoothDevice.class),
                eq(BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT)))
                eq(BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT)))
                .thenReturn(BluetoothProfile.CONNECTION_POLICY_UNKNOWN);
                .thenReturn(BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
        mCurrentDevice = TestUtils.getTestDevice(mBluetoothAdapter, 0);
        mCurrentDevice = TestUtils.getTestDevice(mBluetoothAdapter, 0);
        assertThat(mCurrentDevice).isNotNull();
        assertThat(mCurrentDevice).isNotNull();