Commit 026a3d21 authored by Regan Hsu's avatar Regan Hsu Committed by Chromium LUCI CQ

[CrOS PhoneHub] Mark PhoneHub not supported by phone if empty BT address

If the device has no bluetooth_public_address(), phonehub becomes
kNotSupportedByPhone.

Fixed: 1158592
Bug: 1106937
Change-Id: Ifaf86e3272a6bcbe2b5304cc71759afb1b2c6740
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2598472Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838939}
parent 14428996
...@@ -164,6 +164,16 @@ void ProcessSuiteEdgeCases( ...@@ -164,6 +164,16 @@ void ProcessSuiteEdgeCases(
} }
} }
} }
// If the top level Phone Hub feature is not supported by the phone, the
// sub-features should also be not supported by the phone.
if (feature_states_map[mojom::Feature::kPhoneHub] ==
mojom::FeatureState::kNotSupportedByPhone) {
for (const auto& phone_hub_sub_feature : kPhoneHubSubFeatures) {
feature_states_map[phone_hub_sub_feature] =
mojom::FeatureState::kNotSupportedByPhone;
}
}
} }
bool HasFeatureStateChanged( bool HasFeatureStateChanged(
...@@ -512,6 +522,13 @@ bool FeatureStateManagerImpl::HasBeenActivatedByPhone( ...@@ -512,6 +522,13 @@ bool FeatureStateManagerImpl::HasBeenActivatedByPhone(
if (pair.first != feature) if (pair.first != feature)
continue; continue;
// The bluetooth public address is required in order to use PhoneHub and its
// sub-features.
if (pair.second == multidevice::SoftwareFeature::kPhoneHubHost &&
host_device.bluetooth_public_address().empty()) {
return false;
}
multidevice::SoftwareFeatureState feature_state = multidevice::SoftwareFeatureState feature_state =
host_device.GetSoftwareFeatureState(pair.second); host_device.GetSoftwareFeatureState(pair.second);
......
...@@ -53,7 +53,8 @@ multidevice::RemoteDeviceRef CreateTestLocalDevice() { ...@@ -53,7 +53,8 @@ multidevice::RemoteDeviceRef CreateTestLocalDevice() {
return local_device; return local_device;
} }
multidevice::RemoteDeviceRef CreateTestHostDevice() { multidevice::RemoteDeviceRef CreateTestHostDevice(
bool empty_mac_address = false) {
multidevice::RemoteDeviceRef host_device = multidevice::RemoteDeviceRef host_device =
multidevice::CreateRemoteDeviceRefForTest(); multidevice::CreateRemoteDeviceRefForTest();
...@@ -76,6 +77,9 @@ multidevice::RemoteDeviceRef CreateTestHostDevice() { ...@@ -76,6 +77,9 @@ multidevice::RemoteDeviceRef CreateTestHostDevice() {
raw_device->software_features[multidevice::SoftwareFeature::kWifiSyncHost] = raw_device->software_features[multidevice::SoftwareFeature::kWifiSyncHost] =
multidevice::SoftwareFeatureState::kSupported; multidevice::SoftwareFeatureState::kSupported;
if (empty_mac_address)
raw_device->bluetooth_public_address.clear();
return host_device; return host_device;
} }
...@@ -88,7 +92,9 @@ class MultiDeviceSetupFeatureStateManagerImplTest : public testing::Test { ...@@ -88,7 +92,9 @@ class MultiDeviceSetupFeatureStateManagerImplTest : public testing::Test {
test_host_device_(CreateTestHostDevice()) {} test_host_device_(CreateTestHostDevice()) {}
~MultiDeviceSetupFeatureStateManagerImplTest() override = default; ~MultiDeviceSetupFeatureStateManagerImplTest() override = default;
void SetupFeatureStateManager(bool is_secondary_user = false) { void SetupFeatureStateManager(bool is_secondary_user = false,
bool empty_mac_address = false) {
test_host_device_ = CreateTestHostDevice(empty_mac_address);
test_pref_service_ = test_pref_service_ =
std::make_unique<sync_preferences::TestingPrefServiceSyncable>(); std::make_unique<sync_preferences::TestingPrefServiceSyncable>();
user_prefs::PrefRegistrySyncable* registry = test_pref_service_->registry(); user_prefs::PrefRegistrySyncable* registry = test_pref_service_->registry();
...@@ -538,6 +544,82 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, SmartLock) { ...@@ -538,6 +544,82 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, SmartLock) {
mojom::FeatureState::kProhibitedByPolicy); mojom::FeatureState::kProhibitedByPolicy);
} }
TEST_F(MultiDeviceSetupFeatureStateManagerImplTest,
PhoneHubBluetoothAddressNotSynced) {
SetupFeatureStateManager(/*is_secondary_user=*/false,
/*empty_bluetooth_address=*/true);
const std::vector<mojom::Feature> kAllPhoneHubFeatures{
mojom::Feature::kPhoneHub, mojom::Feature::kPhoneHubNotifications,
mojom::Feature::kPhoneHubTaskContinuation};
for (const auto& phone_hub_feature : kAllPhoneHubFeatures)
TryAllUnverifiedHostStatesAndVerifyFeatureState(phone_hub_feature);
SetVerifiedHost();
for (const auto& phone_hub_feature : kAllPhoneHubFeatures) {
VerifyFeatureState(mojom::FeatureState::kNotSupportedByChromebook,
phone_hub_feature);
}
SetSoftwareFeatureState(true /* use_local_device */,
multidevice::SoftwareFeature::kPhoneHubClient,
multidevice::SoftwareFeatureState::kSupported);
for (const auto& phone_hub_feature : kAllPhoneHubFeatures) {
VerifyFeatureState(mojom::FeatureState::kNotSupportedByPhone,
phone_hub_feature);
}
// This pref should is disabled for existing Better Together users;
// they must go to settings to explicitly enable PhoneHub.
test_pref_service()->SetBoolean(kPhoneHubEnabledPrefName, true);
SetSoftwareFeatureState(false /* use_local_device */,
multidevice::SoftwareFeature::kPhoneHubHost,
multidevice::SoftwareFeatureState::kEnabled);
for (const auto& phone_hub_feature : kAllPhoneHubFeatures) {
VerifyFeatureState(mojom::FeatureState::kNotSupportedByPhone,
phone_hub_feature);
}
VerifyFeatureStateChange(1u /* expected_index */, mojom::Feature::kPhoneHub,
mojom::FeatureState::kNotSupportedByPhone);
MakeBetterTogetherSuiteDisabledByUser(
/*expected_state_upon_disabling=*/mojom::FeatureState::kDisabledByUser);
for (const auto& phone_hub_feature : kAllPhoneHubFeatures) {
VerifyFeatureState(mojom::FeatureState::kNotSupportedByPhone,
phone_hub_feature);
}
VerifyFeatureStateChange(2u /* expected_index */, mojom::Feature::kPhoneHub,
mojom::FeatureState::kNotSupportedByPhone);
test_pref_service()->SetBoolean(kPhoneHubNotificationsEnabledPrefName, false);
VerifyFeatureState(mojom::FeatureState::kNotSupportedByPhone,
mojom::Feature::kPhoneHubNotifications);
test_pref_service()->SetBoolean(kPhoneHubNotificationsEnabledPrefName, true);
test_pref_service()->SetBoolean(kPhoneHubEnabledPrefName, false);
for (const auto& phone_hub_feature : kAllPhoneHubFeatures) {
VerifyFeatureState(mojom::FeatureState::kNotSupportedByPhone,
phone_hub_feature);
}
test_pref_service()->SetBoolean(kPhoneHubNotificationsAllowedPrefName, false);
VerifyFeatureState(mojom::FeatureState::kNotSupportedByPhone,
mojom::Feature::kPhoneHubNotifications);
VerifyFeatureStateChange(3u /* expected_index */,
mojom::Feature::kPhoneHubNotifications,
mojom::FeatureState::kNotSupportedByPhone);
// Prohibiting Phone Hub implicitly prohibits all of its sub-features.
test_pref_service()->SetBoolean(kPhoneHubAllowedPrefName, false);
for (const auto& phone_hub_feature : kAllPhoneHubFeatures) {
VerifyFeatureState(mojom::FeatureState::kProhibitedByPolicy,
phone_hub_feature);
}
VerifyFeatureStateChange(4u /* expected_index */, mojom::Feature::kPhoneHub,
mojom::FeatureState::kProhibitedByPolicy);
}
TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, PhoneHubForSecondaryUsers) { TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, PhoneHubForSecondaryUsers) {
SetupFeatureStateManager(/*is_secondary_user=*/true); SetupFeatureStateManager(/*is_secondary_user=*/true);
......
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