Add UUID to service data and TX power to extended properties.
Bug: 255682209 Test: atest NearbyUnitTests and end-to-end device tests Ignore-AOSP-First: nearby_not_in_aosp_yet Change-Id: I73449ac45fa63b98a5c65baa37a5f5c48bfb811a
This commit is contained in:
parent
13c91a0b0e
commit
de43331abf
2 changed files with 41 additions and 2 deletions
|
|
@ -269,12 +269,25 @@ public class ChreDiscoveryProvider extends AbstractDiscoveryProvider {
|
|||
DataElement.DataType.BLE_ADDRESS,
|
||||
filterResult.getBluetoothAddress().toByteArray()));
|
||||
}
|
||||
// BlE TX Power appended to Data Element.
|
||||
if (filterResult.hasTxPower()) {
|
||||
presenceDeviceBuilder.addExtendedProperty(
|
||||
new DataElement(
|
||||
DataElement.DataType.TX_POWER,
|
||||
new byte[]{(byte) filterResult.getTxPower()}));
|
||||
}
|
||||
// BLE Service data appended to Data Elements.
|
||||
if (filterResult.hasBleServiceData()) {
|
||||
// Retrieves the length of the service data from the first byte,
|
||||
// and then skips the first byte and returns data[1 .. dataLength)
|
||||
// as the DataElement value.
|
||||
int dataLength = Byte.toUnsignedInt(
|
||||
filterResult.getBleServiceData().byteAt(0));
|
||||
presenceDeviceBuilder.addExtendedProperty(
|
||||
new DataElement(
|
||||
DataElement.DataType.BLE_SERVICE_DATA,
|
||||
filterResult.getBleServiceData().toByteArray()));
|
||||
filterResult.getBleServiceData()
|
||||
.substring(1, 1 + dataLength).toByteArray()));
|
||||
}
|
||||
// Add action
|
||||
if (filterResult.hasIntent()) {
|
||||
|
|
|
|||
|
|
@ -55,6 +55,10 @@ public class ChreDiscoveryProviderTest {
|
|||
|
||||
private static final int DATA_TYPE_CONNECTION_STATUS_KEY = 10;
|
||||
private static final int DATA_TYPE_BATTERY_KEY = 11;
|
||||
private static final int DATA_TYPE_TX_POWER_KEY = 5;
|
||||
private static final int DATA_TYPE_BLUETOOTH_ADDR_KEY = 101;
|
||||
private static final int DATA_TYPE_FP_ACCOUNT_KEY = 9;
|
||||
private static final int DATA_TYPE_BLE_SERVICE_DATA_KEY = 100;
|
||||
|
||||
private ChreDiscoveryProvider mChreDiscoveryProvider;
|
||||
|
||||
|
|
@ -111,10 +115,23 @@ public class ChreDiscoveryProviderTest {
|
|||
public void testOnNearbyDeviceDiscoveredWithDataElements() {
|
||||
final byte [] connectionStatus = new byte[] {1, 2, 3};
|
||||
final byte [] batteryStatus = new byte[] {4, 5, 6};
|
||||
final byte [] txPower = new byte[] {2};
|
||||
final byte [] bluetoothAddr = new byte[] {1, 2, 3, 4, 5, 6};
|
||||
final byte [] fastPairAccountKey = new byte[16];
|
||||
// First byte is length of service data, padding zeros should be thrown away.
|
||||
final byte [] bleServiceData = new byte[] {5, 1, 2, 3, 4, 5, 0, 0, 0, 0};
|
||||
|
||||
final List<DataElement> expectedExtendedProperties = new ArrayList<>();
|
||||
expectedExtendedProperties.add(new DataElement(DATA_TYPE_CONNECTION_STATUS_KEY,
|
||||
connectionStatus));
|
||||
expectedExtendedProperties.add(new DataElement(DATA_TYPE_BATTERY_KEY, batteryStatus));
|
||||
expectedExtendedProperties.add(new DataElement(DATA_TYPE_TX_POWER_KEY, txPower));
|
||||
expectedExtendedProperties.add(
|
||||
new DataElement(DATA_TYPE_BLUETOOTH_ADDR_KEY, bluetoothAddr));
|
||||
expectedExtendedProperties.add(
|
||||
new DataElement(DATA_TYPE_FP_ACCOUNT_KEY, fastPairAccountKey));
|
||||
expectedExtendedProperties.add(
|
||||
new DataElement(DATA_TYPE_BLE_SERVICE_DATA_KEY, new byte[] {1, 2, 3, 4, 5}));
|
||||
|
||||
Blefilter.PublicCredential credential =
|
||||
Blefilter.PublicCredential.newBuilder()
|
||||
|
|
@ -128,6 +145,8 @@ public class ChreDiscoveryProviderTest {
|
|||
Blefilter.BleFilterResult.newBuilder()
|
||||
.setTxPower(2)
|
||||
.setRssi(1)
|
||||
.setBluetoothAddress(ByteString.copyFrom(bluetoothAddr))
|
||||
.setBleServiceData(ByteString.copyFrom(bleServiceData))
|
||||
.setPublicCredential(credential)
|
||||
.addDataElement(Blefilter.DataElement.newBuilder()
|
||||
.setKey(
|
||||
|
|
@ -143,6 +162,13 @@ public class ChreDiscoveryProviderTest {
|
|||
.setValue(ByteString.copyFrom(batteryStatus))
|
||||
.setValueLength(batteryStatus.length)
|
||||
)
|
||||
.addDataElement(Blefilter.DataElement.newBuilder()
|
||||
.setKey(
|
||||
Blefilter.DataElement.ElementType
|
||||
.DE_FAST_PAIR_ACCOUNT_KEY)
|
||||
.setValue(ByteString.copyFrom(fastPairAccountKey))
|
||||
.setValueLength(fastPairAccountKey.length)
|
||||
)
|
||||
.build();
|
||||
Blefilter.BleFilterResults results =
|
||||
Blefilter.BleFilterResults.newBuilder().addResult(result).build();
|
||||
|
|
@ -160,7 +186,7 @@ public class ChreDiscoveryProviderTest {
|
|||
|
||||
List<DataElement> extendedProperties = PresenceDiscoveryResult
|
||||
.fromDevice(mNearbyDevice.getValue()).getExtendedProperties();
|
||||
assertThat(expectedExtendedProperties.equals(extendedProperties)).isTrue();
|
||||
assertThat(extendedProperties).containsExactlyElementsIn(expectedExtendedProperties);
|
||||
}
|
||||
|
||||
private static class InLineExecutor implements Executor {
|
||||
|
|
|
|||
Loading…
Reference in a new issue