Commit aee525fc authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS PhoneHub] Add Bluetooth public address field to RemoteDevice

This includes:
(1) Adding to BetterTogetherDeviceMetadata Proto.
(2) Adding to Mojo type.
(3) Adding to C++ RemoteDevice and RemoteDeviceRef classes.
(4) Updating tests.

Note that this field is not yet set during enrollment; a follow-up CL
will do this.

Bug: 1106937
Change-Id: I859efa86a7a57cff6eea185e2945a9201d14d508
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2318685
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarJosh Nohle <nohle@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795207}
parent fd8d55e7
...@@ -508,7 +508,8 @@ void EasyUnlockServiceSignin::OnUserDataLoaded( ...@@ -508,7 +508,8 @@ void EasyUnlockServiceSignin::OnUserDataLoaded(
account_id.GetUserEmail(), std::string() /* instance_id */, account_id.GetUserEmail(), std::string() /* instance_id */,
std::string() /* name */, std::string() /* pii_free_name */, std::string() /* name */, std::string() /* pii_free_name */,
decoded_public_key, decoded_psk /* persistent_symmetric_key */, decoded_public_key, decoded_psk /* persistent_symmetric_key */,
0L /* last_update_time_millis */, software_features, beacon_seeds); 0L /* last_update_time_millis */, software_features, beacon_seeds,
std::string() /* bluetooth_public_address */);
remote_devices.push_back(remote_device); remote_devices.push_back(remote_device);
PA_LOG(VERBOSE) << "Loaded Remote Device:\n" PA_LOG(VERBOSE) << "Loaded Remote Device:\n"
......
include_rules = [ include_rules = [
"+device/bluetooth/public/cpp",
"+mojo/public/cpp", "+mojo/public/cpp",
"+third_party/securemessage", "+third_party/securemessage",
] ]
...@@ -20,7 +20,9 @@ sources = [ ...@@ -20,7 +20,9 @@ sources = [
public_deps = [ public_deps = [
"//chromeos/components/multidevice", "//chromeos/components/multidevice",
"//chromeos/components/multidevice/logging",
"//chromeos/services/device_sync/proto", "//chromeos/services/device_sync/proto",
"//device/bluetooth/public/cpp",
] ]
type_mappings = [ type_mappings = [
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#include "chromeos/components/multidevice/mojom/multidevice_mojom_traits.h" #include "chromeos/components/multidevice/mojom/multidevice_mojom_traits.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "chromeos/components/multidevice/logging/logging.h"
#include "chromeos/components/multidevice/remote_device_ref.h" #include "chromeos/components/multidevice/remote_device_ref.h"
#include "device/bluetooth/public/cpp/bluetooth_address.h"
#include "mojo/public/cpp/base/time_mojom_traits.h" #include "mojo/public/cpp/base/time_mojom_traits.h"
namespace mojo { namespace mojo {
...@@ -113,6 +115,14 @@ StructTraits<chromeos::multidevice::mojom::RemoteDeviceDataView, ...@@ -113,6 +115,14 @@ StructTraits<chromeos::multidevice::mojom::RemoteDeviceDataView,
return remote_device.beacon_seeds; return remote_device.beacon_seeds;
} }
const std::string&
StructTraits<chromeos::multidevice::mojom::RemoteDeviceDataView,
chromeos::multidevice::RemoteDevice>::
bluetooth_public_address(
const chromeos::multidevice::RemoteDevice& remote_device) {
return remote_device.bluetooth_public_address;
}
bool StructTraits<chromeos::multidevice::mojom::RemoteDeviceDataView, bool StructTraits<chromeos::multidevice::mojom::RemoteDeviceDataView,
chromeos::multidevice::RemoteDevice>:: chromeos::multidevice::RemoteDevice>::
Read(chromeos::multidevice::mojom::RemoteDeviceDataView in, Read(chromeos::multidevice::mojom::RemoteDeviceDataView in,
...@@ -127,10 +137,29 @@ bool StructTraits<chromeos::multidevice::mojom::RemoteDeviceDataView, ...@@ -127,10 +137,29 @@ bool StructTraits<chromeos::multidevice::mojom::RemoteDeviceDataView,
!in.ReadPersistentSymmetricKey(&out->persistent_symmetric_key) || !in.ReadPersistentSymmetricKey(&out->persistent_symmetric_key) ||
!in.ReadLastUpdateTime(&last_update_time) || !in.ReadLastUpdateTime(&last_update_time) ||
!in.ReadSoftwareFeatures(&out->software_features) || !in.ReadSoftwareFeatures(&out->software_features) ||
!in.ReadBeaconSeeds(&out->beacon_seeds)) { !in.ReadBeaconSeeds(&out->beacon_seeds) ||
!in.ReadBluetoothPublicAddress(&out->bluetooth_public_address)) {
return false; return false;
} }
// Note: |bluetooth_public_address| may be empty if it has not been synced.
if (!out->bluetooth_public_address.empty()) {
std::string bluetooth_public_address_before_canonicalizing =
out->bluetooth_public_address;
// Canonicalize address, which capitalizes all hex digits. Note that if the
// input address is invalid, CanonicalizeAddress() returns an empty string.
out->bluetooth_public_address =
device::CanonicalizeBluetoothAddress(out->bluetooth_public_address);
if (out->bluetooth_public_address.empty()) {
PA_LOG(ERROR) << "Invalid bluetooth public address \""
<< bluetooth_public_address_before_canonicalizing
<< "\" for device with ID \"" << out->GetDeviceId()
<< "\"; clearing.";
}
}
out->public_key = out->public_key =
chromeos::multidevice::RemoteDevice::DerivePublicKey(device_id); chromeos::multidevice::RemoteDevice::DerivePublicKey(device_id);
out->last_update_time_millis = last_update_time.ToJavaTime(); out->last_update_time_millis = last_update_time.ToJavaTime();
......
...@@ -57,6 +57,8 @@ class StructTraits<chromeos::multidevice::mojom::RemoteDeviceDataView, ...@@ -57,6 +57,8 @@ class StructTraits<chromeos::multidevice::mojom::RemoteDeviceDataView,
software_features(const chromeos::multidevice::RemoteDevice& remote_device); software_features(const chromeos::multidevice::RemoteDevice& remote_device);
static const std::vector<chromeos::multidevice::BeaconSeed>& beacon_seeds( static const std::vector<chromeos::multidevice::BeaconSeed>& beacon_seeds(
const chromeos::multidevice::RemoteDevice& remote_device); const chromeos::multidevice::RemoteDevice& remote_device);
static const std::string& bluetooth_public_address(
const chromeos::multidevice::RemoteDevice& remote_device);
static bool Read(chromeos::multidevice::mojom::RemoteDeviceDataView in, static bool Read(chromeos::multidevice::mojom::RemoteDeviceDataView in,
chromeos::multidevice::RemoteDevice* out); chromeos::multidevice::RemoteDevice* out);
......
...@@ -62,6 +62,7 @@ TEST(MultiDeviceMojomStructTraitsTest, RemoteDevice) { ...@@ -62,6 +62,7 @@ TEST(MultiDeviceMojomStructTraitsTest, RemoteDevice) {
input.last_update_time_millis = 3L; input.last_update_time_millis = 3L;
input.software_features = software_features; input.software_features = software_features;
input.beacon_seeds = {CreateTestBeaconSeed()}; input.beacon_seeds = {CreateTestBeaconSeed()};
input.bluetooth_public_address = "01:23:45:67:89:AB";
chromeos::multidevice::RemoteDevice output; chromeos::multidevice::RemoteDevice output;
EXPECT_TRUE(mojo::test::SerializeAndDeserialize< EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
...@@ -81,6 +82,7 @@ TEST(MultiDeviceMojomStructTraitsTest, RemoteDevice) { ...@@ -81,6 +82,7 @@ TEST(MultiDeviceMojomStructTraitsTest, RemoteDevice) {
output.beacon_seeds[0].start_time().ToJavaTime()); output.beacon_seeds[0].start_time().ToJavaTime());
EXPECT_EQ(kTestBeaconSeedEndTimeMillis, EXPECT_EQ(kTestBeaconSeedEndTimeMillis,
output.beacon_seeds[0].end_time().ToJavaTime()); output.beacon_seeds[0].end_time().ToJavaTime());
EXPECT_EQ("01:23:45:67:89:AB", output.bluetooth_public_address);
} }
TEST(DeviceSyncMojomEnumTraitsTest, SoftwareFeature) { TEST(DeviceSyncMojomEnumTraitsTest, SoftwareFeature) {
......
...@@ -94,4 +94,9 @@ struct RemoteDevice { ...@@ -94,4 +94,9 @@ struct RemoteDevice {
// metadata synced for over 30 days, it is possible that a connection will not // metadata synced for over 30 days, it is possible that a connection will not
// be able to be established over BLE. // be able to be established over BLE.
array<BeaconSeed> beacon_seeds; array<BeaconSeed> beacon_seeds;
// Bluetooth public address, formatted as a hex string with colons and capital
// letters (example: "01:23:45:67:89:AB"). If the device does not have a
// synced address, this field is empty.
string bluetooth_public_address;
}; };
...@@ -37,7 +37,8 @@ RemoteDevice::RemoteDevice( ...@@ -37,7 +37,8 @@ RemoteDevice::RemoteDevice(
const std::string& persistent_symmetric_key, const std::string& persistent_symmetric_key,
int64_t last_update_time_millis, int64_t last_update_time_millis,
const std::map<SoftwareFeature, SoftwareFeatureState>& software_features, const std::map<SoftwareFeature, SoftwareFeatureState>& software_features,
const std::vector<BeaconSeed>& beacon_seeds) const std::vector<BeaconSeed>& beacon_seeds,
const std::string& bluetooth_public_address)
: user_email(user_email), : user_email(user_email),
instance_id(instance_id), instance_id(instance_id),
name(name), name(name),
...@@ -46,7 +47,8 @@ RemoteDevice::RemoteDevice( ...@@ -46,7 +47,8 @@ RemoteDevice::RemoteDevice(
persistent_symmetric_key(persistent_symmetric_key), persistent_symmetric_key(persistent_symmetric_key),
last_update_time_millis(last_update_time_millis), last_update_time_millis(last_update_time_millis),
software_features(software_features), software_features(software_features),
beacon_seeds(beacon_seeds) {} beacon_seeds(beacon_seeds),
bluetooth_public_address(bluetooth_public_address) {}
RemoteDevice::RemoteDevice(const RemoteDevice& other) = default; RemoteDevice::RemoteDevice(const RemoteDevice& other) = default;
...@@ -63,7 +65,8 @@ bool RemoteDevice::operator==(const RemoteDevice& other) const { ...@@ -63,7 +65,8 @@ bool RemoteDevice::operator==(const RemoteDevice& other) const {
persistent_symmetric_key == other.persistent_symmetric_key && persistent_symmetric_key == other.persistent_symmetric_key &&
last_update_time_millis == other.last_update_time_millis && last_update_time_millis == other.last_update_time_millis &&
software_features == other.software_features && software_features == other.software_features &&
beacon_seeds == other.beacon_seeds; beacon_seeds == other.beacon_seeds &&
bluetooth_public_address == other.bluetooth_public_address;
} }
bool RemoteDevice::operator<(const RemoteDevice& other) const { bool RemoteDevice::operator<(const RemoteDevice& other) const {
......
...@@ -42,6 +42,11 @@ struct RemoteDevice { ...@@ -42,6 +42,11 @@ struct RemoteDevice {
std::map<SoftwareFeature, SoftwareFeatureState> software_features; std::map<SoftwareFeature, SoftwareFeatureState> software_features;
std::vector<BeaconSeed> beacon_seeds; std::vector<BeaconSeed> beacon_seeds;
// Bluetooth public address, formatted as a hex string with colons and capital
// letters (example: "01:23:45:67:89:AB"). If the device does not have a
// synced address, this field is empty.
std::string bluetooth_public_address;
RemoteDevice(); RemoteDevice();
RemoteDevice( RemoteDevice(
const std::string& user_email, const std::string& user_email,
...@@ -52,7 +57,8 @@ struct RemoteDevice { ...@@ -52,7 +57,8 @@ struct RemoteDevice {
const std::string& persistent_symmetric_key, const std::string& persistent_symmetric_key,
int64_t last_update_time_millis, int64_t last_update_time_millis,
const std::map<SoftwareFeature, SoftwareFeatureState>& software_features, const std::map<SoftwareFeature, SoftwareFeatureState>& software_features,
const std::vector<BeaconSeed>& beacon_seeds); const std::vector<BeaconSeed>& beacon_seeds,
const std::string& bluetooth_public_address);
RemoteDevice(const RemoteDevice& other); RemoteDevice(const RemoteDevice& other);
~RemoteDevice(); ~RemoteDevice();
......
...@@ -65,6 +65,9 @@ class RemoteDeviceRef { ...@@ -65,6 +65,9 @@ class RemoteDeviceRef {
const std::vector<BeaconSeed>& beacon_seeds() const { const std::vector<BeaconSeed>& beacon_seeds() const {
return remote_device_->beacon_seeds; return remote_device_->beacon_seeds;
} }
const std::string& bluetooth_public_address() const {
return remote_device_->bluetooth_public_address;
}
std::string GetDeviceId() const; std::string GetDeviceId() const;
SoftwareFeatureState GetSoftwareFeatureState( SoftwareFeatureState GetSoftwareFeatureState(
......
...@@ -14,6 +14,10 @@ namespace chromeos { ...@@ -14,6 +14,10 @@ namespace chromeos {
namespace multidevice { namespace multidevice {
namespace {
const char kFakeBluetoothPublicAddress[] = "01:23:45:67:89:AB";
} // namespace
class RemoteDeviceRefTest : public testing::Test { class RemoteDeviceRefTest : public testing::Test {
protected: protected:
RemoteDeviceRefTest() = default; RemoteDeviceRefTest() = default;
...@@ -33,7 +37,8 @@ class RemoteDeviceRefTest : public testing::Test { ...@@ -33,7 +37,8 @@ class RemoteDeviceRefTest : public testing::Test {
"user_email", "instance_id", "name", "pii_free_name", "public_key", "user_email", "instance_id", "name", "pii_free_name", "public_key",
"persistent_symmetric_key", 42000 /* last_update_time_millis */, "persistent_symmetric_key", 42000 /* last_update_time_millis */,
software_feature_to_state_map /* software_features */, software_feature_to_state_map /* software_features */,
beacon_seeds /* beacon_seeds */); beacon_seeds /* beacon_seeds */,
kFakeBluetoothPublicAddress /* bluetooth_public_address */);
} }
std::shared_ptr<RemoteDevice> remote_device_; std::shared_ptr<RemoteDevice> remote_device_;
...@@ -54,6 +59,8 @@ TEST_F(RemoteDeviceRefTest, TestFields) { ...@@ -54,6 +59,8 @@ TEST_F(RemoteDeviceRefTest, TestFields) {
EXPECT_EQ(remote_device_->last_update_time_millis, EXPECT_EQ(remote_device_->last_update_time_millis,
remote_device_ref.last_update_time_millis()); remote_device_ref.last_update_time_millis());
EXPECT_EQ(&remote_device_->beacon_seeds, &remote_device_ref.beacon_seeds()); EXPECT_EQ(&remote_device_->beacon_seeds, &remote_device_ref.beacon_seeds());
EXPECT_EQ(kFakeBluetoothPublicAddress,
remote_device_ref.bluetooth_public_address());
EXPECT_EQ(SoftwareFeatureState::kNotSupported, EXPECT_EQ(SoftwareFeatureState::kNotSupported,
remote_device_ref.GetSoftwareFeatureState( remote_device_ref.GetSoftwareFeatureState(
......
...@@ -59,6 +59,7 @@ std::string InstanceIdFromInt64(int64_t number) { ...@@ -59,6 +59,7 @@ std::string InstanceIdFromInt64(int64_t number) {
// Attributes of the default test remote device. // Attributes of the default test remote device.
const char kTestRemoteDeviceName[] = "remote device"; const char kTestRemoteDeviceName[] = "remote device";
const char kTestRemoteDevicePublicKey[] = "public key"; const char kTestRemoteDevicePublicKey[] = "public key";
const char kTestRemoteDeviceBluetoothPublicAddress[] = "01:23:45:67:89:AB";
RemoteDeviceRefBuilder::RemoteDeviceRefBuilder() { RemoteDeviceRefBuilder::RemoteDeviceRefBuilder() {
remote_device_ = std::make_shared<RemoteDevice>(CreateRemoteDeviceForTest()); remote_device_ = std::make_shared<RemoteDevice>(CreateRemoteDeviceForTest());
...@@ -123,6 +124,12 @@ RemoteDeviceRefBuilder& RemoteDeviceRefBuilder::SetBeaconSeeds( ...@@ -123,6 +124,12 @@ RemoteDeviceRefBuilder& RemoteDeviceRefBuilder::SetBeaconSeeds(
return *this; return *this;
} }
RemoteDeviceRefBuilder& RemoteDeviceRefBuilder::SetBluetoothPublicAddress(
const std::string& bluetooth_public_address) {
remote_device_->bluetooth_public_address = bluetooth_public_address;
return *this;
}
RemoteDeviceRef RemoteDeviceRefBuilder::Build() { RemoteDeviceRef RemoteDeviceRefBuilder::Build() {
return RemoteDeviceRef(remote_device_); return RemoteDeviceRef(remote_device_);
} }
...@@ -141,7 +148,8 @@ RemoteDevice CreateRemoteDeviceForTest() { ...@@ -141,7 +148,8 @@ RemoteDevice CreateRemoteDeviceForTest() {
kTestRemoteDeviceLastUpdateTimeMillis, software_features, kTestRemoteDeviceLastUpdateTimeMillis, software_features,
{multidevice::BeaconSeed( {multidevice::BeaconSeed(
kBeaconSeedData, base::Time::FromJavaTime(kBeaconSeedStartTimeMillis), kBeaconSeedData, base::Time::FromJavaTime(kBeaconSeedStartTimeMillis),
base::Time::FromJavaTime(kBeaconSeedEndTimeMillis))}); base::Time::FromJavaTime(kBeaconSeedEndTimeMillis))},
kTestRemoteDeviceBluetoothPublicAddress);
} }
RemoteDeviceRef CreateRemoteDeviceRefForTest() { RemoteDeviceRef CreateRemoteDeviceRefForTest() {
......
...@@ -18,6 +18,7 @@ namespace multidevice { ...@@ -18,6 +18,7 @@ namespace multidevice {
// Attributes of the default test remote device. // Attributes of the default test remote device.
extern const char kTestRemoteDeviceName[]; extern const char kTestRemoteDeviceName[];
extern const char kTestRemoteDevicePublicKey[]; extern const char kTestRemoteDevicePublicKey[];
extern const char kTestRemoteDeviceBluetoothPublicAddress[];
class RemoteDeviceRefBuilder { class RemoteDeviceRefBuilder {
public: public:
...@@ -37,6 +38,8 @@ class RemoteDeviceRefBuilder { ...@@ -37,6 +38,8 @@ class RemoteDeviceRefBuilder {
int64_t last_update_time_millis); int64_t last_update_time_millis);
RemoteDeviceRefBuilder& SetBeaconSeeds( RemoteDeviceRefBuilder& SetBeaconSeeds(
const std::vector<BeaconSeed>& beacon_seeds); const std::vector<BeaconSeed>& beacon_seeds);
RemoteDeviceRefBuilder& SetBluetoothPublicAddress(
const std::string& bluetooth_public_address);
RemoteDeviceRef Build(); RemoteDeviceRef Build();
private: private:
......
...@@ -24,7 +24,7 @@ message BeaconSeed { ...@@ -24,7 +24,7 @@ message BeaconSeed {
// Device metadata relevant to the suite of multi-device (Better Together) // Device metadata relevant to the suite of multi-device (Better Together)
// features. This data is sent to and received from CryptAuth--using end-to-end // features. This data is sent to and received from CryptAuth--using end-to-end
// encryption--as part of DeviceSync v2. // encryption--as part of DeviceSync v2.
// Next ID: 4 // Next ID: 5
message BetterTogetherDeviceMetadata { message BetterTogetherDeviceMetadata {
// A cryptographic public key associated with the device. // A cryptographic public key associated with the device.
// The format of this key is a serialized SecureMessage.GenericPublicKey. // The format of this key is a serialized SecureMessage.GenericPublicKey.
...@@ -35,4 +35,8 @@ message BetterTogetherDeviceMetadata { ...@@ -35,4 +35,8 @@ message BetterTogetherDeviceMetadata {
// A list of seeds for EID BLE advertisements targeting this device. // A list of seeds for EID BLE advertisements targeting this device.
repeated BeaconSeed beacon_seeds = 3; repeated BeaconSeed beacon_seeds = 3;
// Bluetooth public address, formatted as a hex string with colons and capital
// letters. Example: "01:23:45:67:89:AB"
string bluetooth_public_address = 4;
} }
...@@ -138,7 +138,8 @@ void RemoteDeviceLoader::OnPSKDerived( ...@@ -138,7 +138,8 @@ void RemoteDeviceLoader::OnPSKDerived(
user_email_, std::string() /* instance_id */, user_email_, std::string() /* instance_id */,
device.friendly_device_name(), device.no_pii_device_name(), device.friendly_device_name(), device.no_pii_device_name(),
device.public_key(), psk, device.last_update_time_millis(), device.public_key(), psk, device.last_update_time_millis(),
GetSoftwareFeatureToStateMap(device), multidevice_beacon_seeds); GetSoftwareFeatureToStateMap(device), multidevice_beacon_seeds,
device.bluetooth_address());
remote_devices_.push_back(remote_device); remote_devices_.push_back(remote_device);
......
...@@ -41,6 +41,7 @@ const char kTestRemoteDeviceNamePrefix[] = "name-"; ...@@ -41,6 +41,7 @@ const char kTestRemoteDeviceNamePrefix[] = "name-";
const char kTestRemoteDevicePiiFreeNamePrefix[] = "piiFreeName-"; const char kTestRemoteDevicePiiFreeNamePrefix[] = "piiFreeName-";
const char kTestRemoteDevicePublicKeyPrefix[] = "publicKey-"; const char kTestRemoteDevicePublicKeyPrefix[] = "publicKey-";
const char kTestRemoteDevicePskPrefix[] = "psk-"; const char kTestRemoteDevicePskPrefix[] = "psk-";
const char kTestRemoteDeviceBluetoothPublicAddressPrefix[] = "address-";
multidevice::RemoteDevice CreateRemoteDeviceForTest(const std::string& suffix, multidevice::RemoteDevice CreateRemoteDeviceForTest(const std::string& suffix,
bool has_instance_id, bool has_instance_id,
...@@ -62,7 +63,8 @@ multidevice::RemoteDevice CreateRemoteDeviceForTest(const std::string& suffix, ...@@ -62,7 +63,8 @@ multidevice::RemoteDevice CreateRemoteDeviceForTest(const std::string& suffix,
kTestRemoteDevicePskPrefix + suffix, 100L /* last_update_time_millis */, kTestRemoteDevicePskPrefix + suffix, 100L /* last_update_time_millis */,
{} /* software_features */, {} /* software_features */,
{multidevice::BeaconSeed(beacon_seed_data, base::Time::FromJavaTime(200L), {multidevice::BeaconSeed(beacon_seed_data, base::Time::FromJavaTime(200L),
base::Time::FromJavaTime(300L))}); base::Time::FromJavaTime(300L))},
kTestRemoteDeviceBluetoothPublicAddressPrefix + suffix);
} }
// Provide four fake RemoteDevices associated with a v1 DeviceSync. These // Provide four fake RemoteDevices associated with a v1 DeviceSync. These
......
...@@ -107,7 +107,9 @@ void RemoteDeviceV2LoaderImpl::AddRemoteDevice(const CryptAuthDevice& device, ...@@ -107,7 +107,9 @@ void RemoteDeviceV2LoaderImpl::AddRemoteDevice(const CryptAuthDevice& device,
device.last_update_time.ToJavaTime(), device.feature_states, device.last_update_time.ToJavaTime(), device.feature_states,
beto_metadata ? multidevice::FromCryptAuthV2SeedRepeatedPtrField( beto_metadata ? multidevice::FromCryptAuthV2SeedRepeatedPtrField(
beto_metadata->beacon_seeds()) beto_metadata->beacon_seeds())
: std::vector<multidevice::BeaconSeed>()); : std::vector<multidevice::BeaconSeed>(),
beto_metadata ? beto_metadata->bluetooth_public_address()
: std::string());
remaining_ids_to_process_.erase(device.instance_id()); remaining_ids_to_process_.erase(device.instance_id());
......
...@@ -28,6 +28,7 @@ const char kNoPiiDeviceNamePrefix[] = "no_pii_here"; ...@@ -28,6 +28,7 @@ const char kNoPiiDeviceNamePrefix[] = "no_pii_here";
const char kPublicKeyPrefix[] = "public_key"; const char kPublicKeyPrefix[] = "public_key";
const char kInstanceIdPrefix[] = "instance_id"; const char kInstanceIdPrefix[] = "instance_id";
const char kPskPlaceholder[] = "psk_placeholder"; const char kPskPlaceholder[] = "psk_placeholder";
const char kBluetoothPublicAddressPrefix[] = "bluetooth_public_address";
// The id of the user who the remote devices belong to. // The id of the user who the remote devices belong to.
const char kUserId[] = "example@gmail.com"; const char kUserId[] = "example@gmail.com";
...@@ -53,7 +54,8 @@ const int64_t kLastUpdateTimeMs = 3000; ...@@ -53,7 +54,8 @@ const int64_t kLastUpdateTimeMs = 3000;
// CryptAuthDevice.better_together_device_metadata.public_key is not set. // CryptAuthDevice.better_together_device_metadata.public_key is not set.
CryptAuthDevice CreateCryptAuthDevice(const std::string& suffix, CryptAuthDevice CreateCryptAuthDevice(const std::string& suffix,
bool has_beto_metadata, bool has_beto_metadata,
bool has_public_key) { bool has_public_key,
bool has_bluetooth_address) {
base::Optional<cryptauthv2::BetterTogetherDeviceMetadata> beto_metadata; base::Optional<cryptauthv2::BetterTogetherDeviceMetadata> beto_metadata;
if (has_beto_metadata) { if (has_beto_metadata) {
...@@ -67,6 +69,11 @@ CryptAuthDevice CreateCryptAuthDevice(const std::string& suffix, ...@@ -67,6 +69,11 @@ CryptAuthDevice CreateCryptAuthDevice(const std::string& suffix,
if (has_public_key) if (has_public_key)
beto_metadata->set_public_key(kPublicKeyPrefix + suffix); beto_metadata->set_public_key(kPublicKeyPrefix + suffix);
if (has_bluetooth_address) {
beto_metadata->set_bluetooth_public_address(
kBluetoothPublicAddressPrefix + suffix);
}
} }
return CryptAuthDevice(kInstanceIdPrefix + suffix, kDeviceNamePrefix + suffix, return CryptAuthDevice(kInstanceIdPrefix + suffix, kDeviceNamePrefix + suffix,
...@@ -85,12 +92,16 @@ CryptAuthDevice CreateCryptAuthDevice(const std::string& suffix, ...@@ -85,12 +92,16 @@ CryptAuthDevice CreateCryptAuthDevice(const std::string& suffix,
multidevice::RemoteDevice CreateRemoteDevice(const std::string& suffix, multidevice::RemoteDevice CreateRemoteDevice(const std::string& suffix,
bool has_pii_free_name, bool has_pii_free_name,
bool has_public_key, bool has_public_key,
bool has_beacon_seeds) { bool has_beacon_seeds,
bool has_bluetooth_address) {
std::string pii_free_name = std::string pii_free_name =
has_pii_free_name ? kNoPiiDeviceNamePrefix + suffix : std::string(); has_pii_free_name ? kNoPiiDeviceNamePrefix + suffix : std::string();
std::string public_key = std::string public_key =
has_public_key ? kPublicKeyPrefix + suffix : std::string(); has_public_key ? kPublicKeyPrefix + suffix : std::string();
std::string psk = has_public_key ? kPskPlaceholder : std::string(); std::string psk = has_public_key ? kPskPlaceholder : std::string();
std::string bluetooth_address = has_bluetooth_address
? kBluetoothPublicAddressPrefix + suffix
: std::string();
std::vector<multidevice::BeaconSeed> beacon_seeds; std::vector<multidevice::BeaconSeed> beacon_seeds;
if (has_beacon_seeds) { if (has_beacon_seeds) {
...@@ -104,7 +115,7 @@ multidevice::RemoteDevice CreateRemoteDevice(const std::string& suffix, ...@@ -104,7 +115,7 @@ multidevice::RemoteDevice CreateRemoteDevice(const std::string& suffix,
pii_free_name, public_key, psk, kLastUpdateTimeMs, pii_free_name, public_key, psk, kLastUpdateTimeMs,
{{multidevice::SoftwareFeature::kBetterTogetherHost, {{multidevice::SoftwareFeature::kBetterTogetherHost,
multidevice::SoftwareFeatureState::kSupported}}, multidevice::SoftwareFeatureState::kSupported}},
beacon_seeds); beacon_seeds, bluetooth_address);
} }
} // namespace } // namespace
...@@ -195,21 +206,25 @@ TEST_F(DeviceSyncRemoteDeviceV2LoaderImplTest, NoDevices) { ...@@ -195,21 +206,25 @@ TEST_F(DeviceSyncRemoteDeviceV2LoaderImplTest, NoDevices) {
TEST_F(DeviceSyncRemoteDeviceV2LoaderImplTest, Success) { TEST_F(DeviceSyncRemoteDeviceV2LoaderImplTest, Success) {
CallLoad({CreateCryptAuthDevice("device1", true /* has_beto_metadata */, CallLoad({CreateCryptAuthDevice("device1", true /* has_beto_metadata */,
true /* has_public_key */), true /* has_public_key */,
true /* has_bluetooth_address */),
CreateCryptAuthDevice("device2", true /* has_beto_metadata */, CreateCryptAuthDevice("device2", true /* has_beto_metadata */,
false /* has_public_key */), false /* has_public_key */,
false /* has_bluetooth_address */),
CreateCryptAuthDevice("device3", false /* has_beto_metadata */, CreateCryptAuthDevice("device3", false /* has_beto_metadata */,
false /* has_public_key */)}); false /* has_public_key */,
false /* has_bluetooth_address */)});
VerifyLoad({CreateRemoteDevice("device1", true /* has_pii_free_name */,
true /* has_public_key */, VerifyLoad(
true /* has_beacon_seeds */), {CreateRemoteDevice(
CreateRemoteDevice("device2", true /* has_pii_free_name */, "device1", true /* has_pii_free_name */, true /* has_public_key */,
false /* has_public_key */, true /* has_beacon_seeds */, true /* has_bluetooth_address */),
true /* has_beacon_seeds */), CreateRemoteDevice(
CreateRemoteDevice("device3", false /* has_pii_free_name */, "device2", true /* has_pii_free_name */, false /* has_public_key */,
false /* has_public_key */, true /* has_beacon_seeds */, false /* has_bluetooth_address */),
false /* has_beacon_seeds */)}); CreateRemoteDevice(
"device3", false /* has_pii_free_name */, false /* has_public_key */,
false /* has_beacon_seeds */, false /* has_bluetooth_address */)});
} }
} // namespace device_sync } // namespace device_sync
......
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