Commit 8fb52d77 authored by Jordy Greenblatt's avatar Jordy Greenblatt Committed by Commit Bot

[CrOS MultiDevice] Reserve 'existing user' notifications for verified hosts

This CL adapts the MultiDevice notification functionality to the new
spec that only considers a new phone added or switched to once it is
verified rather than just set.

I added tests for this behavior for both of the 'existing host' events
and an extra test for the edge case of a set (but unverified) host
Phone A is replace by a different host Phone B that is verified.

Bug: 891822
Change-Id: Iebd9d0d209b020602a284de200fae168f34759c2
Reviewed-on: https://chromium-review.googlesource.com/c/1263425
Commit-Queue: Jordy Greenblatt <jordynass@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597628}
parent 2387ead4
...@@ -13,9 +13,6 @@ ...@@ -13,9 +13,6 @@
#include "chromeos/components/proximity_auth/logging/logging.h" #include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/services/multidevice_setup/host_status_provider_impl.h" #include "chromeos/services/multidevice_setup/host_status_provider_impl.h"
#include "chromeos/services/multidevice_setup/setup_flow_completion_recorder.h" #include "chromeos/services/multidevice_setup/setup_flow_completion_recorder.h"
#include "components/cryptauth/proto/cryptauth_api.pb.h"
#include "components/cryptauth/remote_device_ref.h"
#include "components/cryptauth/software_feature_state.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
...@@ -76,7 +73,7 @@ void AccountStatusChangeDelegateNotifierImpl::RegisterPrefs( ...@@ -76,7 +73,7 @@ void AccountStatusChangeDelegateNotifierImpl::RegisterPrefs(
registry->RegisterInt64Pref(kExistingUserChromebookAddedPrefName, registry->RegisterInt64Pref(kExistingUserChromebookAddedPrefName,
kTimestampNotSet); kTimestampNotSet);
registry->RegisterStringPref( registry->RegisterStringPref(
kHostDeviceIdFromMostRecentHostStatusUpdatePrefName, kNoHost); kVerifiedHostDeviceIdFromMostRecentHostStatusUpdatePrefName, kNoHost);
} }
AccountStatusChangeDelegateNotifierImpl:: AccountStatusChangeDelegateNotifierImpl::
...@@ -103,9 +100,12 @@ const char AccountStatusChangeDelegateNotifierImpl:: ...@@ -103,9 +100,12 @@ const char AccountStatusChangeDelegateNotifierImpl::
kExistingUserChromebookAddedPrefName[] = kExistingUserChromebookAddedPrefName[] =
"multidevice_setup.existing_user_chromebook_added"; "multidevice_setup.existing_user_chromebook_added";
// Note that, despite the pref string name, this pref only records the IDs of
// verified hosts. In particular, if a host has been set but is waiting for
// verification, it will not recorded.
// static // static
const char AccountStatusChangeDelegateNotifierImpl:: const char AccountStatusChangeDelegateNotifierImpl::
kHostDeviceIdFromMostRecentHostStatusUpdatePrefName[] = kVerifiedHostDeviceIdFromMostRecentHostStatusUpdatePrefName[] =
"multidevice_setup.host_device_id_from_most_recent_sync"; "multidevice_setup.host_device_id_from_most_recent_sync";
AccountStatusChangeDelegateNotifierImpl:: AccountStatusChangeDelegateNotifierImpl::
...@@ -118,7 +118,7 @@ AccountStatusChangeDelegateNotifierImpl:: ...@@ -118,7 +118,7 @@ AccountStatusChangeDelegateNotifierImpl::
pref_service_(pref_service), pref_service_(pref_service),
setup_flow_completion_recorder_(setup_flow_completion_recorder), setup_flow_completion_recorder_(setup_flow_completion_recorder),
clock_(clock) { clock_(clock) {
host_device_id_from_most_recent_update_ = verified_host_device_id_from_most_recent_update_ =
LoadHostDeviceIdFromEndOfPreviousSession(); LoadHostDeviceIdFromEndOfPreviousSession();
host_status_provider_->AddObserver(this); host_status_provider_->AddObserver(this);
} }
...@@ -137,27 +137,30 @@ void AccountStatusChangeDelegateNotifierImpl::CheckForMultiDeviceEvents( ...@@ -137,27 +137,30 @@ void AccountStatusChangeDelegateNotifierImpl::CheckForMultiDeviceEvents(
return; return;
} }
// Track and update host info. // Track and update verified host info.
base::Optional<std::string> host_device_id_before_update = base::Optional<std::string> verified_host_device_id_before_update =
host_device_id_from_most_recent_update_; verified_host_device_id_from_most_recent_update_;
// Check if a host has been set. // Check if a host has been verified.
if (host_status_with_device.host_device()) { if (host_status_with_device.host_status() ==
host_device_id_from_most_recent_update_ = mojom::HostStatus::kHostVerified) {
verified_host_device_id_from_most_recent_update_ =
host_status_with_device.host_device()->GetDeviceId(); host_status_with_device.host_device()->GetDeviceId();
pref_service_->SetString( pref_service_->SetString(
kHostDeviceIdFromMostRecentHostStatusUpdatePrefName, kVerifiedHostDeviceIdFromMostRecentHostStatusUpdatePrefName,
*host_device_id_from_most_recent_update_); *verified_host_device_id_from_most_recent_update_);
} else { } else {
// No host set. // No host set.
host_device_id_from_most_recent_update_.reset(); verified_host_device_id_from_most_recent_update_.reset();
pref_service_->SetString(
kVerifiedHostDeviceIdFromMostRecentHostStatusUpdatePrefName, kNoHost);
} }
CheckForNewUserPotentialHostExistsEvent(host_status_with_device); CheckForNewUserPotentialHostExistsEvent(host_status_with_device);
CheckForExistingUserHostSwitchedEvent(host_status_with_device, CheckForExistingUserHostSwitchedEvent(host_status_with_device,
host_device_id_before_update); verified_host_device_id_before_update);
CheckForExistingUserChromebookAddedEvent(host_status_with_device, CheckForExistingUserChromebookAddedEvent(
host_device_id_before_update); host_status_with_device, verified_host_device_id_before_update);
} }
void AccountStatusChangeDelegateNotifierImpl:: void AccountStatusChangeDelegateNotifierImpl::
...@@ -165,7 +168,7 @@ void AccountStatusChangeDelegateNotifierImpl:: ...@@ -165,7 +168,7 @@ void AccountStatusChangeDelegateNotifierImpl::
const HostStatusProvider::HostStatusWithDevice& const HostStatusProvider::HostStatusWithDevice&
host_status_with_device) { host_status_with_device) {
// We only check for new user events if there is no enabled host. // We only check for new user events if there is no enabled host.
if (host_device_id_from_most_recent_update_) if (verified_host_device_id_from_most_recent_update_)
return; return;
// If the observer has been notified of this event before, the user is not // If the observer has been notified of this event before, the user is not
...@@ -190,14 +193,17 @@ void AccountStatusChangeDelegateNotifierImpl:: ...@@ -190,14 +193,17 @@ void AccountStatusChangeDelegateNotifierImpl::
void AccountStatusChangeDelegateNotifierImpl:: void AccountStatusChangeDelegateNotifierImpl::
CheckForExistingUserHostSwitchedEvent( CheckForExistingUserHostSwitchedEvent(
const HostStatusProvider::HostStatusWithDevice& host_status_with_device, const HostStatusProvider::HostStatusWithDevice& host_status_with_device,
const base::Optional<std::string>& host_device_id_before_update) { const base::Optional<std::string>&
// The host switched event requires both a pre-update and a post-update host. verified_host_device_id_before_update) {
if (!host_device_id_from_most_recent_update_ || // The host switched event requires both a pre-update and a post-update
!host_device_id_before_update) { // verified host.
if (!verified_host_device_id_from_most_recent_update_ ||
!verified_host_device_id_before_update) {
return; return;
} }
// If the host stayed the same, there was no switch. // If the host stayed the same, there was no switch.
if (*host_device_id_from_most_recent_update_ == *host_device_id_before_update) if (*verified_host_device_id_from_most_recent_update_ ==
*verified_host_device_id_before_update)
return; return;
delegate()->OnConnectedHostSwitchedForExistingUser( delegate()->OnConnectedHostSwitchedForExistingUser(
...@@ -209,11 +215,13 @@ void AccountStatusChangeDelegateNotifierImpl:: ...@@ -209,11 +215,13 @@ void AccountStatusChangeDelegateNotifierImpl::
void AccountStatusChangeDelegateNotifierImpl:: void AccountStatusChangeDelegateNotifierImpl::
CheckForExistingUserChromebookAddedEvent( CheckForExistingUserChromebookAddedEvent(
const HostStatusProvider::HostStatusWithDevice& host_status_with_device, const HostStatusProvider::HostStatusWithDevice& host_status_with_device,
const base::Optional<std::string>& host_device_id_before_update) { const base::Optional<std::string>&
// The Chromebook added event requires that a set host was found by the verified_host_device_id_before_update) {
// update, i.e. there was no host before the host status update but afterward // The Chromebook added event requires that a verified host was found by the
// there is a set host. // update, i.e. there was no verified host before the host status update but
if (!host_device_id_from_most_recent_update_ || host_device_id_before_update) // afterward there was a verified host.
if (!verified_host_device_id_from_most_recent_update_ ||
verified_host_device_id_before_update)
return; return;
delegate()->OnNewChromebookAddedForExistingUser( delegate()->OnNewChromebookAddedForExistingUser(
...@@ -224,11 +232,12 @@ void AccountStatusChangeDelegateNotifierImpl:: ...@@ -224,11 +232,12 @@ void AccountStatusChangeDelegateNotifierImpl::
base::Optional<std::string> AccountStatusChangeDelegateNotifierImpl:: base::Optional<std::string> AccountStatusChangeDelegateNotifierImpl::
LoadHostDeviceIdFromEndOfPreviousSession() { LoadHostDeviceIdFromEndOfPreviousSession() {
std::string host_device_id_from_most_recent_update = pref_service_->GetString( std::string verified_host_device_id_from_most_recent_update =
kHostDeviceIdFromMostRecentHostStatusUpdatePrefName); pref_service_->GetString(
if (host_device_id_from_most_recent_update.empty()) kVerifiedHostDeviceIdFromMostRecentHostStatusUpdatePrefName);
if (verified_host_device_id_from_most_recent_update.empty())
return base::nullopt; return base::nullopt;
return host_device_id_from_most_recent_update; return verified_host_device_id_from_most_recent_update;
} }
} // namespace multidevice_setup } // namespace multidevice_setup
......
...@@ -62,7 +62,8 @@ class AccountStatusChangeDelegateNotifierImpl ...@@ -62,7 +62,8 @@ class AccountStatusChangeDelegateNotifierImpl
static const char kExistingUserHostSwitchedPrefName[]; static const char kExistingUserHostSwitchedPrefName[];
static const char kExistingUserChromebookAddedPrefName[]; static const char kExistingUserChromebookAddedPrefName[];
static const char kHostDeviceIdFromMostRecentHostStatusUpdatePrefName[]; static const char
kVerifiedHostDeviceIdFromMostRecentHostStatusUpdatePrefName[];
AccountStatusChangeDelegateNotifierImpl( AccountStatusChangeDelegateNotifierImpl(
HostStatusProvider* host_status_provider, HostStatusProvider* host_status_provider,
...@@ -84,17 +85,17 @@ class AccountStatusChangeDelegateNotifierImpl ...@@ -84,17 +85,17 @@ class AccountStatusChangeDelegateNotifierImpl
const HostStatusProvider::HostStatusWithDevice& host_status_with_device); const HostStatusProvider::HostStatusWithDevice& host_status_with_device);
void CheckForExistingUserHostSwitchedEvent( void CheckForExistingUserHostSwitchedEvent(
const HostStatusProvider::HostStatusWithDevice& host_status_with_device, const HostStatusProvider::HostStatusWithDevice& host_status_with_device,
const base::Optional<std::string>& host_device_id_before_update); const base::Optional<std::string>& verified_host_device_id_before_update);
void CheckForExistingUserChromebookAddedEvent( void CheckForExistingUserChromebookAddedEvent(
const HostStatusProvider::HostStatusWithDevice& host_status_with_device, const HostStatusProvider::HostStatusWithDevice& host_status_with_device,
const base::Optional<std::string>& host_device_id_before_update); const base::Optional<std::string>& verified_host_device_id_before_update);
// Loads data from previous session using PrefService. // Loads data from previous session using PrefService.
base::Optional<std::string> LoadHostDeviceIdFromEndOfPreviousSession(); base::Optional<std::string> LoadHostDeviceIdFromEndOfPreviousSession();
// Set to base::nullopt if there was no enabled host in the most recent // Set to base::nullopt if there was no enabled host in the most recent
// host status update. // host status update.
base::Optional<std::string> host_device_id_from_most_recent_update_; base::Optional<std::string> verified_host_device_id_from_most_recent_update_;
mojom::AccountStatusChangeDelegatePtr delegate_ptr_; mojom::AccountStatusChangeDelegatePtr delegate_ptr_;
HostStatusProvider* host_status_provider_; HostStatusProvider* host_status_provider_;
......
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