Skip to content

Commit

Permalink
[CrOS Tether] Add support for filtering by Pixel-only phones.
Browse files Browse the repository at this point in the history
This will be used to work around Android Bluetooth bugs.

Bug: 764386, 672263
Change-Id: I0e13a94c50c9c91e9f6957917f595ed30a76b7d1
Reviewed-on: https://chromium-review.googlesource.com/663206
Reviewed-by: Tim Song <[email protected]>
Commit-Queue: Kyle Horimoto <[email protected]>
Cr-Commit-Position: refs/heads/master@{#501421}
  • Loading branch information
Kyle Horimoto authored and Commit Bot committed Sep 12, 2017
1 parent 4c7bfdc commit 70e761d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
50 changes: 44 additions & 6 deletions components/cryptauth/cryptauth_device_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const char kExternalDeviceKeyMobileHotspotSupported[] =
"mobile_hotspot_supported";
const char kExternalDeviceKeyDeviceType[] = "device_type";
const char kExternalDeviceKeyBeaconSeeds[] = "beacon_seeds";
const char kExternalDeviceKeyArcPlusPlus[] = "arc_plus_plus";
const char kExternalDeviceKeyPixelPhone[] = "pixel_phone";
const char kExternalDeviceKeyBeaconSeedData[] = "beacon_seed_data";
const char kExternalDeviceKeyBeaconSeedStartMs[] = "beacon_seed_start_ms";
const char kExternalDeviceKeyBeaconSeedEndMs[] = "beacon_seed_end_ms";
Expand Down Expand Up @@ -156,6 +158,15 @@ std::unique_ptr<base::DictionaryValue> UnlockKeyToDictionary(
device.device_type());
}

if (device.has_arc_plus_plus()) {
dictionary->SetInteger(kExternalDeviceKeyArcPlusPlus,
device.arc_plus_plus());
}

if (device.has_pixel_phone()) {
dictionary->SetInteger(kExternalDeviceKeyPixelPhone, device.pixel_phone());
}

std::unique_ptr<base::ListValue> beacon_seed_list =
BeaconSeedsToListValue(device.beacon_seeds());
dictionary->Set(kExternalDeviceKeyBeaconSeeds, std::move(beacon_seed_list));
Expand Down Expand Up @@ -254,14 +265,12 @@ bool DictionaryToUnlockKey(const base::DictionaryValue& dictionary,
}

bool unlock_key;
if (dictionary.GetBoolean(kExternalDeviceKeyUnlockKey, &unlock_key)) {
if (dictionary.GetBoolean(kExternalDeviceKeyUnlockKey, &unlock_key))
external_device->set_unlock_key(unlock_key);
}

bool unlockable;
if (dictionary.GetBoolean(kExternalDeviceKeyUnlockable, &unlockable)) {
if (dictionary.GetBoolean(kExternalDeviceKeyUnlockable, &unlockable))
external_device->set_unlockable(unlockable);
}

