Commit ea6592ca authored by Yue Li's avatar Yue Li Committed by Commit Bot

Disable Assistant for dasher domain

If the Assistant is disabled by dasher domain admin, disable the
Assistant in settings and disallow user to enable it.

Also update tests for opt-in flow and settings.

AssistantOptInFlowTest.* in browser_tests

Bug: b/130424602
Test: run CrSettingsGoogleAssistantPageTest.All and
Change-Id: Ieb040d54f5cb9127d8bcaaf3e7b4eb825593eb72
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1633649Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Yue Li <updowndota@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666565}
parent ac673d1e
...@@ -70,8 +70,8 @@ class FakeAssistantSettings ...@@ -70,8 +70,8 @@ class FakeAssistantSettings
static constexpr int CONSENT_UI_FLAG_SKIP_ACTIVITY_CONTROL = 1; static constexpr int CONSENT_UI_FLAG_SKIP_ACTIVITY_CONTROL = 1;
static constexpr int CONSENT_UI_FLAG_SKIP_THIRD_PARTY_DISCLOSURE = 1 << 1; static constexpr int CONSENT_UI_FLAG_SKIP_THIRD_PARTY_DISCLOSURE = 1 << 1;
static constexpr int CONSENT_UI_FLAG_ASK_EMAIL_OPT_IN = 1 << 2; static constexpr int CONSENT_UI_FLAG_ASK_EMAIL_OPT_IN = 1 << 2;
static constexpr int CONSENT_UI_FLAG_WAA_DISABLED_BY_DOMAIN = 1 << 3; static constexpr int CONSENT_UI_FLAG_WAA_DISABLED_BY_POLICY = 1 << 3;
static constexpr int CONSENT_UI_FLAG_ASSISTANT_DISABLED_BY_DOMAIN = 1 << 4; static constexpr int CONSENT_UI_FLAG_ASSISTANT_DISABLED_BY_POLICY = 1 << 4;
enum class SpeakerIdEnrollmentMode { enum class SpeakerIdEnrollmentMode {
// On speaker enrollment request, the client will be notified that the // On speaker enrollment request, the client will be notified that the
...@@ -180,9 +180,9 @@ class FakeAssistantSettings ...@@ -180,9 +180,9 @@ class FakeAssistantSettings
auto* gaia_user_context_ui = settings_ui.mutable_gaia_user_context_ui(); auto* gaia_user_context_ui = settings_ui.mutable_gaia_user_context_ui();
gaia_user_context_ui->set_is_gaia_user(true); gaia_user_context_ui->set_is_gaia_user(true);
gaia_user_context_ui->set_waa_disabled_by_dasher_domain( gaia_user_context_ui->set_waa_disabled_by_dasher_domain(
(consent_ui_flags_ & CONSENT_UI_FLAG_WAA_DISABLED_BY_DOMAIN)); (consent_ui_flags_ & CONSENT_UI_FLAG_WAA_DISABLED_BY_POLICY));
gaia_user_context_ui->set_assistant_disabled_by_dasher_domain( gaia_user_context_ui->set_assistant_disabled_by_dasher_domain(
(consent_ui_flags_ & CONSENT_UI_FLAG_ASSISTANT_DISABLED_BY_DOMAIN)); (consent_ui_flags_ & CONSENT_UI_FLAG_ASSISTANT_DISABLED_BY_POLICY));
auto* consent_flow_ui = settings_ui.mutable_consent_flow_ui(); auto* consent_flow_ui = settings_ui.mutable_consent_flow_ui();
consent_flow_ui->set_consent_status( consent_flow_ui->set_consent_status(
...@@ -1139,9 +1139,9 @@ IN_PROC_BROWSER_TEST_F(AssistantOptInFlowTest, ...@@ -1139,9 +1139,9 @@ IN_PROC_BROWSER_TEST_F(AssistantOptInFlowTest,
EXPECT_TRUE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled)); EXPECT_TRUE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled));
} }
IN_PROC_BROWSER_TEST_F(AssistantOptInFlowTest, WAADisabledByDasherDomain) { IN_PROC_BROWSER_TEST_F(AssistantOptInFlowTest, WAADisabledByPolicy) {
assistant_settings_->set_consent_ui_flags( assistant_settings_->set_consent_ui_flags(
FakeAssistantSettings::CONSENT_UI_FLAG_WAA_DISABLED_BY_DOMAIN); FakeAssistantSettings::CONSENT_UI_FLAG_WAA_DISABLED_BY_POLICY);
arc::VoiceInteractionControllerClient::Get()->NotifyStatusChanged( arc::VoiceInteractionControllerClient::Get()->NotifyStatusChanged(
ash::mojom::VoiceInteractionState::STOPPED); ash::mojom::VoiceInteractionState::STOPPED);
...@@ -1152,14 +1152,14 @@ IN_PROC_BROWSER_TEST_F(AssistantOptInFlowTest, WAADisabledByDasherDomain) { ...@@ -1152,14 +1152,14 @@ IN_PROC_BROWSER_TEST_F(AssistantOptInFlowTest, WAADisabledByDasherDomain) {
ExpectCollectedOptIns({}); ExpectCollectedOptIns({});
PrefService* const prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); PrefService* const prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
EXPECT_TRUE(prefs->GetBoolean(arc::prefs::kVoiceInteractionEnabled));
EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled)); EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled));
EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled)); EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled));
} }
IN_PROC_BROWSER_TEST_F(AssistantOptInFlowTest, IN_PROC_BROWSER_TEST_F(AssistantOptInFlowTest, AssistantDisabledByPolicy) {
AssistantDisabledByDasherDomain) {
assistant_settings_->set_consent_ui_flags( assistant_settings_->set_consent_ui_flags(
FakeAssistantSettings::CONSENT_UI_FLAG_ASSISTANT_DISABLED_BY_DOMAIN); FakeAssistantSettings::CONSENT_UI_FLAG_ASSISTANT_DISABLED_BY_POLICY);
arc::VoiceInteractionControllerClient::Get()->NotifyStatusChanged( arc::VoiceInteractionControllerClient::Get()->NotifyStatusChanged(
ash::mojom::VoiceInteractionState::STOPPED); ash::mojom::VoiceInteractionState::STOPPED);
...@@ -1170,6 +1170,9 @@ IN_PROC_BROWSER_TEST_F(AssistantOptInFlowTest, ...@@ -1170,6 +1170,9 @@ IN_PROC_BROWSER_TEST_F(AssistantOptInFlowTest,
ExpectCollectedOptIns({}); ExpectCollectedOptIns({});
PrefService* const prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); PrefService* const prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
EXPECT_TRUE(
prefs->GetBoolean(::assistant::prefs::kAssistantDisabledByPolicy));
EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionEnabled));
EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled)); EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled));
EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled)); EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled));
} }
......
...@@ -403,6 +403,8 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() { ...@@ -403,6 +403,8 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
// Google Assistant. // Google Assistant.
(*s_whitelist)[::assistant::prefs::kAssistantConsentStatus] = (*s_whitelist)[::assistant::prefs::kAssistantConsentStatus] =
settings_api::PrefType::PREF_TYPE_NUMBER; settings_api::PrefType::PREF_TYPE_NUMBER;
(*s_whitelist)[::assistant::prefs::kAssistantDisabledByPolicy] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[arc::prefs::kVoiceInteractionEnabled] = (*s_whitelist)[arc::prefs::kVoiceInteractionEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN; settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[arc::prefs::kVoiceInteractionContextEnabled] = (*s_whitelist)[arc::prefs::kVoiceInteractionContextEnabled] =
......
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
class="first primary-toggle" class="first primary-toggle"
pref="{{prefs.settings.voice_interaction.enabled}}" pref="{{prefs.settings.voice_interaction.enabled}}"
label="[[getAssistantOnOffLabel_( label="[[getAssistantOnOffLabel_(
prefs.settings.voice_interaction.enabled.value)]]"> prefs.settings.voice_interaction.enabled.value)]]"
disabled="{{prefs.settings.assistant.disabled_by_policy.value}}">
</settings-toggle-button> </settings-toggle-button>
<template is="dom-if" <template is="dom-if"
if="[[prefs.settings.voice_interaction.enabled.value]]"> if="[[prefs.settings.voice_interaction.enabled.value]]">
......
...@@ -113,6 +113,7 @@ Polymer({ ...@@ -113,6 +113,7 @@ Polymer({
'onPrefsChanged_(prefs.settings.voice_interaction.hotword.always_on.value)', 'onPrefsChanged_(prefs.settings.voice_interaction.hotword.always_on.value)',
`onPrefsChanged_( `onPrefsChanged_(
prefs.settings.voice_interaction.activity_control.consent_status.value)`, prefs.settings.voice_interaction.activity_control.consent_status.value)`,
'onPrefsChanged_(prefs.settings.assistant.disabled_by_policy.value)',
], ],
/** @private {?settings.GoogleAssistantBrowserProxy} */ /** @private {?settings.GoogleAssistantBrowserProxy} */
...@@ -187,6 +188,11 @@ Polymer({ ...@@ -187,6 +188,11 @@ Polymer({
/** @private */ /** @private */
onPrefsChanged_: function() { onPrefsChanged_: function() {
if (this.getPref('settings.assistant.disabled_by_policy.value')) {
this.setPrefValue('settings.voice_interaction.enabled', false);
return;
}
this.refreshDspHotwordState_(); this.refreshDspHotwordState_();
this.shouldShowVoiceMatchSettings_ = this.shouldShowVoiceMatchSettings_ =
......
...@@ -12,13 +12,19 @@ ...@@ -12,13 +12,19 @@
namespace assistant { namespace assistant {
namespace prefs { namespace prefs {
// A preference that indicates the user has accepted activity control.
const char kAssistantConsentStatus[] = const char kAssistantConsentStatus[] =
"settings.voice_interaction.activity_control.consent_status"; "settings.voice_interaction.activity_control.consent_status";
// A preference that indicates the Assistant has been disabled by domain policy.
// If true, the Assistant will always been disabled and user cannot enable it.
const char kAssistantDisabledByPolicy[] =
"settings.assistant.disabled_by_policy";
void RegisterProfilePrefs(PrefRegistrySimple* registry) { void RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterIntegerPref( registry->RegisterIntegerPref(
kAssistantConsentStatus, kAssistantConsentStatus,
static_cast<int>(ash::mojom::ConsentStatus::kUnknown)); static_cast<int>(ash::mojom::ConsentStatus::kUnknown));
registry->RegisterBooleanPref(kAssistantDisabledByPolicy, false);
} }
ash::mojom::ConsentStatus GetConsentStatus(PrefService* pref_service) { ash::mojom::ConsentStatus GetConsentStatus(PrefService* pref_service) {
......
...@@ -14,6 +14,7 @@ namespace assistant { ...@@ -14,6 +14,7 @@ namespace assistant {
namespace prefs { namespace prefs {
extern const char kAssistantConsentStatus[]; extern const char kAssistantConsentStatus[];
extern const char kAssistantDisabledByPolicy[];
// Registers Assistant specific profile preferences. // Registers Assistant specific profile preferences.
void RegisterProfilePrefs(PrefRegistrySimple* registry); void RegisterProfilePrefs(PrefRegistrySimple* registry);
......
...@@ -207,8 +207,15 @@ void AssistantOptInFlowScreenHandler::OnSpeakerIdEnrollmentFailure() { ...@@ -207,8 +207,15 @@ void AssistantOptInFlowScreenHandler::OnSpeakerIdEnrollmentFailure() {
} }
void AssistantOptInFlowScreenHandler::SetupAssistantConnection() { void AssistantOptInFlowScreenHandler::SetupAssistantConnection() {
// Make sure enable Assistant service since we need it during the flow.
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
// If Assistant is disabled by domain admin, end the flow.
if (prefs->GetBoolean(::assistant::prefs::kAssistantDisabledByPolicy)) {
HandleFlowFinished();
return;
}
// Make sure enable Assistant service since we need it during the flow.
prefs->SetBoolean(arc::prefs::kVoiceInteractionEnabled, true); prefs->SetBoolean(arc::prefs::kVoiceInteractionEnabled, true);
if (arc::VoiceInteractionControllerClient::Get()->voice_interaction_state() == if (arc::VoiceInteractionControllerClient::Get()->voice_interaction_state() ==
...@@ -329,10 +336,19 @@ void AssistantOptInFlowScreenHandler::OnGetSettingsResponse( ...@@ -329,10 +336,19 @@ void AssistantOptInFlowScreenHandler::OnGetSettingsResponse(
if (settings_ui.has_gaia_user_context_ui()) { if (settings_ui.has_gaia_user_context_ui()) {
auto gaia_user_context_ui = settings_ui.gaia_user_context_ui(); auto gaia_user_context_ui = settings_ui.gaia_user_context_ui();
if (gaia_user_context_ui.waa_disabled_by_dasher_domain() || if (gaia_user_context_ui.assistant_disabled_by_dasher_domain()) {
gaia_user_context_ui.assistant_disabled_by_dasher_domain()) { DVLOG(1) << "Assistant is disabled by domain policy. Skip Assistant "
DVLOG(1) << "Assistant/web & app activity is disabled by dasher domain. " "opt-in flow.";
"Skip Assistant opt-in flow."; PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
prefs->SetBoolean(::assistant::prefs::kAssistantDisabledByPolicy, true);
prefs->SetBoolean(arc::prefs::kVoiceInteractionEnabled, false);
HandleFlowFinished();
return;
}
if (gaia_user_context_ui.waa_disabled_by_dasher_domain()) {
DVLOG(1) << "Web & app activity is disabled by domain policy. Skip "
"Assistant opt-in flow.";
HandleFlowFinished(); HandleFlowFinished();
return; return;
} }
...@@ -579,6 +595,12 @@ void AssistantOptInFlowScreenHandler::HandleFlowFinished() { ...@@ -579,6 +595,12 @@ void AssistantOptInFlowScreenHandler::HandleFlowFinished() {
void AssistantOptInFlowScreenHandler::HandleFlowInitialized( void AssistantOptInFlowScreenHandler::HandleFlowInitialized(
const int flow_type) { const int flow_type) {
auto* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
if (!prefs->GetBoolean(arc::prefs::kVoiceInteractionEnabled)) {
HandleFlowFinished();
return;
}
initialized_ = true; initialized_ = true;
if (on_initialized_) if (on_initialized_)
......
...@@ -323,6 +323,25 @@ suite('GoogleAssistantHandler', function() { ...@@ -323,6 +323,25 @@ suite('GoogleAssistantHandler', function() {
assertTrue(!!dropdown); assertTrue(!!dropdown);
assertTrue(dropdown.hasAttribute('hidden')); assertTrue(dropdown.hasAttribute('hidden'));
}); });
test('assistantDisabledByPolicy', function() {
let button = page.$$('#google-assistant-enable');
assertTrue(!!button);
assertFalse(button.disabled);
assertFalse(button.checked);
page.setPrefValue('settings.voice_interaction.enabled', true);
Polymer.dom.flush();
button = page.$$('#google-assistant-enable');
assertTrue(!!button);
assertFalse(button.disabled);
assertTrue(button.checked);
page.setPrefValue('settings.assistant.disabled_by_policy', true);
Polymer.dom.flush();
assertTrue(!!button);
assertTrue(button.disabled);
assertFalse(button.checked);
});
}); });
suite('GoogleAssistantHandlerWihtNoDspHotword', function() { suite('GoogleAssistantHandlerWihtNoDspHotword', function() {
......
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