Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Unified Diff: device/bluetooth/test/bluetooth_test_mac.mm

Issue 2248913002: bluetooth: Implement RSSI and Tx Power on macOS and Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-refactor-adv-data
Patch Set: Address jyasskin's comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/test/bluetooth_test_mac.mm
diff --git a/device/bluetooth/test/bluetooth_test_mac.mm b/device/bluetooth/test/bluetooth_test_mac.mm
index 7cf74db2fb007ea8a5b5f4e3dfda16855ed697a5..d7e6f4b63ad6020d8ebfeed19d13e4afb3bd52ee 100644
--- a/device/bluetooth/test/bluetooth_test_mac.mm
+++ b/device/bluetooth/test/bluetooth_test_mac.mm
@@ -60,7 +60,8 @@ namespace {
scoped_nsobject<NSDictionary> CreateAdvertisementData(
NSString* name,
NSArray* uuids,
- NSDictionary* service_data) {
+ NSDictionary* service_data,
+ NSNumber* tx_power) {
NSMutableDictionary* advertisement_data(
[NSMutableDictionary dictionaryWithDictionary:@{
CBAdvertisementDataIsConnectable : @(YES)
@@ -80,6 +81,11 @@ scoped_nsobject<NSDictionary> CreateAdvertisementData(
forKey:CBAdvertisementDataServiceDataKey];
}
+ if (tx_power) {
+ [advertisement_data setObject:tx_power
+ forKey:CBAdvertisementDataTxPowerLevelKey];
+ }
+
return scoped_nsobject<NSDictionary>(advertisement_data,
base::scoped_policy::RETAIN);
}
@@ -147,12 +153,15 @@ BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) {
const char* identifier;
NSString* name;
NSArray* uuids;
+ NSNumber* rssi;
NSDictionary* service_data;
+ NSNumber* tx_power;
switch (device_ordinal) {
case 1:
identifier = kTestPeripheralUUID1.c_str();
name = @(kTestDeviceName.c_str());
+ rssi = @(static_cast<int8_t>(TestRSSI::LOWEST));
uuids = @[
[CBUUID UUIDWithString:@(kTestUUIDGenericAccess.c_str())],
[CBUUID UUIDWithString:@(kTestUUIDGenericAttribute.c_str())]
@@ -161,10 +170,12 @@ BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) {
[CBUUID UUIDWithString:@(kTestUUIDHeartRate.c_str())] :
[NSData dataWithBytes:(unsigned char[]){1} length:1]
};
+ tx_power = @(static_cast<int8_t>(TestTxPower::LOWEST));
break;
case 2:
identifier = kTestPeripheralUUID1.c_str();
name = @(kTestDeviceName.c_str());
+ rssi = @(static_cast<int8_t>(TestRSSI::LOWER));
uuids = @[
[CBUUID UUIDWithString:@(kTestUUIDImmediateAlert.c_str())],
[CBUUID UUIDWithString:@(kTestUUIDLinkLoss.c_str())]
@@ -175,32 +186,41 @@ BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) {
[CBUUID UUIDWithString:@(kTestUUIDImmediateAlert.c_str())] :
[NSData dataWithBytes:(unsigned char[]){0} length:1]
};
+ tx_power = @(static_cast<int8_t>(TestTxPower::LOWER));
break;
case 3:
identifier = kTestPeripheralUUID1.c_str();
name = @(kTestDeviceNameEmpty.c_str());
+ rssi = @(static_cast<int8_t>(TestRSSI::LOW));
uuids = nil;
service_data = nil;
+ tx_power = nil;
break;
case 4:
identifier = kTestPeripheralUUID2.c_str();
name = @(kTestDeviceNameEmpty.c_str());
+ rssi = @(static_cast<int8_t>(TestRSSI::MEDIUM));
uuids = nil;
service_data = nil;
+ tx_power = nil;
break;
case 5:
identifier = kTestPeripheralUUID1.c_str();
name = nil;
+ rssi = @(static_cast<int8_t>(TestRSSI::HIGH));
uuids = nil;
service_data = nil;
+ tx_power = nil;
break;
default:
NOTREACHED() << "SimulateLowEnergyDevice not implemented for "
<< device_ordinal;
identifier = nil;
name = nil;
+ rssi = nil;
uuids = nil;
service_data = nil;
+ tx_power = nil;
}
scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc]
initWithUTF8StringIdentifier:identifier
@@ -209,8 +229,9 @@ BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) {
[central_manager_delegate
centralManager:central_manager
didDiscoverPeripheral:mock_peripheral.get().peripheral
- advertisementData:CreateAdvertisementData(name, uuids, service_data)
- RSSI:@(0)];
+ advertisementData:CreateAdvertisementData(name, uuids, service_data,
+ tx_power)
+ RSSI:rssi];
return observer.last_device();
}
« device/bluetooth/bluetooth_device_unittest.cc ('K') | « device/bluetooth/test/bluetooth_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698