Commit 773c26f5 authored by Regan Hsu's avatar Regan Hsu Committed by Commit Bot

[CrOS PhoneHub] Dismissal undo for Onboarding and NotificationAccess UI

* When user clicks dismiss on the real Notification Setup UI in phonehub
  they can now show the UI again by clicking a button.
* When user dismisses the real onboarding UI, they can now show the UI
  again by clicking a button.

Other-
* When user dismisses the fake onboarding UI, it will be reflected to
  the toggle accurately as off.

Screenshots:
https://screenshot.googleplex.com/6eofiCBa3afSUMT
https://screenshot.googleplex.com/3YLYNsHkA6aGVKo

Bug: 1106938
Change-Id: I2fb56e1864905602a9ae769d0d9b007294fa7441
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490513Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820391}
parent db69599f
...@@ -127,6 +127,7 @@ js_library("phonehub_tab") { ...@@ -127,6 +127,7 @@ js_library("phonehub_tab") {
":quick_action_controller_form", ":quick_action_controller_form",
":types", ":types",
"//ui/webui/resources/js:load_time_data.m", "//ui/webui/resources/js:load_time_data.m",
"//ui/webui/resources/js:web_ui_listener_behavior.m",
] ]
} }
......
...@@ -99,6 +99,21 @@ export class MultidevicePhoneHubBrowserProxy { ...@@ -99,6 +99,21 @@ export class MultidevicePhoneHubBrowserProxy {
setTetherStatus(tetherStatus) { setTetherStatus(tetherStatus) {
chrome.send('setTetherStatus', [tetherStatus]); chrome.send('setTetherStatus', [tetherStatus]);
} }
/**
* Resets should show onboarding UI for the real PhoneHubManager.
*/
resetShouldShowOnboardingUi() {
chrome.send('resetShouldShowOnboardingUi');
}
/**
* Resets notification setup UI to not having been dismissed for the real
* PhoneHubManager.
*/
resetHasNotificationSetupUiBeenDismissed() {
chrome.send('resetHasNotificationSetupUiBeenDismissed');
}
} }
addSingletonGetter(MultidevicePhoneHubBrowserProxy); addSingletonGetter(MultidevicePhoneHubBrowserProxy);
...@@ -24,6 +24,30 @@ ...@@ -24,6 +24,30 @@
<cr-toggle checked="{{shouldEnableFakePhoneHubManager_}}"> <cr-toggle checked="{{shouldEnableFakePhoneHubManager_}}">
</cr-toggle> </cr-toggle>
</div> </div>
<template is="dom-if" if="[[!shouldEnableFakePhoneHubManager_]]" restamp>
<div class="cr-row">
<div class="cr-padded-text">
Click to undo Notification Setup UI user dismissal. Note that
Notification access must be revoked by the phone (Toggle "Google Play
Services" to off in Apps & notifications > Special app access >
Notification access.
</div>
<cr-button class="internals-button"
on-click="onResetHasNotificationSetupUiBeenDismissedButtonClick_">
Reset
</cr-button>
</div>
<div class="cr-row">
<div class="cr-padded-text">
Click to undo Onboarding UI user dismissal. Note that the user must
have not started the opt-in flow yet.
</div>
<cr-button class="internals-button"
on-click="onResetShouldShowOnboardingUiButtonClick_">
Reset
</cr-button>
</div>
</template>
<template is="dom-if" if="[[shouldEnableFakePhoneHubManager_]]" restamp> <template is="dom-if" if="[[shouldEnableFakePhoneHubManager_]]" restamp>
<div class="cr-row"> <div class="cr-row">
<div class="cr-padded-text"> <div class="cr-padded-text">
......
...@@ -15,6 +15,7 @@ import './shared_style.js'; ...@@ -15,6 +15,7 @@ import './shared_style.js';
import './quick_action_controller_form.js'; import './quick_action_controller_form.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {WebUIListenerBehavior} from 'chrome://resources/js/web_ui_listener_behavior.m.js';
import {flush, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {flush, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {MultidevicePhoneHubBrowserProxy} from './multidevice_phonehub_browser_proxy.js'; import {MultidevicePhoneHubBrowserProxy} from './multidevice_phonehub_browser_proxy.js';
import {FeatureStatus} from './types.js'; import {FeatureStatus} from './types.js';
...@@ -45,6 +46,10 @@ Polymer({ ...@@ -45,6 +46,10 @@ Polymer({
_template: html`{__html_template__}`, _template: html`{__html_template__}`,
behaviors: [
WebUIListenerBehavior,
],
properties: { properties: {
/** @private */ /** @private */
isPhoneHubEnabled_: { isPhoneHubEnabled_: {
...@@ -121,6 +126,13 @@ Polymer({ ...@@ -121,6 +126,13 @@ Polymer({
this.browserProxy_ = MultidevicePhoneHubBrowserProxy.getInstance(); this.browserProxy_ = MultidevicePhoneHubBrowserProxy.getInstance();
}, },
/** @override */
attached() {
this.addWebUIListener(
'should-show-onboarding-ui-changed',
this.onShouldShowOnboardingUiChanged_.bind(this));
},
/** /**
* @return {boolean} * @return {boolean}
* @private * @private
...@@ -190,6 +202,26 @@ Polymer({ ...@@ -190,6 +202,26 @@ Polymer({
window.open('chrome://flags/#enable-phone-hub'); window.open('chrome://flags/#enable-phone-hub');
}, },
/**
* @param {boolean} shouldShowOnboardingUi
* @private
*/
onShouldShowOnboardingUiChanged_(shouldShowOnboardingUi) {
if (this.shouldShowOnboardingFlow_ !== shouldShowOnboardingUi) {
this.shouldShowOnboardingFlow_ = shouldShowOnboardingUi;
}
},
/** @private */
onResetHasNotificationSetupUiBeenDismissedButtonClick_() {
this.browserProxy_.resetHasNotificationSetupUiBeenDismissed();
},
/** @private */
onResetShouldShowOnboardingUiButtonClick_() {
this.browserProxy_.resetShouldShowOnboardingUi();
},
/** @private */ /** @private */
onShouldShowOnboardingFlowChanged_() { onShouldShowOnboardingFlowChanged_() {
if (!this.shouldEnableFakePhoneHubManager_) { if (!this.shouldEnableFakePhoneHubManager_) {
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chromeos/components/multidevice/logging/logging.h" #include "chromeos/components/multidevice/logging/logging.h"
#include "chromeos/components/phonehub/fake_phone_hub_manager.h" #include "chromeos/components/phonehub/fake_phone_hub_manager.h"
#include "chromeos/components/phonehub/pref_names.h"
#include "components/prefs/pref_service.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
...@@ -184,6 +186,18 @@ void MultidevicePhoneHubHandler::RegisterMessages() { ...@@ -184,6 +186,18 @@ void MultidevicePhoneHubHandler::RegisterMessages() {
"setTetherStatus", "setTetherStatus",
base::BindRepeating(&MultidevicePhoneHubHandler::HandleSetTetherStatus, base::BindRepeating(&MultidevicePhoneHubHandler::HandleSetTetherStatus,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"resetShouldShowOnboardingUi",
base::BindRepeating(
&MultidevicePhoneHubHandler::HandleResetShouldShowOnboardingUi,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"resetHasNotificationSetupUiBeenDismissed",
base::BindRepeating(&MultidevicePhoneHubHandler::
HandleResetHasNotificationSetupUiBeenDismissed,
base::Unretained(this)));
} }
void MultidevicePhoneHubHandler::OnJavascriptDisallowed() { void MultidevicePhoneHubHandler::OnJavascriptDisallowed() {
...@@ -199,6 +213,8 @@ void MultidevicePhoneHubHandler::AddObservers() { ...@@ -199,6 +213,8 @@ void MultidevicePhoneHubHandler::AddObservers() {
fake_phone_hub_manager_->fake_find_my_device_controller()); fake_phone_hub_manager_->fake_find_my_device_controller());
tether_controller_observer_.Add( tether_controller_observer_.Add(
fake_phone_hub_manager_->fake_tether_controller()); fake_phone_hub_manager_->fake_tether_controller());
onboarding_ui_tracker_observer_.Add(
fake_phone_hub_manager_->fake_onboarding_ui_tracker());
} }
void MultidevicePhoneHubHandler::RemoveObservers() { void MultidevicePhoneHubHandler::RemoveObservers() {
...@@ -228,6 +244,12 @@ void MultidevicePhoneHubHandler::RemoveObservers() { ...@@ -228,6 +244,12 @@ void MultidevicePhoneHubHandler::RemoveObservers() {
if (tether_controller_observer_.IsObserving(fake_tether_controller)) { if (tether_controller_observer_.IsObserving(fake_tether_controller)) {
tether_controller_observer_.Remove(fake_tether_controller); tether_controller_observer_.Remove(fake_tether_controller);
} }
phonehub::OnboardingUiTracker* fake_onboarding_ui_tracker =
fake_phone_hub_manager_->fake_onboarding_ui_tracker();
if (onboarding_ui_tracker_observer_.IsObserving(fake_onboarding_ui_tracker)) {
onboarding_ui_tracker_observer_.Remove(fake_onboarding_ui_tracker);
}
} }
void MultidevicePhoneHubHandler::OnNotificationsRemoved( void MultidevicePhoneHubHandler::OnNotificationsRemoved(
...@@ -261,6 +283,14 @@ void MultidevicePhoneHubHandler::OnTetherStatusChanged() { ...@@ -261,6 +283,14 @@ void MultidevicePhoneHubHandler::OnTetherStatusChanged() {
FireWebUIListener("tether-status-changed", base::Value(status_as_int)); FireWebUIListener("tether-status-changed", base::Value(status_as_int));
} }
void MultidevicePhoneHubHandler::OnShouldShowOnboardingUiChanged() {
bool should_show_onboarding_ui =
fake_phone_hub_manager_->fake_onboarding_ui_tracker()
->ShouldShowOnboardingUi();
FireWebUIListener("should-show-onboarding-ui-changed",
base::Value(should_show_onboarding_ui));
}
void MultidevicePhoneHubHandler::HandleEnableDnd(const base::ListValue* args) { void MultidevicePhoneHubHandler::HandleEnableDnd(const base::ListValue* args) {
bool enabled = false; bool enabled = false;
CHECK(args->GetBoolean(0, &enabled)); CHECK(args->GetBoolean(0, &enabled));
...@@ -528,5 +558,22 @@ void MultidevicePhoneHubHandler::HandleRemoveNotification( ...@@ -528,5 +558,22 @@ void MultidevicePhoneHubHandler::HandleRemoveNotification(
PA_LOG(VERBOSE) << "Removed notification with id " << notification_id; PA_LOG(VERBOSE) << "Removed notification with id " << notification_id;
} }
void MultidevicePhoneHubHandler::HandleResetShouldShowOnboardingUi(
const base::ListValue* args) {
PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
prefs->SetBoolean(
chromeos::phonehub::prefs::kHasDismissedUiAfterCompletingOnboarding,
false);
PA_LOG(VERBOSE) << "Reset kHasDismissedUiAfterCompletingOnboarding pref";
}
void MultidevicePhoneHubHandler::HandleResetHasNotificationSetupUiBeenDismissed(
const base::ListValue* args) {
PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
prefs->SetBoolean(chromeos::phonehub::prefs::kHasDismissedSetupRequiredUi,
false);
PA_LOG(VERBOSE) << "Reset kHasDismissedSetupRequiredUi pref";
}
} // namespace multidevice } // namespace multidevice
} // namespace chromeos } // namespace chromeos
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "chromeos/components/phonehub/do_not_disturb_controller.h" #include "chromeos/components/phonehub/do_not_disturb_controller.h"
#include "chromeos/components/phonehub/find_my_device_controller.h" #include "chromeos/components/phonehub/find_my_device_controller.h"
#include "chromeos/components/phonehub/notification_manager.h" #include "chromeos/components/phonehub/notification_manager.h"
#include "chromeos/components/phonehub/onboarding_ui_tracker.h"
#include "chromeos/components/phonehub/tether_controller.h" #include "chromeos/components/phonehub/tether_controller.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
...@@ -26,7 +27,8 @@ class MultidevicePhoneHubHandler ...@@ -26,7 +27,8 @@ class MultidevicePhoneHubHandler
public phonehub::NotificationManager::Observer, public phonehub::NotificationManager::Observer,
public phonehub::DoNotDisturbController::Observer, public phonehub::DoNotDisturbController::Observer,
public phonehub::FindMyDeviceController::Observer, public phonehub::FindMyDeviceController::Observer,
public phonehub::TetherController::Observer { public phonehub::TetherController::Observer,
public phonehub::OnboardingUiTracker::Observer {
public: public:
MultidevicePhoneHubHandler(); MultidevicePhoneHubHandler();
MultidevicePhoneHubHandler(const MultidevicePhoneHubHandler&) = delete; MultidevicePhoneHubHandler(const MultidevicePhoneHubHandler&) = delete;
...@@ -53,6 +55,9 @@ class MultidevicePhoneHubHandler ...@@ -53,6 +55,9 @@ class MultidevicePhoneHubHandler
// TetherController::Observer // TetherController::Observer
void OnTetherStatusChanged() override; void OnTetherStatusChanged() override;
// OnboardingUiTracker::Observer
void OnShouldShowOnboardingUiChanged() override;
void EnableRealPhoneHubManager(); void EnableRealPhoneHubManager();
void EnableFakePhoneHubManager(); void EnableFakePhoneHubManager();
void HandleEnableFakePhoneHubManager(const base::ListValue* args); void HandleEnableFakePhoneHubManager(const base::ListValue* args);
...@@ -66,6 +71,9 @@ class MultidevicePhoneHubHandler ...@@ -66,6 +71,9 @@ class MultidevicePhoneHubHandler
void HandleEnableDnd(const base::ListValue* args); void HandleEnableDnd(const base::ListValue* args);
void HandleSetFindMyDeviceStatus(const base::ListValue* args); void HandleSetFindMyDeviceStatus(const base::ListValue* args);
void HandleSetTetherStatus(const base::ListValue* args); void HandleSetTetherStatus(const base::ListValue* args);
void HandleResetShouldShowOnboardingUi(const base::ListValue* args);
void HandleResetHasNotificationSetupUiBeenDismissed(
const base::ListValue* args);
void AddObservers(); void AddObservers();
void RemoveObservers(); void RemoveObservers();
...@@ -83,6 +91,9 @@ class MultidevicePhoneHubHandler ...@@ -83,6 +91,9 @@ class MultidevicePhoneHubHandler
ScopedObserver<phonehub::TetherController, ScopedObserver<phonehub::TetherController,
phonehub::TetherController::Observer> phonehub::TetherController::Observer>
tether_controller_observer_{this}; tether_controller_observer_{this};
ScopedObserver<phonehub::OnboardingUiTracker,
phonehub::OnboardingUiTracker::Observer>
onboarding_ui_tracker_observer_{this};
}; };
} // namespace multidevice } // namespace multidevice
......
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