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

Commit ca935287 authored by William Escande's avatar William Escande
Browse files

PTS: use extended advertising API

Test: atest pts-bot
Bug: 302595208
Change-Id: I21448266dbfefc40722939a969ed9c586f584ae2
parent 832c154f
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            connectable=True,
            own_address_type=PUBLIC,
        )
@@ -245,6 +246,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            own_address_type=PUBLIC,
            data=DataTypes(complete_service_class_uuids128=["955798ce-3022-455c-b759-ee8edcd73d1a"],))
        return "OK"
@@ -256,6 +258,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(own_address_type=PUBLIC,
                                             legacy=True,
                                             data=DataTypes(
                                                 include_complete_local_name=True,
                                                 include_shortened_local_name=True,
@@ -270,6 +273,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            connectable=True,
            own_address_type=PUBLIC,
        )
@@ -286,6 +290,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(own_address_type=PUBLIC,
                                             legacy=True,
                                             data=DataTypes(manufacturer_specific_data=b"d0n't b3 3v1l!",))

        return "OK"
@@ -296,7 +301,9 @@ class GAPProxy(ProfileProxy):
        Please prepare IUT to send an advertising report with TX Power Level.
        """

        self.advertise = self.host.Advertise(own_address_type=PUBLIC, data=DataTypes(include_tx_power_level=True,))
        self.advertise = self.host.Advertise(legacy=True,
                                             own_address_type=PUBLIC,
                                             data=DataTypes(include_tx_power_level=True,))

        return "OK"

@@ -307,6 +314,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            own_address_type=PUBLIC,
            connectable=True,
        )
@@ -322,6 +330,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            own_address_type=PUBLIC,
            connectable=True,
        )
@@ -396,6 +405,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            data=DataTypes(le_discoverability_mode=DISCOVERABLE_GENERAL),
            own_address_type=PUBLIC,
            connectable=True,
@@ -414,6 +424,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            data=DataTypes(le_discoverability_mode=DISCOVERABLE_GENERAL),
            own_address_type=PUBLIC,
            connectable=True,
@@ -431,6 +442,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            data=DataTypes(le_discoverability_mode=NOT_DISCOVERABLE),
            own_address_type=PUBLIC,
            connectable=True,
@@ -445,6 +457,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            data=DataTypes(le_discoverability_mode=DISCOVERABLE_GENERAL),
            own_address_type=PUBLIC,
            connectable=True,
@@ -560,7 +573,10 @@ class GAPProxy(ProfileProxy):
        send an advertising report.
        """

        self.advertise = self.host.Advertise(own_address_type=PUBLIC,)
        self.advertise = self.host.Advertise(
            legacy=True,
            own_address_type=PUBLIC,
        )

        return "OK"

@@ -676,6 +692,7 @@ class GAPProxy(ProfileProxy):
        self.host.SetDiscoverabilityMode(mode=DISCOVERABLE_GENERAL)

        self.advertise = self.host.Advertise(
            legacy=True,
            data=DataTypes(le_discoverability_mode=DISCOVERABLE_GENERAL),
            own_address_type=PUBLIC,
            connectable=True,
@@ -792,6 +809,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            data=DataTypes(le_discoverability_mode=DISCOVERABLE_GENERAL),
            own_address_type=PUBLIC,
            connectable=False,
@@ -819,6 +837,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            data=DataTypes(le_discoverability_mode=DISCOVERABLE_GENERAL),
            own_address_type=PUBLIC,
            connectable=False,
@@ -834,6 +853,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            data=DataTypes(le_discoverability_mode=NOT_DISCOVERABLE),
            own_address_type=PUBLIC,
            connectable=True,
@@ -849,6 +869,7 @@ class GAPProxy(ProfileProxy):
        """

        self.advertise = self.host.Advertise(
            legacy=True,
            data=DataTypes(le_discoverability_mode=DISCOVERABLE_GENERAL),
            own_address_type=PUBLIC,
            connectable=True,
+1 −0
Original line number Diff line number Diff line
@@ -1006,6 +1006,7 @@ class GATTProxy(ProfileProxy):
        PTS.
        """
        self.advertise = self.host.Advertise(
            legacy=True,
            connectable=True,
            own_address_type=PUBLIC,
        )
+1 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ class L2CAPProxy(ProfileProxy):
        Place the IUT into LE connectable mode.
        """
        self.advertise = self.host.Advertise(
            legacy=True,
            connectable=True,
            own_address_type=PUBLIC,
        )
+1 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ class SMProxy(ProfileProxy):
        Action: Place the IUT in connectable mode
        """
        self.advertise = self.host.Advertise(
            legacy=True,
            connectable=True,
            own_address_type=PUBLIC,
        )
+25 −16
Original line number Diff line number Diff line
@@ -28,13 +28,12 @@ import android.bluetooth.BluetoothProfile
import android.bluetooth.BluetoothUuid
import android.bluetooth.le.AdvertiseCallback
import android.bluetooth.le.AdvertiseData
import android.bluetooth.le.AdvertiseSettings
import android.bluetooth.le.AdvertisingSet
import android.bluetooth.le.AdvertisingSetCallback
import android.bluetooth.le.AdvertisingSetParameters
import android.bluetooth.le.ScanCallback
import android.bluetooth.le.ScanFilter
import android.bluetooth.le.ScanRecord
import android.bluetooth.le.ScanResult
import android.bluetooth.le.ScanSettings
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
@@ -64,7 +63,6 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import pandora.HostGrpc.HostImplBase
import pandora.HostProto.*

@@ -437,7 +435,8 @@ class Host(
                        throw IllegalArgumentException("Request address field must be set")
                }
            Log.i(TAG, "connectLE: $address")
            val bluetoothDevice = bluetoothAdapter.getRemoteLeDevice(address.decodeAsMacAddressToString(), type)
            val bluetoothDevice =
                bluetoothAdapter.getRemoteLeDevice(address.decodeAsMacAddressToString(), type)
            initiatedConnection.add(bluetoothDevice)
            GattInstance(bluetoothDevice, TRANSPORT_LE, context)
                .waitForState(BluetoothProfile.STATE_CONNECTED)
@@ -455,12 +454,16 @@ class Host(
        grpcServerStream(scope, responseObserver) {
            callbackFlow {
                val callback =
                    object : AdvertiseCallback() {
                        override fun onStartSuccess(settingsInEffect: AdvertiseSettings) {
                            Log.d(TAG, "advertising started")
                    object : AdvertisingSetCallback() {
                        override fun onAdvertisingSetStarted(
                            advertisingSet: AdvertisingSet,
                            txPower: Int,
                            status: Int
                        ) {
                            Log.d(TAG, "advertising started with status " + status)
                            if (status != 0) {
                                error("failed to start advertisingSet: $status")
                            }
                        override fun onStartFailure(errorCode: Int) {
                            error("failed to start advertising: $errorCode")
                        }
                    }
                val advertisingDataBuilder = AdvertiseData.Builder()
@@ -544,15 +547,21 @@ class Host(
                        OwnAddressType.RANDOM -> AdvertisingSetParameters.ADDRESS_TYPE_RANDOM
                        else -> AdvertisingSetParameters.ADDRESS_TYPE_DEFAULT
                    }
                val advertiseSettings =
                    AdvertiseSettings.Builder()

                val advertisingSetParameters =
                    AdvertisingSetParameters.Builder()
                        .setConnectable(request.connectable)
                        .setOwnAddressType(ownAddressType)
                        .setLegacyMode(request.legacy)
                        .setScannable(request.legacy && request.connectable)
                        .build()

                bluetoothAdapter.bluetoothLeAdvertiser.startAdvertising(
                    advertiseSettings,
                bluetoothAdapter.bluetoothLeAdvertiser.startAdvertisingSet(
                    advertisingSetParameters,
                    advertisingData,
                    null, /* scanResponse */
                    null, /* periodicParameters */
                    null, /* periodicData */
                    callback,
                )

@@ -570,7 +579,7 @@ class Host(
                    }
                }

                awaitClose { bluetoothAdapter.bluetoothLeAdvertiser.stopAdvertising(callback) }
                awaitClose { bluetoothAdapter.bluetoothLeAdvertiser.stopAdvertisingSet(callback) }
            }
        }
    }