Commit 7044601b authored by Jimmy Gong's avatar Jimmy Gong Committed by Commit Bot

Phonehub: Conditionally check eligibility of host phone

Fixes an edge case where there are multiple phones associated to one
GAIA account. If there is at least one device that is eligible but the
others are not, the non-eligible phones will be marked as eligible
incorrectly. This CL fixes that bug by verifying that the current
host phone device is eligible for the feature.

Bug: 1106937
Fixed: 1146619
Test: chrome_components_unittest, local

Change-Id: I88686e2b1f819ea1e3d3a903fa8124778c4c2632
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2530897
Commit-Queue: Jimmy Gong <jimmyxgong@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827083}
parent 3bd1fc34
...@@ -29,11 +29,16 @@ using multidevice_setup::mojom::Feature; ...@@ -29,11 +29,16 @@ using multidevice_setup::mojom::Feature;
using multidevice_setup::mojom::FeatureState; using multidevice_setup::mojom::FeatureState;
using multidevice_setup::mojom::HostStatus; using multidevice_setup::mojom::HostStatus;
bool DoesDeviceSupportPhoneHubHost(const RemoteDeviceRef& device) {
return device.GetSoftwareFeatureState(SoftwareFeature::kPhoneHubHost) !=
SoftwareFeatureState::kNotSupported;
}
bool IsEligibleForFeature( bool IsEligibleForFeature(
const base::Optional<multidevice::RemoteDeviceRef>& local_device, const base::Optional<multidevice::RemoteDeviceRef>& local_device,
multidevice_setup::MultiDeviceSetupClient::HostStatusWithDevice host_status,
const RemoteDeviceRefList& remote_devices, const RemoteDeviceRefList& remote_devices,
FeatureState feature_state, FeatureState feature_state) {
HostStatus host_status) {
// If the feature is prohibited by policy, we don't initialize Phone Hub // If the feature is prohibited by policy, we don't initialize Phone Hub
// classes at all. But, there is an edge case where a user session starts up // classes at all. But, there is an edge case where a user session starts up
// normally, then an administrator prohibits the policy during the user // normally, then an administrator prohibits the policy during the user
...@@ -60,9 +65,16 @@ bool IsEligibleForFeature( ...@@ -60,9 +65,16 @@ bool IsEligibleForFeature(
return false; return false;
// If the host device is not an eligible host, do not initialize Phone Hub. // If the host device is not an eligible host, do not initialize Phone Hub.
if (host_status == HostStatus::kNoEligibleHosts) if (host_status.first == HostStatus::kNoEligibleHosts)
return false; return false;
// If there is a host device available, check if the device is eligible for
// Phonehub.
if (host_status.second.has_value())
return DoesDeviceSupportPhoneHubHost(*(host_status.second));
// Otherwise, check if there is any available remote device that is
// eligible for Phonehub.
for (const RemoteDeviceRef& device : remote_devices) { for (const RemoteDeviceRef& device : remote_devices) {
// Device must be capable of being a multi-device host. // Device must be capable of being a multi-device host.
if (device.GetSoftwareFeatureState(SoftwareFeature::kBetterTogetherHost) == if (device.GetSoftwareFeatureState(SoftwareFeature::kBetterTogetherHost) ==
...@@ -71,8 +83,7 @@ bool IsEligibleForFeature( ...@@ -71,8 +83,7 @@ bool IsEligibleForFeature(
} }
// Device must be capable of being a Phone Hub host. // Device must be capable of being a Phone Hub host.
if (device.GetSoftwareFeatureState(SoftwareFeature::kPhoneHubHost) == if (!DoesDeviceSupportPhoneHubHost(device)) {
SoftwareFeatureState::kNotSupported) {
continue; continue;
} }
...@@ -253,8 +264,9 @@ FeatureStatus FeatureStatusProviderImpl::ComputeStatus() { ...@@ -253,8 +264,9 @@ FeatureStatus FeatureStatusProviderImpl::ComputeStatus() {
// feature until proven otherwise. // feature until proven otherwise.
if (!device_sync_client_->is_ready() || if (!device_sync_client_->is_ready() ||
!IsEligibleForFeature(device_sync_client_->GetLocalDeviceMetadata(), !IsEligibleForFeature(device_sync_client_->GetLocalDeviceMetadata(),
multidevice_setup_client_->GetHostStatus(),
device_sync_client_->GetSyncedDevices(), device_sync_client_->GetSyncedDevices(),
feature_state, host_status)) { feature_state)) {
return FeatureStatus::kNotEligibleForFeature; return FeatureStatus::kNotEligibleForFeature;
} }
......
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