fun testDiscoverDkGattService() {
// 2. Advertise the host's (presumably the car's) Bluetooth capabilities using another
// gRPC call:
// - `hostBlocking()` accesses another gRPC service related to the host.
// The following `advertise(...)` sends an advertise request to the server, setting
// specific attributes.
mBumble
.hostBlocking()
.advertise(
AdvertiseRequest.newBuilder()
.setLegacy(
true
) // As of now, Bumble only support legacy advertising (b/266124496).
.setConnectable(true)
.setOwnAddressType(
OwnAddressType.RANDOM
) // Ask Bumble to advertise it's `RANDOM` address.
.build()
)
// 3. Fetch a remote Bluetooth device instance (here, Bumble).
val bumbleDevice =
bluetoothAdapter.getRemoteLeDevice(
// To keep things straightforward, the Bumble RANDOM address is set to a predefined
// constant.
// Typically, an LE scan would be conducted to identify the Bumble device, matching
// it based on its
// Advertising data.
Utils.BUMBLE_RANDOM_ADDRESS,
BluetoothDevice
.ADDRESS_TYPE_RANDOM // Specify address type as RANDOM because the device
// advertises with this address type.
)
// 4. Create a mock callback to handle Bluetooth GATT (Generic Attribute Profile) related
// events.
val gattCallback = mock<BluetoothGattCallback>()
// 5. Connect to the Bumble device and expect a successful connection callback.
var bumbleGatt = bumbleDevice.connectGatt(context, false, gattCallback)
verify(gattCallback, timeout(TIMEOUT))
.onConnectionStateChange(
any(),
eq(BluetoothGatt.GATT_SUCCESS),
eq(BluetoothProfile.STATE_CONNECTED)
)
// 6. Discover GATT services offered by Bumble and expect successful service discovery.
bumbleGatt.discoverServices()
verify(gattCallback, timeout(DISCOVERY_TIMEOUT))
.onServicesDiscovered(any(), eq(BluetoothGatt.GATT_SUCCESS))
// 7. Check if the required service (CCC_DK_UUID) is available on Bumble.
assertThat(bumbleGatt.getService(CCC_DK_UUID)).isNotNull()
// 8. Disconnect from the Bumble device and expect a successful disconnection callback.
bumbleGatt.disconnect()
verify(gattCallback, timeout(TIMEOUT))
.onConnectionStateChange(
any(),
eq(BluetoothGatt.GATT_SUCCESS),
eq(BluetoothProfile.STATE_DISCONNECTED)
)
}
上面是谷歌源码,本地代码这一块和谷歌是一样的,但是运行时,会报下面的错误
2024-10-08 17:40:52 atest_tf_test_runner.py:512:DEBUG: received: TEST_FAILED
{"trace":"Wanted but not invoked:\r\nbluetoothGattCallback.onConnectionStateChange(\r\n
,\r\n 0,\r\n 2\r\n);\r\n-> at android.bluetooth.DckGattTest.testDiscoverDkGattService(DckGattTest.kt:193)\r\nActually,
there were zero interactions with this mock.
\r\n\r\n\tat android.bluetooth.DckGattTest.testDiscoverDkGattService(DckGattTest.kt:193)\r\n",
"action_in_progress":"UNSET","className":"android.bluetooth.DckGattTest","testName":"testDiscoverDkGattService[connected=false]"}
有知道是缺少什么文件吗?