From 040ed31341f03ded50fa97ef3b075d645f07ecf7 Mon Sep 17 00:00:00 2001 From: Qin Wang Date: Wed, 26 Jul 2023 14:28:54 -0700 Subject: [PATCH] Integrate Dart UX with windows_admin_plugin PiperOrigin-RevId: 551316220 --- fastpair/keyed_service/fast_pair_mediator.cc | 2 +- fastpair/plugins/windows_admin_plugin.cc | 56 +++++++++++++++++--- fastpair/plugins/windows_admin_plugin.h | 2 + 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/fastpair/keyed_service/fast_pair_mediator.cc b/fastpair/keyed_service/fast_pair_mediator.cc index a58c6986..16850e2c 100644 --- a/fastpair/keyed_service/fast_pair_mediator.cc +++ b/fastpair/keyed_service/fast_pair_mediator.cc @@ -130,7 +130,7 @@ void Mediator::OnDiscoveryAction(FastPairDevice& device, NEARBY_LOGS(INFO) << __func__ << ": Action = kDismissedByUser"; foreground_currently_showing_notification_ = false; // TODO(b/285453663): update discovery block list - [[fallthrough]]; + break; case DiscoveryAction::kDismissedByTimeout: NEARBY_LOGS(INFO) << __func__ << ": Action = kDismissedByTimeout"; foreground_currently_showing_notification_ = false; diff --git a/fastpair/plugins/windows_admin_plugin.cc b/fastpair/plugins/windows_admin_plugin.cc index 99430c11..c78f4b74 100644 --- a/fastpair/plugins/windows_admin_plugin.cc +++ b/fastpair/plugins/windows_admin_plugin.cc @@ -22,13 +22,45 @@ namespace fastpair { void WindowsAdminPlugin::PluginState::DiscoveryClicked(DiscoveryAction action) { NEARBY_LOGS(INFO) << __func__; if (device == nullptr || fast_pair_service == nullptr) return; - absl::Status status = fast_pair_service->GetSeeker()->StartInitialPairing( - *device, InitialPairingParam{}, - {.on_pairing_result = [](const FastPairDevice& device, - absl::Status status) { - NEARBY_LOGS(INFO) << "Pairing result: " << status; - }}); - NEARBY_LOGS(INFO) << "StartInitialPairing: " << status; + switch (action) { + case DiscoveryAction::kPairToDevice: { + NEARBY_LOGS(INFO) << __func__ << ": Action = kPairToDevice"; + absl::Status status = fast_pair_service->GetSeeker()->StartInitialPairing( + *device, InitialPairingParam{}, + {.on_pairing_result = [this](const FastPairDevice& device, + absl::Status status) { + NEARBY_LOGS(INFO) << "Pairing result: " << status; + for (auto* observer : observers.GetObservers()) { + observer->OnPairingResult(device.GetMetadata().value(), + status.ok()); + } + }}); + NEARBY_LOGS(INFO) << "StartInitialPairing: " << status; + } break; + case DiscoveryAction::kDismissedByOs: + NEARBY_LOGS(INFO) << __func__ << ": Action = kDismissedByOs"; + break; + case DiscoveryAction::kDismissedByUser: + // When the user explicitly dismisses the discovery notification, update + // the device's block-list value accordingly. + NEARBY_LOGS(INFO) << __func__ << ": Action = kDismissedByUser"; + foreground_currently_showing_notification = false; + break; + case DiscoveryAction::kDismissedByTimeout: + NEARBY_LOGS(INFO) << __func__ << ": Action = kDismissedByTimeout"; + foreground_currently_showing_notification = false; + break; + case DiscoveryAction::kLearnMore: + NEARBY_LOGS(INFO) << __func__ << ": Action = kLearnMore"; + break; + case DiscoveryAction::kDone: + NEARBY_LOGS(INFO) << __func__ << ": Action = kDone"; + foreground_currently_showing_notification = false; + break; + default: + NEARBY_LOGS(INFO) << __func__ << ": Action = Unknown"; + break; + } } void WindowsAdminPlugin::PluginState::SetIsScreenLocked(bool is_locked) { @@ -48,6 +80,14 @@ void WindowsAdminPlugin::OnInitialDiscoveryEvent( << "Ignoring initial discovery event because metadata is missing"; return; } + if (state_->foreground_currently_showing_notification) { + NEARBY_LOGS(VERBOSE) << __func__ + << ": Already showing a notification for a device"; + return; + } + // Show discovery notification + state_->foreground_currently_showing_notification = true; + state_->device = device_; for (auto* observer : state_->observers.GetObservers()) { observer->OnUpdateDevice(*metadata); @@ -61,7 +101,7 @@ void WindowsAdminPlugin::OnPairEvent(const PairEvent& event) { {.on_pairing_result = [](const FastPairDevice& device, absl::Status status) { NEARBY_LOGS(INFO) << "Pairing result: " << status; - // TODO(jsobczak): Ask for user constent and save the Account Key to + // TODO(jsobczak): Ask for user consent and save the Account Key to // user's account. }}); NEARBY_LOGS(INFO) << "StartRetroactivePairing: " << status; diff --git a/fastpair/plugins/windows_admin_plugin.h b/fastpair/plugins/windows_admin_plugin.h index 5d2ce3d3..6dd600cf 100644 --- a/fastpair/plugins/windows_admin_plugin.h +++ b/fastpair/plugins/windows_admin_plugin.h @@ -37,7 +37,9 @@ class WindowsAdminPlugin : public FastPairPlugin { ObserverList observers; const FastPairDevice* device = nullptr; std::unique_ptr fast_pair_service; + bool foreground_currently_showing_notification = false; }; + class Provider : public FastPairPluginProvider { public: explicit Provider(PluginState* state) : state_(state) {}