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") {
":quick_action_controller_form",
":types",
"//ui/webui/resources/js:load_time_data.m",
"//ui/webui/resources/js:web_ui_listener_behavior.m",
]
}
......
......@@ -99,6 +99,21 @@ export class MultidevicePhoneHubBrowserProxy {
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);
......@@ -24,6 +24,30 @@
<cr-toggle checked="{{shouldEnableFakePhoneHubManager_}}">
</cr-toggle>
</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>
<div class="cr-row">
<div class="cr-padded-text">
......
......@@ -15,6 +15,7 @@ import './shared_style.js';
import './quick_action_controller_form.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 {MultidevicePhoneHubBrowserProxy} from './multidevice_phonehub_browser_proxy.js';
import {FeatureStatus} from './types.js';
......@@ -45,6 +46,10 @@ Polymer({
_template: html`{__html_template__}`,
behaviors: [
WebUIListenerBehavior,
],
properties: {
/** @private */
isPhoneHubEnabled_: {
......@@ -121,6 +126,13 @@ Polymer({
this.browserProxy_ = MultidevicePhoneHubBrowserProxy.getInstance();
},
/** @override */
attached() {
this.addWebUIListener(
'should-show-onboarding-ui-changed',
this.onShouldShowOnboardingUiChanged_.bind(this));
},
/**
* @return {boolean}
* @private
......@@ -190,6 +202,26 @@ Polymer({
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 */
onShouldShowOnboardingFlowChanged_() {
if (!this.shouldEnableFakePhoneHubManager_) {
......
......@@ -11,6 +11,8 @@
#include "chrome/browser/profiles/profile.h"
#include "chromeos/components/multidevice/logging/logging.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 "ui/gfx/image/image.h"
......@@ -184,6 +186,18 @@ void MultidevicePhoneHubHandler::RegisterMessages() {
"setTetherStatus",
base::BindRepeating(&MultidevicePhoneHubHandler::HandleSetTetherStatus,
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() {
......@@ -199,6 +213,8 @@ void MultidevicePhoneHubHandler::AddObservers() {
fake_phone_hub_manager_->fake_find_my_device_controller());
tether_controller_observer_.Add(
fake_phone_hub_manager_->fake_tether_controller());
onboarding_ui_tracker_observer_.Add(
fake_phone_hub_manager_->fake_onboarding_ui_tracker());
}
void MultidevicePhoneHubHandler::RemoveObservers() {
......@@ -228,6 +244,12 @@ void MultidevicePhoneHubHandler::RemoveObservers() {
if (tether_controller_observer_.IsObserving(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(
......@@ -261,6 +283,14 @@ void MultidevicePhoneHubHandler::OnTetherStatusChanged() {
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) {
bool enabled = false;
CHECK(args->GetBoolean(0, &enabled));
......@@ -528,5 +558,22 @@ void MultidevicePhoneHubHandler::HandleRemoveNotification(
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 chromeos
......@@ -9,6 +9,7 @@
#include "chromeos/components/phonehub/do_not_disturb_controller.h"
#include "chromeos/components/phonehub/find_my_device_controller.h"
#include "chromeos/components/phonehub/notification_manager.h"
#include "chromeos/components/phonehub/onboarding_ui_tracker.h"
#include "chromeos/components/phonehub/tether_controller.h"
#include "content/public/browser/web_ui_message_handler.h"
......@@ -26,7 +27,8 @@ class MultidevicePhoneHubHandler
public phonehub::NotificationManager::Observer,
public phonehub::DoNotDisturbController::Observer,
public phonehub::FindMyDeviceController::Observer,
public phonehub::TetherController::Observer {
public phonehub::TetherController::Observer,
public phonehub::OnboardingUiTracker::Observer {
public:
MultidevicePhoneHubHandler();
MultidevicePhoneHubHandler(const MultidevicePhoneHubHandler&) = delete;
......@@ -53,6 +55,9 @@ class MultidevicePhoneHubHandler
// TetherController::Observer
void OnTetherStatusChanged() override;
// OnboardingUiTracker::Observer
void OnShouldShowOnboardingUiChanged() override;
void EnableRealPhoneHubManager();
void EnableFakePhoneHubManager();
void HandleEnableFakePhoneHubManager(const base::ListValue* args);
......@@ -66,6 +71,9 @@ class MultidevicePhoneHubHandler
void HandleEnableDnd(const base::ListValue* args);
void HandleSetFindMyDeviceStatus(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 RemoveObservers();
......@@ -83,6 +91,9 @@ class MultidevicePhoneHubHandler
ScopedObserver<phonehub::TetherController,
phonehub::TetherController::Observer>
tether_controller_observer_{this};
ScopedObserver<phonehub::OnboardingUiTracker,
phonehub::OnboardingUiTracker::Observer>
onboarding_ui_tracker_observer_{this};
};
} // 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