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

Commit 951491f8 authored by Shilika Gehlot's avatar Shilika Gehlot
Browse files

Implementing LE Scan with UUID tests

Test: atest BumbleBluetoothTests:android.bluetooth.DckScanTest
Bug: 315518656
Flag: TEST_ONLY
Change-Id: I7f368270ec73b931ee00d79bad06254ca7fce381
parent b6a30e16
Loading
Loading
Loading
Loading
+37 −8
Original line number Diff line number Diff line
@@ -20,21 +20,32 @@ import android.bluetooth.DckTestRule.LeScanResult
import android.bluetooth.le.ScanFilter
import android.bluetooth.le.ScanSettings
import android.content.Context
import android.os.ParcelUuid
import androidx.test.core.app.ApplicationProvider
import com.android.compatibility.common.util.AdoptShellPermissionsRule
import com.google.common.truth.Truth.assertThat
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import java.util.UUID
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import org.junit.Assume.assumeTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/** DCK LE Scan Tests */
@RunWith(TestParameterInjector::class)
class DckScanTest() {
class DckScanTest(
    private @TestParameter val isBluetoothToggled: Boolean,
    private @TestParameter val isRemoteAdvertisingWithUuid: Boolean,
    private @TestParameter val isGattConnected: Boolean
) {
    // TODO(315852141): Include variations for LE only vs. Dual mode Bumble when supported
    // TODO(315852141): Include variations for two advertisements at the same time
    // TODO(303502437): Include variations for other callback types when supported in rootcanal

    private val context: Context = ApplicationProvider.getApplicationContext()

    // Gives shell permissions during the test.
@@ -84,15 +95,33 @@ class DckScanTest() {
            .isEqualTo(TEST_ADDRESS_RANDOM_STATIC)
    }

    @Test
    fun scanForUuid_remoteFound() {
        // Assume isRemoteAdvertisingWithUuid is true to skip tests in which
        // device is not advertising with UUID
        assumeTrue(isRemoteAdvertisingWithUuid)
        val scanFilter = ScanFilter.Builder().setServiceUuid(ParcelUuid(CCC_DK_UUID)).build()
        val scanSettings =
            ScanSettings.Builder()
                .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
                .setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE)
                .build()

        val result: LeScanResult = runBlocking {
            withTimeout(TIMEOUT_MS) { dck.scanWithCallback(scanFilter, scanSettings).first() }
        }

        assertThat(result).isInstanceOf(LeScanResult.Success::class.java)
        assertThat((result as LeScanResult.Success).callbackType)
            .isEqualTo(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
        assertThat((result as LeScanResult.Success).scanResult.device.address)
            .isEqualTo(Utils.BUMBLE_RANDOM_ADDRESS)
    }

    companion object {
        private const val TIMEOUT_MS = 3000L
        private const val TEST_ADDRESS_RANDOM_STATIC = "F0:43:A8:23:10:11"

        // TODO(315852141): Include variations for LE only vs. Dual mode Bumble when supported
        // TODO(315852141): Include variations for two advertisements at the same time
        // TODO(303502437): Include variations for other callback types when supported in rootcanal
        @TestParameter val isRemoteAdvertisingWithUuid: Boolean = false
        @TestParameter val isBluetoothToggled: Boolean = false
        @TestParameter val isGattConnected: Boolean = false
        private val CCC_DK_UUID = UUID.fromString("0000FFF5-0000-1000-8000-00805f9b34fb")
    }
}