0

[Fast Pair] Add new subsequent pairing notification

Adds new logic to the FastPairNotificationController to display the
subsequent pairing notification with updated strings from UX in
the MessageCenter: https://screenshot.googleplex.com/3EpHVzuRBWgLMiq

Test: Verified on DUT on follow up CL's to confirm
Change-Id: I829122330ecd1e021d91ad3d97e9d7e68f3ae1f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3785129
Reviewed-by: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: Daniel Classon <dclasson@google.com>
Commit-Queue: Juliet Lévesque <julietlevesque@google.com>
Cr-Commit-Position: refs/heads/main@{#1029847}
This commit is contained in:
Juliet Levesque
2022-07-29 17:30:03 +00:00
committed by Chromium LUCI CQ
parent 7d80b8d4fc
commit 4db3baff37
5 changed files with 155 additions and 0 deletions

@ -3305,6 +3305,9 @@ Connect your device to power.
<message name="IDS_FAST_PAIR_DISCOVERY_NOTIFICATION_EMAIL_MESSAGE" desc="Notification message shown when there is a device discovered with Fast Pair that includes the user's email address.">
Your <ph name="NAME">$1<ex>Pixel Buds</ex></ph> will appear on devices linked with <ph name="EMAIL">$2<ex>alisha123@gmail.com</ex></ph>
</message>
<message name="IDS_FAST_PAIR_DISCOVERY_NOTIFICATION_SUBSEQUENT" desc="Notification message shown when there is a device discovered with Fast Pair that has already been saved to a user's account on another device.">
Connect <ph name="NAME">$1<ex>Pixel Buds</ex></ph> previously saved to <ph name="EMAIL">$2<ex>alisha123@gmail.com</ex></ph>
</message>
<message name="IDS_FAST_PAIR_CANCEL_BUTTON" desc="Message on button to tell users to cancel bluetooth device connection with Fast Pair.">
Cancel
</message>

@ -0,0 +1 @@
be2978e6db6a3553ae35ce2897e407228f9d46cc

@ -39,6 +39,8 @@ const char kFastPairPairingNotificationId[] =
"cros_fast_pair_pairing_notification_id";
const char kFastPairAssociateAccountNotificationId[] =
"cros_fast_pair_associate_account_notification_id";
const char kFastPairDiscoverySubsequentNotificationId[] =
"cros_fast_pair_discovery_subsequent_notification_id";
// Values outside of the range (e.g. -1) will show an infinite loading
// progress bar.
@ -257,6 +259,48 @@ void FastPairNotificationController::ShowGuestDiscoveryNotification(
message_center_->AddNotification(std::move(discovery_notification));
}
void FastPairNotificationController::ShowSubsequentDiscoveryNotification(
const std::u16string& device_name,
const std::u16string& email_address,
gfx::Image device_image,
base::RepeatingClosure on_connect_clicked,
base::RepeatingClosure on_learn_more_clicked,
base::OnceCallback<void(bool)> on_close) {
std::unique_ptr<message_center::Notification> discovery_notification =
CreateNotification(kFastPairDiscoverySubsequentNotificationId,
message_center::SystemNotificationWarningLevel::NORMAL,
message_center_);
discovery_notification->set_title(l10n_util::GetStringFUTF16(
IDS_FAST_PAIR_DISCOVERY_NOTIFICATION_TITLE, device_name));
discovery_notification->set_message(l10n_util::GetStringFUTF16(
IDS_FAST_PAIR_DISCOVERY_NOTIFICATION_SUBSEQUENT, device_name,
email_address));
message_center::ButtonInfo connect_button(
l10n_util::GetStringUTF16(IDS_FAST_PAIR_CONNECT_BUTTON));
message_center::ButtonInfo learn_more_button(
l10n_util::GetStringUTF16(IDS_FAST_PAIR_LEARN_MORE_BUTTON));
discovery_notification->set_buttons({connect_button, learn_more_button});
discovery_notification->set_delegate(
base::MakeRefCounted<NotificationDelegate>(
/*on_primary_click=*/on_connect_clicked,
/*on_close=*/std::move(on_close),
/*on_secondary_click=*/on_learn_more_clicked,
/*expire_notification_timer=*/&expire_notification_timer_));
discovery_notification->set_image(device_image);
// Start timer for how long to show the notification before removing the
// notification. After the timeout period, we will remove the notification
// from the Message Center.
expire_notification_timer_.Start(
FROM_HERE, kNotificationTimeout,
base::BindOnce(&FastPairNotificationController::RemoveNotifications,
weak_ptr_factory_.GetWeakPtr()));
message_center_->AddNotification(std::move(discovery_notification));
}
void FastPairNotificationController::ShowApplicationAvailableNotification(
const std::u16string& device_name,
gfx::Image device_image,

@ -47,6 +47,13 @@ class FastPairNotificationController {
base::RepeatingClosure on_connect_clicked,
base::RepeatingClosure on_learn_more_clicked,
base::OnceCallback<void(bool)> on_close);
void ShowSubsequentDiscoveryNotification(
const std::u16string& device_name,
const std::u16string& email_address,
gfx::Image device_image,
base::RepeatingClosure on_connect_clicked,
base::RepeatingClosure on_learn_more_clicked,
base::OnceCallback<void(bool)> on_close);
void ShowApplicationAvailableNotification(
const std::u16string& device_name,
gfx::Image device_image,

@ -37,6 +37,8 @@ const char kFastPairPairingNotificationId[] =
"cros_fast_pair_pairing_notification_id";
const char kFastPairAssociateAccountNotificationId[] =
"cros_fast_pair_associate_account_notification_id";
const char kFastPairDiscoverySubsequentNotificationId[] =
"cros_fast_pair_discovery_subsequent_notification_id";
class TestMessageCenter : public message_center::FakeMessageCenter {
public:
@ -614,5 +616,103 @@ TEST_F(FastPairNotificationControllerTest, ShowAssociateAccount_RemovedByOS) {
base::RunLoop().RunUntilIdle();
}
TEST_F(FastPairNotificationControllerTest,
ShowSubsequentDiscoveryNotification_ConnectClicked) {
EXPECT_FALSE(test_message_center_.FindVisibleNotificationById(
kFastPairDiscoverySubsequentNotificationId));
base::MockCallback<base::OnceCallback<void(bool)>> on_close;
base::MockCallback<base::RepeatingClosure> on_connect_clicked;
base::MockCallback<base::RepeatingClosure> on_learn_more_clicked;
EXPECT_CALL(on_connect_clicked, Run).Times(1);
EXPECT_CALL(on_learn_more_clicked, Run).Times(0);
fast_pair_notification_controller_->ShowSubsequentDiscoveryNotification(
kTestDeviceName, kTestEmail,
/*device_image=*/gfx::Image(), on_connect_clicked.Get(),
on_learn_more_clicked.Get(), on_close.Get());
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(test_message_center_.FindVisibleNotificationById(
kFastPairDiscoverySubsequentNotificationId));
test_message_center_.ClickOnNotificationButton(
/*id=*/kFastPairDiscoverySubsequentNotificationId, /*button_index=*/0);
base::RunLoop().RunUntilIdle();
}
TEST_F(FastPairNotificationControllerTest,
ShowSubsequentDiscoveryNotification_LearnMoreClicked) {
EXPECT_FALSE(test_message_center_.FindVisibleNotificationById(
kFastPairDiscoveryUserNotificationId));
base::MockCallback<base::OnceCallback<void(bool)>> on_close;
base::MockCallback<base::RepeatingClosure> on_connect_clicked;
base::MockCallback<base::RepeatingClosure> on_learn_more_clicked;
EXPECT_CALL(on_connect_clicked, Run).Times(0);
EXPECT_CALL(on_learn_more_clicked, Run).Times(1);
fast_pair_notification_controller_->ShowSubsequentDiscoveryNotification(
kTestDeviceName, kTestEmail,
/*device_image=*/gfx::Image(), on_connect_clicked.Get(),
on_learn_more_clicked.Get(), on_close.Get());
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(test_message_center_.FindVisibleNotificationById(
kFastPairDiscoverySubsequentNotificationId));
test_message_center_.ClickOnNotificationButton(
/*id=*/kFastPairDiscoverySubsequentNotificationId, /*button_index=*/1);
base::RunLoop().RunUntilIdle();
}
TEST_F(FastPairNotificationControllerTest,
ShowSubsequentDiscoveryNotification_RemovedByUser) {
EXPECT_FALSE(test_message_center_.FindVisibleNotificationById(
kFastPairDiscoverySubsequentNotificationId));
base::MockCallback<base::OnceCallback<void(bool)>> on_close;
base::MockCallback<base::RepeatingClosure> on_connect_clicked;
base::MockCallback<base::RepeatingClosure> on_learn_more_clicked;
EXPECT_CALL(on_connect_clicked, Run).Times(0);
EXPECT_CALL(on_learn_more_clicked, Run).Times(0);
EXPECT_CALL(on_close, Run).Times(1);
fast_pair_notification_controller_->ShowSubsequentDiscoveryNotification(
kTestDeviceName, kTestEmail,
/*device_image=*/gfx::Image(), on_connect_clicked.Get(),
on_learn_more_clicked.Get(), on_close.Get());
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(test_message_center_.FindVisibleNotificationById(
kFastPairDiscoverySubsequentNotificationId));
test_message_center_.RemoveNotification(
/*id=*/kFastPairDiscoverySubsequentNotificationId, /*by_user=*/true);
base::RunLoop().RunUntilIdle();
}
TEST_F(FastPairNotificationControllerTest,
ShowSubsequentDiscoveryNotification_RemovedByOS) {
EXPECT_FALSE(test_message_center_.FindVisibleNotificationById(
kFastPairDiscoverySubsequentNotificationId));
base::MockCallback<base::OnceCallback<void(bool)>> on_close;
base::MockCallback<base::RepeatingClosure> on_connect_clicked;
base::MockCallback<base::RepeatingClosure> on_learn_more_clicked;
EXPECT_CALL(on_connect_clicked, Run).Times(0);
EXPECT_CALL(on_learn_more_clicked, Run).Times(0);
EXPECT_CALL(on_close, Run).Times(1);
fast_pair_notification_controller_->ShowSubsequentDiscoveryNotification(
kTestDeviceName, kTestEmail,
/*device_image=*/gfx::Image(), on_connect_clicked.Get(),
on_learn_more_clicked.Get(), on_close.Get());
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(test_message_center_.FindVisibleNotificationById(
kFastPairDiscoverySubsequentNotificationId));
test_message_center_.RemoveNotification(
/*id=*/kFastPairDiscoverySubsequentNotificationId, /*by_user=*/false);
base::RunLoop().RunUntilIdle();
}
} // namespace quick_pair
} // namespace ash