std::string last_update_time_millis_str;
if (dictionary.GetString(
Expand Down Expand Up @@ -291,9 +300,16 @@ bool DictionaryToUnlockKey(const base::DictionaryValue& dictionary,

const base::ListValue* beacon_seeds = nullptr;
dictionary.GetList(kExternalDeviceKeyBeaconSeeds, &beacon_seeds);
if (beacon_seeds) {
if (beacon_seeds)
AddBeaconSeedsToExternalDevice(*beacon_seeds, *external_device);
}

bool arc_plus_plus;
if (dictionary.GetBoolean(kExternalDeviceKeyArcPlusPlus, &arc_plus_plus))
external_device->set_arc_plus_plus(arc_plus_plus);

bool pixel_phone;
if (dictionary.GetBoolean(kExternalDeviceKeyPixelPhone, &pixel_phone))
external_device->set_pixel_phone(pixel_phone);

return true;
}
Expand Down Expand Up @@ -433,6 +449,17 @@ std::vector<ExternalDeviceInfo> CryptAuthDeviceManager::GetUnlockKeys() const {
return unlock_keys;
}

std::vector<ExternalDeviceInfo> CryptAuthDeviceManager::GetPixelUnlockKeys()
const {
std::vector<ExternalDeviceInfo> unlock_keys;
for (const auto& device : synced_devices_) {
if (device.unlock_key() && device.pixel_phone()) {
unlock_keys.push_back(device);
}
}
return unlock_keys;
}

std::vector<ExternalDeviceInfo> CryptAuthDeviceManager::GetTetherHosts() const {
std::vector<ExternalDeviceInfo> tether_hosts;
for (const auto& device : synced_devices_) {
Expand All @@ -443,6 +470,17 @@ std::vector<ExternalDeviceInfo> CryptAuthDeviceManager::GetTetherHosts() const {
return tether_hosts;
}

std::vector<ExternalDeviceInfo> CryptAuthDeviceManager::GetPixelTetherHosts()
const {
std::vector<ExternalDeviceInfo> tether_hosts;
for (const auto& device : synced_devices_) {
if (device.mobile_hotspot_supported() && device.pixel_phone()) {
tether_hosts.push_back(device);
}
}
return tether_hosts;
}

void CryptAuthDeviceManager::OnGetMyDevicesSuccess(
const GetMyDevicesResponse& response) {
// Update the synced devices stored in the user's prefs.
Expand Down
4 changes: 4 additions & 0 deletions components/cryptauth/cryptauth_device_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ class CryptAuthDeviceManager : public SyncScheduler::Delegate,

// Returns a list of remote devices that can unlock the user's other devices.
virtual std::vector<ExternalDeviceInfo> GetUnlockKeys() const;
// Like GetUnlockKeys(), but only returns Pixel devices.
virtual std::vector<ExternalDeviceInfo> GetPixelUnlockKeys() const;

// Returns a list of remote devices that can host tether hotspots.
virtual std::vector<ExternalDeviceInfo> GetTetherHosts() const;
// Like GetTetherHosts(), but only returns Pixel devices.
virtual std::vector<ExternalDeviceInfo> GetPixelTetherHosts() const;

protected:
// Empty constructor, to be used by tests to mock the device manager. Do not
Expand Down
10 changes: 9 additions & 1 deletion components/cryptauth/cryptauth_device_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const bool kStoredMobileHotspotSupported = true;

// ExternalDeviceInfo fields for the synced unlock key.
const char kPublicKey1[] = "GOOG";
const char kDeviceName1[] = "Nexus 5";
const char kDeviceName1[] = "Pixel XL";
const char kBluetoothAddress1[] = "aa:bb:cc:ee:dd:ff";
const bool kUnlockKey1 = true;
const bool kUnlockable1 = false;
Expand All @@ -64,6 +64,8 @@ const int64_t kBeaconSeed1EndTime = 123457;
const char kBeaconSeed2Data[] = "beaconSeed2Data";
const int64_t kBeaconSeed2StartTime = 234567;
const int64_t kBeaconSeed2EndTime = 234568;
const bool kArcPlusPlus1 = true;
const bool kPixelPhone1 = true;

// ExternalDeviceInfo fields for a non-synced unlockable device.
const char kPublicKey2[] = "MSFT";
Expand All @@ -77,6 +79,8 @@ const int64_t kBeaconSeed3EndTime = 123457;
const char kBeaconSeed4Data[] = "beaconSeed4Data";
const int64_t kBeaconSeed4StartTime = 234567;
const int64_t kBeaconSeed4EndTime = 234568;
const bool kArcPlusPlus2 = false;
const bool kPixelPhone2 = false;

// Validates that |devices| is equal to |expected_devices|.
void ExpectSyncedDevicesAreEqual(
Expand Down Expand Up @@ -351,6 +355,8 @@ class CryptAuthDeviceManagerTest
seed2->set_data(kBeaconSeed2Data);
seed2->set_start_time_millis(kBeaconSeed2StartTime);
seed2->set_end_time_millis(kBeaconSeed2EndTime);
unlock_key.set_arc_plus_plus(kArcPlusPlus1);
unlock_key.set_pixel_phone(kPixelPhone1);
devices_in_response_.push_back(unlock_key);

ExternalDeviceInfo unlockable_device;
Expand All @@ -367,6 +373,8 @@ class CryptAuthDeviceManagerTest
seed4->set_data(kBeaconSeed4Data);
seed4->set_start_time_millis(kBeaconSeed4StartTime);
seed4->set_end_time_millis(kBeaconSeed4EndTime);
unlockable_device.set_arc_plus_plus(kArcPlusPlus2);
unlockable_device.set_pixel_phone(kPixelPhone2);
devices_in_response_.push_back(unlockable_device);
}

Expand Down
6 changes: 6 additions & 0 deletions components/cryptauth/proto/cryptauth_api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ message ExternalDeviceInfo {

// A list of seeds for EID BLE advertisements targeting this device.
repeated BeaconSeed beacon_seeds = 9;

// Whether this device is an ARC++ device enrolled via gmscore.
optional bool arc_plus_plus = 10 [default = false];

// Whether this is a "Pixel Experience" phone.
optional bool pixel_phone = 11 [default = false];
}

// Determine if the calling device is allowed to promote the SmartLock
Expand Down

0 comments on commit 70e761d

Please sign in to comment.