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

Commit 5ef0c449 authored by Charlie Boutier's avatar Charlie Boutier Committed by Gerrit Code Review
Browse files

Merge changes from topic "update_bumble" into main

* changes:
  BumbleBluetoothTests: cancel advertise call
  avatar: update SDP tests to new Bumble's SDP API
parents baab8de7 4b734832
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ from bumble.sdp import (
    SDP_ALL_ATTRIBUTES_RANGE,
    SDP_PUBLIC_BROWSE_ROOT,
    SDP_SERVICE_CLASS_ID_LIST_ATTRIBUTE_ID,
    Client as SDP_Client,
    Client as SdpClient,
    ServiceAttribute,
)
from mobly import base_test, test_runner
@@ -90,8 +90,8 @@ class SdpTest(base_test.BaseTestClass): # type: ignore[misc]

        # Connect to the SDP Server
        self.ref.log.info(f'Connecting to SDP Server')
        sdp_client = SDP_Client(self.ref.device)  # type: ignore
        await sdp_client.connect(connection)  # type: ignore
        sdp_client = SdpClient(connection)  # type: ignore
        await sdp_client.connect()  # type: ignore
        self.ref.log.info(f'Connected to SDP Server')

        # SDP Client disconnect
@@ -119,8 +119,8 @@ class SdpTest(base_test.BaseTestClass): # type: ignore[misc]

        # Connect to the SDP Server
        self.ref.log.info(f'Connecting to SDP Server')
        sdp_client = SDP_Client(self.ref.device)  # type: ignore
        await sdp_client.connect(connection)  # type: ignore
        sdp_client = SdpClient(connection)  # type: ignore
        await sdp_client.connect()  # type: ignore
        self.ref.log.info(f'Connected to SDP Server')

        # List all services in the root browse group
@@ -163,8 +163,8 @@ class SdpTest(base_test.BaseTestClass): # type: ignore[misc]

        # Connect to the SDP Server
        self.ref.log.info(f'Connecting to SDP Server')
        sdp_client = SDP_Client(self.ref.device)  # type: ignore
        await sdp_client.connect(connection)  # type: ignore
        sdp_client = SdpClient(connection)  # type: ignore
        await sdp_client.connect()  # type: ignore
        self.ref.log.info(f'Connected to SDP Server')

        # List all services in the root browse group
+28 −14
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.compatibility.common.util.AdoptShellPermissionsRule
import com.google.common.collect.Sets
import com.google.common.truth.Truth.assertThat
import com.google.protobuf.Empty
import io.grpc.Context as GrpcContext
import io.grpc.Deadline
import java.util.UUID
import java.util.concurrent.TimeUnit
@@ -77,8 +78,19 @@ public class DckGattTest(private val connected: Boolean) {

    @Before
    fun setUp() {
        // 1. Register Bumble's DCK (Digital Car Key) service via a gRPC call:
        // - `dckBlocking()` is likely a stub that accesses the DCK service over gRPC in a
        //   blocking/synchronous manner.
        // - `withDeadline(Deadline.after(TIMEOUT, TimeUnit.MILLISECONDS))` sets a timeout for the
        //   gRPC call.
        // - `register(Empty.getDefaultInstance())` sends a registration request to the server.
        mBumble
            .dckBlocking()
            .withDeadline(Deadline.after(TIMEOUT, TimeUnit.MILLISECONDS))
            .register(Empty.getDefaultInstance())

        if (connected) {
            advertiseWithBumble()
            val advertiseContext = advertiseWithBumble()

            // Connect DUT to Ref as prerequisite
            val device =
@@ -93,6 +105,11 @@ public class DckGattTest(private val connected: Boolean) {
                    eq(BluetoothGatt.GATT_SUCCESS),
                    eq(BluetoothProfile.STATE_CONNECTED)
                )
            advertiseContext.cancel(null)

            // Wait a bit for the advertising to stop.
            // b/332322761
            Thread.sleep(1000)
        }

        clearInvocations(gattCallbackMock)
@@ -133,16 +150,6 @@ public class DckGattTest(private val connected: Boolean) {
     */
    @Test
    fun testDiscoverDkGattService() {
        // 1. Register Bumble's DCK (Digital Car Key) service via a gRPC call:
        // - `dckBlocking()` is likely a stub that accesses the DCK service over gRPC in a
        //   blocking/synchronous manner.
        // - `withDeadline(Deadline.after(TIMEOUT, TimeUnit.MILLISECONDS))` sets a timeout for the
        //   gRPC call.
        // - `register(Empty.getDefaultInstance())` sends a registration request to the server.
        mBumble
            .dckBlocking()
            .withDeadline(Deadline.after(TIMEOUT, TimeUnit.MILLISECONDS))
            .register(Empty.getDefaultInstance())

        // 2. Advertise the host's (presumably the car's) Bluetooth capabilities using another
        //    gRPC call:
@@ -219,7 +226,7 @@ public class DckGattTest(private val connected: Boolean) {
        assumeFalse(connected)

        // Start advertisement on Ref
        advertiseWithBumble()
        val advertiseStreamObserver = advertiseWithBumble()

        // Start IRK scan for Ref on DUT
        val scanSettings =
@@ -258,6 +265,7 @@ public class DckGattTest(private val connected: Boolean) {

        // Stop scan on DUT after GATT connect
        leScanner.stopScan(scanCallbackMock)
        advertiseStreamObserver.cancel(null)
    }

    /*
@@ -302,7 +310,7 @@ public class DckGattTest(private val connected: Boolean) {
            )
    }

    private fun advertiseWithBumble(withUuid: Boolean = false) {
    private fun advertiseWithBumble(withUuid: Boolean = false): GrpcContext.CancellableContext {
        val requestBuilder =
            AdvertiseRequest.newBuilder()
                .setLegacy(true)
@@ -315,7 +323,13 @@ public class DckGattTest(private val connected: Boolean) {
                    .addCompleteServiceClassUuids128(CCC_DK_UUID.toString())
                    .build()
        }
        mBumble.hostBlocking().advertise(requestBuilder.build())

        val cancellableContext = GrpcContext.current().withCancellation()
        with(cancellableContext) {
            run { mBumble.hostBlocking().advertise(requestBuilder.build()) }
        }

        return cancellableContext
    }

    companion object {