Commit 638e028c authored by Regan Hsu's avatar Regan Hsu Committed by Commit Bot

[CrOS PhoneHub] Persist hiding of notification setup banner on dismiss.

Note that OnShouldShowSetupRequiredUiDismissed() was added for
the debug UI control which will be added in a later CL.

Bug: 1106937
Change-Id: I0b4915827ec690d3f639177d1189fac74da0220f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2488613
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819460}
parent b4bb18df
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ash/system/unified/rounded_label_button.h" #include "ash/system/unified/rounded_label_button.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chromeos/components/phonehub/notification_access_manager.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/views/border.h" #include "ui/views/border.h"
...@@ -55,8 +56,11 @@ constexpr char kMultideviceSettingsUrl[] = ...@@ -55,8 +56,11 @@ constexpr char kMultideviceSettingsUrl[] =
} // namespace } // namespace
NotificationOptInView::NotificationOptInView(TrayBubbleView* bubble_view) NotificationOptInView::NotificationOptInView(
: bubble_view_(bubble_view) { TrayBubbleView* bubble_view,
chromeos::phonehub::NotificationAccessManager* notification_access_manager)
: bubble_view_(bubble_view),
notification_access_manager_(notification_access_manager) {
SetID(PhoneHubViewID::kNotificationOptInView); SetID(PhoneHubViewID::kNotificationOptInView);
InitLayout(); InitLayout();
LogInterstitialScreenEvent(InterstitialScreen::kNotificationOptIn, LogInterstitialScreenEvent(InterstitialScreen::kNotificationOptIn,
...@@ -74,6 +78,7 @@ void NotificationOptInView::ButtonPressed(views::Button* sender, ...@@ -74,6 +78,7 @@ void NotificationOptInView::ButtonPressed(views::Button* sender,
InterstitialScreenEvent::kDismiss); InterstitialScreenEvent::kDismiss);
SetVisible(false); SetVisible(false);
bubble_view_->UpdateBubble(); bubble_view_->UpdateBubble();
notification_access_manager_->DismissSetupRequiredUi();
break; break;
case kSetUpButtonTag: case kSetUpButtonTag:
// Opens the notification set up dialog in settings to start the opt in // Opens the notification set up dialog in settings to start the opt in
......
...@@ -16,6 +16,12 @@ namespace views { ...@@ -16,6 +16,12 @@ namespace views {
class Label; class Label;
} // namespace views } // namespace views
namespace chromeos {
namespace phonehub {
class NotificationAccessManager;
} // namespace phonehub
} // namespace chromeos
namespace ash { namespace ash {
class TrayBubbleView; class TrayBubbleView;
...@@ -27,7 +33,9 @@ class ASH_EXPORT NotificationOptInView : public views::View, ...@@ -27,7 +33,9 @@ class ASH_EXPORT NotificationOptInView : public views::View,
public: public:
METADATA_HEADER(NotificationOptInView); METADATA_HEADER(NotificationOptInView);
explicit NotificationOptInView(TrayBubbleView* bubble_view); NotificationOptInView(TrayBubbleView* bubble_view,
chromeos::phonehub::NotificationAccessManager*
notification_access_manager);
NotificationOptInView(const NotificationOptInView&) = delete; NotificationOptInView(const NotificationOptInView&) = delete;
NotificationOptInView& operator=(const NotificationOptInView&) = delete; NotificationOptInView& operator=(const NotificationOptInView&) = delete;
~NotificationOptInView() override; ~NotificationOptInView() override;
...@@ -47,6 +55,7 @@ class ASH_EXPORT NotificationOptInView : public views::View, ...@@ -47,6 +55,7 @@ class ASH_EXPORT NotificationOptInView : public views::View,
InterstitialViewButton* dismiss_button_ = nullptr; InterstitialViewButton* dismiss_button_ = nullptr;
TrayBubbleView* bubble_view_ = nullptr; TrayBubbleView* bubble_view_ = nullptr;
chromeos::phonehub::NotificationAccessManager* notification_access_manager_;
}; };
} // namespace ash } // namespace ash
......
...@@ -45,11 +45,14 @@ PhoneConnectedView::PhoneConnectedView( ...@@ -45,11 +45,14 @@ PhoneConnectedView::PhoneConnectedView(
AddSeparator(); AddSeparator();
// TODO(meilinw): handle the case when the user has dismissed this opt in chromeos::phonehub::NotificationAccessManager* access_manager =
// view once, we shouldn't show it again. phone_hub_manager->GetNotificationAccessManager();
if (!phone_hub_manager->GetNotificationAccessManager() bool should_show_notification_setup_ui =
->HasAccessBeenGranted()) { !access_manager->HasAccessBeenGranted() &&
AddChildView(std::make_unique<NotificationOptInView>(bubble_view)); !access_manager->HasNotificationSetupUiBeenDismissed();
if (should_show_notification_setup_ui) {
AddChildView(std::make_unique<NotificationOptInView>(
bubble_view, phone_hub_manager->GetNotificationAccessManager()));
} }
setup_layered_view( setup_layered_view(
......
...@@ -26,6 +26,19 @@ bool FakeNotificationAccessManager::HasAccessBeenGranted() const { ...@@ -26,6 +26,19 @@ bool FakeNotificationAccessManager::HasAccessBeenGranted() const {
return has_access_been_granted_; return has_access_been_granted_;
} }
bool FakeNotificationAccessManager::HasNotificationSetupUiBeenDismissed()
const {
return has_notification_setup_ui_been_dismissed_;
}
void FakeNotificationAccessManager::DismissSetupRequiredUi() {
has_notification_setup_ui_been_dismissed_ = true;
}
void FakeNotificationAccessManager::ResetHasNotificationSetupUiBeenDismissed() {
has_notification_setup_ui_been_dismissed_ = false;
}
void FakeNotificationAccessManager::SetNotificationSetupOperationStatus( void FakeNotificationAccessManager::SetNotificationSetupOperationStatus(
NotificationAccessSetupOperation::Status new_status) { NotificationAccessSetupOperation::Status new_status) {
if (new_status == if (new_status ==
......
...@@ -23,9 +23,14 @@ class FakeNotificationAccessManager : public NotificationAccessManager { ...@@ -23,9 +23,14 @@ class FakeNotificationAccessManager : public NotificationAccessManager {
// NotificationAccessManager: // NotificationAccessManager:
bool HasAccessBeenGranted() const override; bool HasAccessBeenGranted() const override;
bool HasNotificationSetupUiBeenDismissed() const override;
void DismissSetupRequiredUi() override;
void ResetHasNotificationSetupUiBeenDismissed();
private: private:
bool has_access_been_granted_; bool has_access_been_granted_;
bool has_notification_setup_ui_been_dismissed_ = false;
}; };
} // namespace phonehub } // namespace phonehub
......
...@@ -41,6 +41,11 @@ class NotificationAccessManager { ...@@ -41,6 +41,11 @@ class NotificationAccessManager {
virtual bool HasAccessBeenGranted() const = 0; virtual bool HasAccessBeenGranted() const = 0;
virtual bool HasNotificationSetupUiBeenDismissed() const = 0;
// Disables the ability to show the banner within the PhoneHub UI.
virtual void DismissSetupRequiredUi() = 0;
// Starts an attempt to enable the notification access. |delegate| will be // Starts an attempt to enable the notification access. |delegate| will be
// updated with the status of the flow as long as the operation object // updated with the status of the flow as long as the operation object
// returned by this function remains instantiated. // returned by this function remains instantiated.
......
...@@ -18,6 +18,7 @@ namespace phonehub { ...@@ -18,6 +18,7 @@ namespace phonehub {
void NotificationAccessManagerImpl::RegisterPrefs( void NotificationAccessManagerImpl::RegisterPrefs(
PrefRegistrySimple* registry) { PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(prefs::kNotificationAccessGranted, false); registry->RegisterBooleanPref(prefs::kNotificationAccessGranted, false);
registry->RegisterBooleanPref(prefs::kHasDismissedSetupRequiredUi, false);
} }
NotificationAccessManagerImpl::NotificationAccessManagerImpl( NotificationAccessManagerImpl::NotificationAccessManagerImpl(
...@@ -40,6 +41,15 @@ NotificationAccessManagerImpl::~NotificationAccessManagerImpl() { ...@@ -40,6 +41,15 @@ NotificationAccessManagerImpl::~NotificationAccessManagerImpl() {
feature_status_provider_->RemoveObserver(this); feature_status_provider_->RemoveObserver(this);
} }
bool NotificationAccessManagerImpl::HasNotificationSetupUiBeenDismissed()
const {
return pref_service_->GetBoolean(prefs::kHasDismissedSetupRequiredUi);
}
void NotificationAccessManagerImpl::DismissSetupRequiredUi() {
pref_service_->SetBoolean(prefs::kHasDismissedSetupRequiredUi, true);
}
bool NotificationAccessManagerImpl::HasAccessBeenGranted() const { bool NotificationAccessManagerImpl::HasAccessBeenGranted() const {
return pref_service_->GetBoolean(prefs::kNotificationAccessGranted); return pref_service_->GetBoolean(prefs::kNotificationAccessGranted);
} }
......
...@@ -43,6 +43,9 @@ class NotificationAccessManagerImpl : public NotificationAccessManager, ...@@ -43,6 +43,9 @@ class NotificationAccessManagerImpl : public NotificationAccessManager,
void SetHasAccessBeenGrantedInternal(bool has_access_been_granted) override; void SetHasAccessBeenGrantedInternal(bool has_access_been_granted) override;
void OnSetupRequested() override; void OnSetupRequested() override;
bool HasNotificationSetupUiBeenDismissed() const override;
void DismissSetupRequiredUi() override;
// FeatureStatusProvider::Observer: // FeatureStatusProvider::Observer:
void OnFeatureStatusChanged() override; void OnFeatureStatusChanged() override;
......
...@@ -93,6 +93,12 @@ class NotificationAccessManagerImplTest : public testing::Test { ...@@ -93,6 +93,12 @@ class NotificationAccessManagerImplTest : public testing::Test {
EXPECT_EQ(expected_value, manager_->HasAccessBeenGranted()); EXPECT_EQ(expected_value, manager_->HasAccessBeenGranted());
} }
bool HasNotificationSetupUiBeenDismissed() {
return manager_->HasNotificationSetupUiBeenDismissed();
}
void DismissSetupRequiredUi() { manager_->DismissSetupRequiredUi(); }
std::unique_ptr<NotificationAccessSetupOperation> StartSetupOperation() { std::unique_ptr<NotificationAccessSetupOperation> StartSetupOperation() {
return manager_->AttemptNotificationSetup(&fake_delegate_); return manager_->AttemptNotificationSetup(&fake_delegate_);
} }
...@@ -134,6 +140,30 @@ class NotificationAccessManagerImplTest : public testing::Test { ...@@ -134,6 +140,30 @@ class NotificationAccessManagerImplTest : public testing::Test {
std::unique_ptr<NotificationAccessManager> manager_; std::unique_ptr<NotificationAccessManager> manager_;
}; };
TEST_F(NotificationAccessManagerImplTest, ShouldShowSetupRequiredUi) {
// Notification setup is not dismissed initially even when access has been
// granted.
Initialize(/*initial_has_access_been_granted=*/true);
EXPECT_FALSE(HasNotificationSetupUiBeenDismissed());
// Notification setup is not dismissed initially when access has not been
// granted.
Initialize(/*initial_has_access_been_granted=*/false);
EXPECT_FALSE(HasNotificationSetupUiBeenDismissed());
// Simlulate dismissal of UI.
DismissSetupRequiredUi();
EXPECT_TRUE(HasNotificationSetupUiBeenDismissed());
// Dismissal value is persisted on initialization with access not granted.
Initialize(/*initial_has_access_been_granted=*/false);
EXPECT_TRUE(HasNotificationSetupUiBeenDismissed());
// Dismissal value is persisted on initialization with access granted.
Initialize(/*initial_has_access_been_granted=*/true);
EXPECT_TRUE(HasNotificationSetupUiBeenDismissed());
}
TEST_F(NotificationAccessManagerImplTest, InitiallyGranted) { TEST_F(NotificationAccessManagerImplTest, InitiallyGranted) {
Initialize(/*initial_has_access_been_granted=*/true); Initialize(/*initial_has_access_been_granted=*/true);
VerifyNotificationAccessGrantedState(/*expected_value=*/true); VerifyNotificationAccessGrantedState(/*expected_value=*/true);
......
...@@ -21,6 +21,11 @@ const char kHasDismissedUiAfterCompletingOnboarding[] = ...@@ -21,6 +21,11 @@ const char kHasDismissedUiAfterCompletingOnboarding[] =
const char kIsAwaitingVerifiedHost[] = const char kIsAwaitingVerifiedHost[] =
"cros.phonehub.is_awaiting_verified_host"; "cros.phonehub.is_awaiting_verified_host";
// Whether the Notification access setup banner in the PhoneHub UI has
// been dismissed.
const char kHasDismissedSetupRequiredUi[] =
"cros.phonehub.has_dismissed_setup_required_ui";
} // namespace prefs } // namespace prefs
} // namespace phonehub } // namespace phonehub
} // namespace chromeos } // namespace chromeos
...@@ -12,6 +12,7 @@ namespace prefs { ...@@ -12,6 +12,7 @@ namespace prefs {
extern const char kNotificationAccessGranted[]; extern const char kNotificationAccessGranted[];
extern const char kHasDismissedUiAfterCompletingOnboarding[]; extern const char kHasDismissedUiAfterCompletingOnboarding[];
extern const char kIsAwaitingVerifiedHost[]; extern const char kIsAwaitingVerifiedHost[];
extern const char kHasDismissedSetupRequiredUi[];
} // namespace prefs } // namespace prefs
} // namespace phonehub } // namespace phonehub
......
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