Commit 0c8c5dae authored by Anton Bershanskiy's avatar Anton Bershanskiy Committed by Commit Bot

Bluetooth: propagate advertising flags on Android

Added getScanRecord_getAdvertiseFlags() to ScanResultWrapper to be
called by ScanCallback.onScanResult to pass to
ChromeBluetoothAdapterJni.get().createOrUpdateDeviceOnScan() which
sends them to UpdateAdvertisementData().

Bug: 661814
Change-Id: Iad8c49936a796d4ca4ec39782c0f28ea66286271
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144153Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Commit-Queue: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758541}
parent 8519ac7c
......@@ -96,6 +96,7 @@ Anna Henningsen <anna@addaleax.net>
Anne Kao <annekao94@gmail.com>
Anssi Hannula <anssi.hannula@iki.fi>
Anthony Halliday <anth.halliday12@gmail.com>
Anton Bershanskiy <bershanskiy@pm.me>
Anton Obzhirov <a.obzhirov@samsung.com>
Antonin Hildebrand <antonin.hildebrand@gmail.com>
Antonio Gomes <a1.gomes@sisa.samsung.com>
......
......@@ -296,7 +296,8 @@ final class ChromeBluetoothAdapter extends BroadcastReceiver {
result.getDevice().getAddress(), result.getDevice(),
result.getScanRecord_getDeviceName(), result.getRssi(), uuid_strings,
result.getScanRecord_getTxPowerLevel(), serviceDataKeys, serviceDataValues,
manufacturerDataKeys, manufacturerDataValues);
manufacturerDataKeys, manufacturerDataValues,
result.getScanRecord_getAdvertiseFlags());
}
}
......@@ -360,7 +361,7 @@ final class ChromeBluetoothAdapter extends BroadcastReceiver {
Wrappers.BluetoothDeviceWrapper deviceWrapper, String localName, int rssi,
String[] advertisedUuids, int txPower, String[] serviceDataKeys,
Object[] serviceDataValues, int[] manufacturerDataKeys,
Object[] manufacturerDataValues);
Object[] manufacturerDataValues, int advertiseFlags);
// Binds to BluetoothAdapterAndroid::nativeOnAdapterStateChanged
void onAdapterStateChanged(
......
......@@ -314,6 +314,10 @@ class Wrappers {
public String getScanRecord_getDeviceName() {
return mScanResult.getScanRecord().getDeviceName();
}
public int getScanRecord_getAdvertiseFlags() {
return mScanResult.getScanRecord().getAdvertiseFlags();
}
}
/**
......
......@@ -178,8 +178,8 @@ void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan(
const JavaParamRef<jobjectArray>& service_data_values, // Java Type: byte[]
const JavaParamRef<jintArray>& manufacturer_data_keys, // Java Type: int[]
const JavaParamRef<jobjectArray>&
manufacturer_data_values // Java Type: byte[]
) {
manufacturer_data_values, // Java Type: byte[]
int32_t advertisement_flags) {
std::string device_address = ConvertJavaStringToUTF8(env, address);
auto iter = devices_.find(device_address);
......@@ -235,7 +235,11 @@ void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan(
int8_t clamped_tx_power = BluetoothDevice::ClampPower(tx_power);
device_android->UpdateAdvertisementData(
BluetoothDevice::ClampPower(rssi), base::nullopt /* flags */,
BluetoothDevice::ClampPower(rssi),
// Android uses -1 to indicate no advertising flags.
// https://developer.android.com/reference/android/bluetooth/le/ScanRecord.html#getAdvertiseFlags()
advertisement_flags == -1 ? base::nullopt
: base::make_optional(advertisement_flags),
advertised_bluetooth_uuids,
// Android uses INT32_MIN to indicate no Advertised Tx Power.
// https://developer.android.com/reference/android/bluetooth/le/ScanRecord.html#getTxPowerLevel()
......
......@@ -104,8 +104,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterAndroid final
const base::android::JavaParamRef<jintArray>&
manufacturer_data_keys, // Java Type: int[]
const base::android::JavaParamRef<jobjectArray>&
manufacturer_data_values // Java Type: byte[]
);
manufacturer_data_values, // Java Type: byte[]
int32_t advertisement_flags);
protected:
BluetoothAdapterAndroid();
......
......@@ -365,7 +365,7 @@ TEST_F(BluetoothTest, MAYBE_GetServiceDataUUIDs_GetServiceDataForUUID) {
// Receive Advertisement with service data.
BluetoothDevice* device2 = SimulateLowEnergyDevice(1);
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_ANDROID)
EXPECT_TRUE(device2->GetAdvertisingDataFlags().has_value());
EXPECT_EQ(0x04, device2->GetAdvertisingDataFlags().value());
#endif
......@@ -405,7 +405,7 @@ TEST_F(BluetoothTest, MAYBE_GetServiceDataUUIDs_GetServiceDataForUUID) {
// Receive Advertisement with new service data and empty manufacturer data.
SimulateLowEnergyDevice(2);
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_ANDROID)
EXPECT_TRUE(device2->GetAdvertisingDataFlags().has_value());
EXPECT_EQ(0x05, device2->GetAdvertisingDataFlags().value());
#endif
......@@ -476,7 +476,7 @@ TEST_F(BluetoothTest, MAYBE_AdvertisementData_Discovery) {
EXPECT_EQ(0, observer.device_changed_count());
EXPECT_EQ(ToInt8(TestRSSI::LOWEST), device->GetInquiryRSSI().value());
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_ANDROID)
EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value());
EXPECT_EQ(0x04, device->GetAdvertisingDataFlags().value());
#endif
......@@ -517,7 +517,7 @@ TEST_F(BluetoothTest, MAYBE_AdvertisementData_Discovery) {
EXPECT_EQ(2, observer.device_changed_count());
EXPECT_EQ(ToInt8(TestRSSI::LOWER), device->GetInquiryRSSI().value());
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_ANDROID)
EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value());
EXPECT_EQ(0x05, device->GetAdvertisingDataFlags().value());
#endif
......@@ -570,7 +570,7 @@ TEST_F(BluetoothTest, MAYBE_AdvertisementData_Discovery) {
EXPECT_EQ(4, observer.device_changed_count());
EXPECT_EQ(ToInt8(TestRSSI::LOWEST), device->GetInquiryRSSI().value());
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_ANDROID)
EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value());
EXPECT_EQ(0x04, device->GetAdvertisingDataFlags().value());
#endif
......@@ -870,7 +870,7 @@ TEST_F(BluetoothTest, MAYBE_AdvertisementData_DiscoveryDuringConnection) {
EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDGenericAccess),
BluetoothUUID(kTestUUIDGenericAttribute)}),
device->GetUUIDs());
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_ANDROID)
EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value());
EXPECT_EQ(0x04, device->GetAdvertisingDataFlags().value());
#endif
......@@ -902,7 +902,7 @@ TEST_F(BluetoothTest, MAYBE_AdvertisementData_DiscoveryDuringConnection) {
EXPECT_EQ(3, observer.device_changed_count());
EXPECT_EQ(ToInt8(TestRSSI::LOWER), device->GetInquiryRSSI().value());
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_ANDROID)
EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value());
EXPECT_EQ(0x05, device->GetAdvertisingDataFlags().value());
#endif
......@@ -987,7 +987,7 @@ TEST_F(BluetoothTest, MAYBE_AdvertisementData_ConnectionDuringDiscovery) {
EXPECT_EQ(0, observer.device_changed_count());
EXPECT_EQ(ToInt8(TestRSSI::LOWEST), device->GetInquiryRSSI().value());
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_ANDROID)
EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value());
EXPECT_EQ(0x04, device->GetAdvertisingDataFlags().value());
#endif
......@@ -1018,7 +1018,7 @@ TEST_F(BluetoothTest, MAYBE_AdvertisementData_ConnectionDuringDiscovery) {
EXPECT_EQ(1, observer.device_changed_count());
EXPECT_EQ(ToInt8(TestRSSI::LOWER), device->GetInquiryRSSI().value());
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_ANDROID)
EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value());
EXPECT_EQ(0x05, device->GetAdvertisingDataFlags().value());
#endif
......@@ -1058,7 +1058,7 @@ TEST_F(BluetoothTest, MAYBE_AdvertisementData_ConnectionDuringDiscovery) {
EXPECT_EQ(3, observer.device_changed_count());
EXPECT_EQ(ToInt8(TestRSSI::LOWER), device->GetInquiryRSSI().value());
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_ANDROID)
EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value());
EXPECT_EQ(0x05, device->GetAdvertisingDataFlags().value());
#endif
......@@ -1082,7 +1082,7 @@ TEST_F(BluetoothTest, MAYBE_AdvertisementData_ConnectionDuringDiscovery) {
EXPECT_EQ(4, observer.device_changed_count());
EXPECT_EQ(ToInt8(TestRSSI::LOWEST), device->GetInquiryRSSI().value());
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_ANDROID)
EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value());
EXPECT_EQ(0x04, device->GetAdvertisingDataFlags().value());
#endif
......
......@@ -152,7 +152,7 @@ class Fakes {
mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(new FakeBluetoothDevice(this, "01:00:00:90:1E:BE",
"FakeBluetoothDevice"),
"FakeBluetoothDevice", TestRSSI.LOWEST, uuids,
"FakeBluetoothDevice", TestRSSI.LOWEST, 4, uuids,
TestTxPower.LOWEST, serviceData, manufacturerData));
break;
}
......@@ -173,8 +173,8 @@ class Fakes {
mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(new FakeBluetoothDevice(this, "01:00:00:90:1E:BE",
"FakeBluetoothDevice"),
"Local Device Name", TestRSSI.LOWER, uuids, TestTxPower.LOWER,
serviceData, manufacturerData));
"Local Device Name", TestRSSI.LOWER, 5, uuids,
TestTxPower.LOWER, serviceData, manufacturerData));
break;
}
case 3: {
......@@ -182,7 +182,7 @@ class Fakes {
mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(
new FakeBluetoothDevice(this, "01:00:00:90:1E:BE", ""),
"Local Device Name", TestRSSI.LOW, uuids, NO_TX_POWER, null,
"Local Device Name", TestRSSI.LOW, -1, uuids, NO_TX_POWER, null,
null));
break;
......@@ -192,8 +192,8 @@ class Fakes {
mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(
new FakeBluetoothDevice(this, "02:00:00:8B:74:63", ""),
"Local Device Name", TestRSSI.MEDIUM, uuids, NO_TX_POWER, null,
null));
"Local Device Name", TestRSSI.MEDIUM, -1, uuids, NO_TX_POWER,
null, null));
break;
}
......@@ -202,8 +202,8 @@ class Fakes {
mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(
new FakeBluetoothDevice(this, "01:00:00:90:1E:BE", null),
"Local Device Name", TestRSSI.HIGH, uuids, NO_TX_POWER, null,
null));
"Local Device Name", TestRSSI.HIGH, -1, uuids, NO_TX_POWER,
null, null));
break;
}
case 6: {
......@@ -211,8 +211,8 @@ class Fakes {
mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(
new FakeBluetoothDevice(this, "02:00:00:8B:74:63", null),
"Local Device Name", TestRSSI.LOWEST, uuids, NO_TX_POWER, null,
null));
"Local Device Name", TestRSSI.LOWEST, -1, uuids, NO_TX_POWER,
null, null));
break;
}
case 7: {
......@@ -226,7 +226,7 @@ class Fakes {
mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(new FakeBluetoothDevice(
this, "01:00:00:90:1E:BE", "U2F FakeDevice"),
"Local Device Name", TestRSSI.LOWEST, uuids, NO_TX_POWER,
"Local Device Name", TestRSSI.LOWEST, -1, uuids, NO_TX_POWER,
serviceData, null));
break;
}
......@@ -370,17 +370,19 @@ class Fakes {
private final String mLocalName;
private final int mRssi;
private final int mTxPower;
private final int mAdvertisementFlags;
private final ArrayList<ParcelUuid> mUuids;
private final Map<ParcelUuid, byte[]> mServiceData;
private final SparseArray<byte[]> mManufacturerData;
FakeScanResult(FakeBluetoothDevice device, String localName, int rssi,
ArrayList<ParcelUuid> uuids, int txPower, Map<ParcelUuid, byte[]> serviceData,
SparseArray<byte[]> manufacturerData) {
int advertisementFlags, ArrayList<ParcelUuid> uuids, int txPower,
Map<ParcelUuid, byte[]> serviceData, SparseArray<byte[]> manufacturerData) {
super(null);
mDevice = device;
mLocalName = localName;
mRssi = rssi;
mAdvertisementFlags = advertisementFlags;
mUuids = uuids;
mTxPower = txPower;
mServiceData = serviceData;
......@@ -421,6 +423,11 @@ class Fakes {
public String getScanRecord_getDeviceName() {
return mLocalName;
}
@Override
public int getScanRecord_getAdvertiseFlags() {
return mAdvertisementFlags;
}
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment