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

Commit 2c103fba authored by Bhakthavatsala Raghavendra's avatar Bhakthavatsala Raghavendra
Browse files

Test: Update tests related to bond check from Profiles

Bug: 378276848
Bug: 353738134
Flag:
com.android.bluetooth.flags.donot_validate_bond_state_from_profiles
Test: mmm packages/modules/Bluetooth

Change-Id: Iea730987cb70b8abbf61d52735f7806b794e94e5
parent 5a986e9d
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ public class A2dpServiceTest {
                sTestDevice,
                BluetoothDevice.BOND_NONE,
                BluetoothProfile.CONNECTION_POLICY_UNKNOWN,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(
                sTestDevice,
                BluetoothDevice.BOND_NONE,
@@ -250,13 +250,13 @@ public class A2dpServiceTest {
                sTestDevice,
                BluetoothDevice.BOND_NONE,
                BluetoothProfile.CONNECTION_POLICY_ALLOWED,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(sTestDevice, BluetoothDevice.BOND_NONE, badPriorityValue, false);
        testOkToConnectCase(
                sTestDevice,
                BluetoothDevice.BOND_BONDING,
                BluetoothProfile.CONNECTION_POLICY_UNKNOWN,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(
                sTestDevice,
                BluetoothDevice.BOND_BONDING,
@@ -266,7 +266,7 @@ public class A2dpServiceTest {
                sTestDevice,
                BluetoothDevice.BOND_BONDING,
                BluetoothProfile.CONNECTION_POLICY_ALLOWED,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(sTestDevice, BluetoothDevice.BOND_BONDING, badPriorityValue, false);
        testOkToConnectCase(
                sTestDevice,
@@ -285,11 +285,17 @@ public class A2dpServiceTest {
                true);
        testOkToConnectCase(sTestDevice, BluetoothDevice.BOND_BONDED, badPriorityValue, false);
        testOkToConnectCase(
                sTestDevice, badBondState, BluetoothProfile.CONNECTION_POLICY_UNKNOWN, false);
                sTestDevice,
                badBondState,
                BluetoothProfile.CONNECTION_POLICY_UNKNOWN,
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(
                sTestDevice, badBondState, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN, false);
        testOkToConnectCase(
                sTestDevice, badBondState, BluetoothProfile.CONNECTION_POLICY_ALLOWED, false);
                sTestDevice,
                badBondState,
                BluetoothProfile.CONNECTION_POLICY_ALLOWED,
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(sTestDevice, badBondState, badPriorityValue, false);
    }

+13 −3
Original line number Diff line number Diff line
@@ -205,13 +205,11 @@ public class HearingAidServiceTest {
    public void okToConnect_whenNotBonded_returnFalse() {
        int badPolicyValue = 1024;
        int badBondState = 42;
        for (int bondState : List.of(BOND_NONE, BOND_BONDING, badBondState)) {
        for (int bondState : List.of(badBondState)) {
            doReturn(bondState).when(mAdapterService).getBondState(any());
            for (int policy :
                    List.of(
                            CONNECTION_POLICY_UNKNOWN,
                            CONNECTION_POLICY_FORBIDDEN,
                            CONNECTION_POLICY_ALLOWED,
                            badPolicyValue)) {
                doReturn(policy).when(mDatabaseManager).getProfileConnectionPolicy(any(), anyInt());
                assertThat(mService.okToConnect(mSingleDevice)).isEqualTo(false);
@@ -219,6 +217,18 @@ public class HearingAidServiceTest {
        }
    }

    @Test
    public void okToConnect_whenNotBonded_returnTrue() {
        for (int bondState : List.of(BOND_NONE, BOND_BONDING)) {
            doReturn(bondState).when(mAdapterService).getBondState(any());
            for (int policy : List.of(CONNECTION_POLICY_UNKNOWN, CONNECTION_POLICY_ALLOWED)) {
                doReturn(policy).when(mDatabaseManager).getProfileConnectionPolicy(any(), anyInt());
                assertThat(mService.okToConnect(mSingleDevice))
                        .isEqualTo(Flags.donotValidateBondStateFromProfiles());
            }
        }
    }

    @Test
    public void okToConnect_whenBonded() {
        int badPolicyValue = 1024;
+13 −6
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.RemoteDevices;
import com.android.bluetooth.btservice.SilenceDeviceManager;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.flags.Flags;

import org.hamcrest.Matchers;
import org.junit.After;
@@ -210,7 +211,7 @@ public class HeadsetServiceTest {
                mCurrentDevice,
                BluetoothDevice.BOND_NONE,
                BluetoothProfile.CONNECTION_POLICY_UNKNOWN,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToAcceptConnectionCase(
                mCurrentDevice,
                BluetoothDevice.BOND_NONE,
@@ -220,14 +221,14 @@ public class HeadsetServiceTest {
                mCurrentDevice,
                BluetoothDevice.BOND_NONE,
                BluetoothProfile.CONNECTION_POLICY_ALLOWED,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToAcceptConnectionCase(
                mCurrentDevice, BluetoothDevice.BOND_NONE, badPriorityValue, false);
        testOkToAcceptConnectionCase(
                mCurrentDevice,
                BluetoothDevice.BOND_BONDING,
                BluetoothProfile.CONNECTION_POLICY_UNKNOWN,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToAcceptConnectionCase(
                mCurrentDevice,
                BluetoothDevice.BOND_BONDING,
@@ -237,7 +238,7 @@ public class HeadsetServiceTest {
                mCurrentDevice,
                BluetoothDevice.BOND_BONDING,
                BluetoothProfile.CONNECTION_POLICY_ALLOWED,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToAcceptConnectionCase(
                mCurrentDevice, BluetoothDevice.BOND_BONDING, badPriorityValue, false);
        testOkToAcceptConnectionCase(
@@ -258,11 +259,17 @@ public class HeadsetServiceTest {
        testOkToAcceptConnectionCase(
                mCurrentDevice, BluetoothDevice.BOND_BONDED, badPriorityValue, false);
        testOkToAcceptConnectionCase(
                mCurrentDevice, badBondState, BluetoothProfile.CONNECTION_POLICY_UNKNOWN, false);
                mCurrentDevice,
                badBondState,
                BluetoothProfile.CONNECTION_POLICY_UNKNOWN,
                Flags.donotValidateBondStateFromProfiles());
        testOkToAcceptConnectionCase(
                mCurrentDevice, badBondState, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN, false);
        testOkToAcceptConnectionCase(
                mCurrentDevice, badBondState, BluetoothProfile.CONNECTION_POLICY_ALLOWED, false);
                mCurrentDevice,
                badBondState,
                BluetoothProfile.CONNECTION_POLICY_ALLOWED,
                Flags.donotValidateBondStateFromProfiles());
        testOkToAcceptConnectionCase(mCurrentDevice, badBondState, badPriorityValue, false);
    }

+13 −6
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.flags.Flags;

import org.junit.After;
import org.junit.Assert;
@@ -93,7 +94,7 @@ public class HidHostServiceTest {
                mTestDevice,
                BluetoothDevice.BOND_NONE,
                BluetoothProfile.CONNECTION_POLICY_UNKNOWN,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(
                mTestDevice,
                BluetoothDevice.BOND_NONE,
@@ -103,13 +104,13 @@ public class HidHostServiceTest {
                mTestDevice,
                BluetoothDevice.BOND_NONE,
                BluetoothProfile.CONNECTION_POLICY_ALLOWED,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(mTestDevice, BluetoothDevice.BOND_NONE, badPriorityValue, false);
        testOkToConnectCase(
                mTestDevice,
                BluetoothDevice.BOND_BONDING,
                BluetoothProfile.CONNECTION_POLICY_UNKNOWN,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(
                mTestDevice,
                BluetoothDevice.BOND_BONDING,
@@ -119,7 +120,7 @@ public class HidHostServiceTest {
                mTestDevice,
                BluetoothDevice.BOND_BONDING,
                BluetoothProfile.CONNECTION_POLICY_ALLOWED,
                false);
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(mTestDevice, BluetoothDevice.BOND_BONDING, badPriorityValue, false);
        testOkToConnectCase(
                mTestDevice,
@@ -138,11 +139,17 @@ public class HidHostServiceTest {
                true);
        testOkToConnectCase(mTestDevice, BluetoothDevice.BOND_BONDED, badPriorityValue, false);
        testOkToConnectCase(
                mTestDevice, badBondState, BluetoothProfile.CONNECTION_POLICY_UNKNOWN, false);
                mTestDevice,
                badBondState,
                BluetoothProfile.CONNECTION_POLICY_UNKNOWN,
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(
                mTestDevice, badBondState, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN, false);
        testOkToConnectCase(
                mTestDevice, badBondState, BluetoothProfile.CONNECTION_POLICY_ALLOWED, false);
                mTestDevice,
                badBondState,
                BluetoothProfile.CONNECTION_POLICY_ALLOWED,
                Flags.donotValidateBondStateFromProfiles());
        testOkToConnectCase(mTestDevice, badBondState, badPriorityValue, false);
    }