Skip to content

Commit e22ebe5

Browse files
author
Yue Li
committed
Hook up Assistant Voice Match screen
Bug: b/116166191 Test: Manual Test Change-Id: I5611a49d124f75ff535724224594e3f098ed31be Reviewed-on: https://chromium-review.googlesource.com/c/1355520 Reviewed-by: Xiyuan Xia <xiyuan@chromium.org> Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org> Commit-Queue: Yue Li <updowndota@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#613649}(cherry picked from commit b027ce5) Reviewed-on: https://chromium-review.googlesource.com/c/1362478 Reviewed-by: Yue Li <updowndota@chromium.org> Cr-Commit-Position: refs/branch-heads/3626@{#55} Cr-Branched-From: d897fb1-refs/heads/master@{#612437}
1 parent 0d1870b commit e22ebe5

File tree

10 files changed

+216
-58
lines changed

10 files changed

+216
-58
lines changed

chrome/browser/resources/chromeos/assistant_optin/assistant_get_more.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ Polymer({
4646
*/
4747
screenShown_: false,
4848

49+
/**
50+
* Whether the voice match feature has been enabled.
51+
* @type {boolean}
52+
* @private
53+
*/
54+
voiceMatchFeatureEnabled_: false,
55+
4956
/**
5057
* On-tap event handler for next button.
5158
*
@@ -56,13 +63,17 @@ Polymer({
5663
return;
5764
}
5865
this.buttonsDisabled = true;
59-
var hotword = this.$$('#toggle0').hasAttribute('checked');
60-
var screenContext = this.$$('#toggle1').hasAttribute('checked');
61-
var toggle2 = this.$$('#toggle2');
62-
var emailOptedIn = toggle2 != null && toggle2.hasAttribute('checked');
66+
67+
if (!this.voiceMatchFeatureEnabled_) {
68+
var hotword = this.$$('#toggle-hotword').hasAttribute('checked');
69+
chrome.send('login.AssistantOptInFlowScreen.hotwordResult', [hotword]);
70+
}
71+
var screenContext = this.$$('#toggle-context').hasAttribute('checked');
72+
var toggleEmail = this.$$('#toggle-email');
73+
var emailOptedIn =
74+
toggleEmail != null && toggleEmail.hasAttribute('checked');
6375

6476
// TODO(updowndota): Wrap chrome.send() calls with a proxy object.
65-
chrome.send('login.AssistantOptInFlowScreen.hotwordResult', [hotword]);
6677
chrome.send(
6778
'login.AssistantOptInFlowScreen.GetMoreScreen.userActed',
6879
[screenContext, emailOptedIn]);
@@ -83,6 +94,7 @@ Polymer({
8394
this.$['title-text'].textContent = data['getMoreTitle'];
8495
this.$['intro-text'].textContent = data['getMoreIntro'];
8596
this.$['next-button-text'].textContent = data['getMoreContinueButton'];
97+
this.voiceMatchFeatureEnabled_ = data['voiceMatchFeatureEnabled'];
8698

8799
this.consentStringLoaded_ = true;
88100
if (this.settingZippyLoaded_) {
@@ -103,15 +115,15 @@ Polymer({
103115
'data:text/html;charset=utf-8,' +
104116
encodeURIComponent(zippy.getWrappedIcon(data['iconUri'])));
105117
zippy.setAttribute('toggle-style', true);
106-
zippy.id = 'zippy' + i;
118+
zippy.id = 'zippy-' + data['id'];
107119
var title = document.createElement('div');
108120
title.className = 'zippy-title';
109121
title.textContent = data['title'];
110122
zippy.appendChild(title);
111123

112124
var toggle = document.createElement('cr-toggle');
113125
toggle.className = 'zippy-toggle';
114-
toggle.id = 'toggle' + i;
126+
toggle.id = 'toggle-' + data['id'];
115127
if (data['defaultEnabled']) {
116128
toggle.setAttribute('checked', '');
117129
}

chrome/browser/resources/chromeos/assistant_optin/assistant_optin_flow.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ Polymer({
4242
* @param {!Object} data New dictionary with i18n values.
4343
*/
4444
reloadContent: function(data) {
45-
// Reload global local strings, process DOM tree again.
46-
loadTimeData.overrideValues(data);
47-
i18nTemplate.process(document, loadTimeData);
45+
this.voiceMatchFeatureEnabled = data['voiceMatchFeatureEnabled'];
4846
this.$['value-prop'].reloadContent(data);
4947
this.$['third-party'].reloadContent(data);
5048
this.$['get-more'].reloadContent(data);
@@ -80,7 +78,11 @@ Polymer({
8078
this.showScreen(this.$['third-party']);
8179
break;
8280
case this.$['third-party']:
83-
this.showScreen(this.$['voice-match']);
81+
if (this.voiceMatchFeatureEnabled) {
82+
this.showScreen(this.$['voice-match']);
83+
} else {
84+
this.showScreen(this.$['get-more']);
85+
}
8486
break;
8587
case this.$['voice-match']:
8688
this.showScreen(this.$['get-more']);

chrome/browser/resources/chromeos/assistant_optin/assistant_voice_match.css

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424
padding: 0 8px 0 8px;
2525
}
2626

27-
.intro #recording-container,
28-
.recording #intro-container,
29-
.completed #intro-container {
30-
position: absolute;
31-
visibility: hidden;
27+
#intro-container,
28+
#recording-container,
29+
#already-setup-container {
30+
display: none;
31+
}
32+
33+
.intro #intro-container,
34+
.recording #recording-container,
35+
.completed #recording-container,
36+
.already-setup #already-setup-container {
37+
display: block;
3238
}
3339

3440
.recording #title-completed,
@@ -37,9 +43,10 @@
3743
}
3844

3945
.intro #skip-button,
40-
.intro #next-button,
46+
.intro #agree-button,
4147
.recording #later-button,
42-
.completed #done-button {
48+
.completed #done-button,
49+
.already-setup #next-button {
4350
display: block;
4451
}
4552

chrome/browser/resources/chromeos/assistant_optin/assistant_voice_match.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,35 @@
4848
<div class="content" id="footer-text"
4949
i18n-content="assistantVoiceMatchFooter"></div>
5050
</div>
51+
<div id="already-setup-container">
52+
<div class="title" id="title-already-setup"
53+
i18n-content="assistantVoiceMatchAlreadySetupTitle"></div>
54+
<div class="content"
55+
i18n-content="assistantVoiceMatchAlreadySetupMessage"></div>
56+
</div>
5157
</div>
5258
</div>
5359
<div slot="bottom-buttons" class="flex layout horizontal">
5460
<div class="flex"></div>
5561
<oobe-text-button id="skip-button" on-tap="onSkipTap_"
5662
disabled="[[buttonsDisabled]]">
57-
<div id="skip-button-text">No thanks</div>
63+
<div i18n-content="assistantOptinNoThanksButton"></div>
5864
</oobe-text-button>
5965
<oobe-text-button id="later-button" on-tap="onSkipTap_"
6066
disabled="[[buttonsDisabled]]">
61-
<div id="skip-button-text">Do it later</div>
67+
<div i18n-content="assistantOptinLaterButton"></div>
6268
</oobe-text-button>
63-
<oobe-text-button id="next-button" inverse on-tap="onNextTap_"
69+
<oobe-text-button id="agree-button" inverse on-tap="onAgreeTap_"
6470
disabled="[[buttonsDisabled]]">
65-
<div id="next-button-text">I agree</div>
71+
<div i18n-content="assistantOptinAgreeButton"></div>
6672
</oobe-text-button>
6773
<oobe-text-button id="done-button" inverse on-tap="onDoneTap_"
6874
disabled="[[buttonsDisabled]]">
69-
<div id="done-button-text">Save</div>
75+
<div i18n-content="assistantOptinSaveButton"></div>
76+
</oobe-text-button>
77+
<oobe-text-button id="next-button" inverse on-tap="onDoneTap_"
78+
disabled="[[buttonsDisabled]]">
79+
<div i18n-content="next"></div>
7080
</oobe-text-button>
7181
</div>
7282
</oobe-dialog>

chrome/browser/resources/chromeos/assistant_optin/assistant_voice_match.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ Polymer({
3131
},
3232

3333
/**
34-
* On-tap event handler for next button.
34+
* On-tap event handler for agree button.
3535
*
3636
* @private
3737
*/
38-
onNextTap_: function() {
38+
onAgreeTap_: function() {
3939
this.removeClass_('intro');
4040
this.addClass_('recording');
4141
chrome.send(
@@ -44,7 +44,7 @@ Polymer({
4444
},
4545

4646
/**
47-
* On-tap event handler for next button.
47+
* On-tap event handler for done button.
4848
*
4949
* @private
5050
*/
@@ -107,6 +107,6 @@ Polymer({
107107
* Signal from host to show the screen.
108108
*/
109109
onShow: function() {
110-
this.$['next-button'].focus();
110+
this.$['agree-button'].focus();
111111
},
112112
});

chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_utils.cc

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "chrome/browser/ui/webui/chromeos/user_image_source.h"
1111
#include "chrome/grit/browser_resources.h"
1212
#include "chrome/grit/generated_resources.h"
13+
#include "chromeos/services/assistant/public/features.h"
1314
#include "components/arc/arc_prefs.h"
1415
#include "components/consent_auditor/consent_auditor.h"
1516
#include "components/signin/core/browser/signin_manager_base.h"
@@ -108,23 +109,28 @@ base::Value CreateGetMoreData(bool email_optin_needed,
108109
const assistant::EmailOptInUi& email_optin_ui) {
109110
base::Value get_more_data(base::Value::Type::LIST);
110111

111-
// Process hotword data.
112-
base::Value hotword_data(base::Value::Type::DICTIONARY);
113-
hotword_data.SetKey(
114-
"title",
115-
base::Value(l10n_util::GetStringUTF16(IDS_ASSISTANT_HOTWORD_TITLE)));
116-
hotword_data.SetKey(
117-
"description",
118-
base::Value(l10n_util::GetStringUTF16(IDS_ASSISTANT_HOTWORD_DESC)));
119-
hotword_data.SetKey("defaultEnabled", base::Value(true));
120-
hotword_data.SetKey(
121-
"iconUri",
122-
base::Value("https://www.gstatic.com/images/icons/material/system/"
123-
"2x/mic_none_grey600_48dp.png"));
124-
get_more_data.GetList().push_back(std::move(hotword_data));
112+
if (!base::FeatureList::IsEnabled(
113+
assistant::features::kAssistantVoiceMatch)) {
114+
// Process hotword data.
115+
base::Value hotword_data(base::Value::Type::DICTIONARY);
116+
hotword_data.SetKey("id", base::Value("hotword"));
117+
hotword_data.SetKey(
118+
"title",
119+
base::Value(l10n_util::GetStringUTF16(IDS_ASSISTANT_HOTWORD_TITLE)));
120+
hotword_data.SetKey(
121+
"description",
122+
base::Value(l10n_util::GetStringUTF16(IDS_ASSISTANT_HOTWORD_DESC)));
123+
hotword_data.SetKey("defaultEnabled", base::Value(true));
124+
hotword_data.SetKey(
125+
"iconUri",
126+
base::Value("https://www.gstatic.com/images/icons/material/system/"
127+
"2x/mic_none_grey600_48dp.png"));
128+
get_more_data.GetList().push_back(std::move(hotword_data));
129+
}
125130

126131
// Process screen context data.
127132
base::Value context_data(base::Value::Type::DICTIONARY);
133+
context_data.SetKey("id", base::Value("context"));
128134
context_data.SetKey("title", base::Value(l10n_util::GetStringUTF16(
129135
IDS_ASSISTANT_SCREEN_CONTEXT_TITLE)));
130136
context_data.SetKey("description", base::Value(l10n_util::GetStringUTF16(
@@ -139,6 +145,7 @@ base::Value CreateGetMoreData(bool email_optin_needed,
139145
// Process email optin data.
140146
if (email_optin_needed) {
141147
base::Value data(base::Value::Type::DICTIONARY);
148+
data.SetKey("id", base::Value("email"));
142149
data.SetKey("title", base::Value(email_optin_ui.title()));
143150
data.SetKey("description", base::Value(email_optin_ui.description()));
144151
data.SetKey("defaultEnabled",

chrome/browser/ui/webui/chromeos/login/assistant_optin_flow_screen_handler.cc

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ void AssistantOptInFlowScreenHandler::DeclareLocalizedValues(
7979
IDS_ASSISTANT_VOICE_MATCH_COMPLETE);
8080
builder->Add("assistantVoiceMatchUploading",
8181
IDS_ASSISTANT_VOICE_MATCH_UPLOADING);
82+
builder->Add("assistantVoiceMatchAlreadySetupTitle",
83+
IDS_ASSISTANT_VOICE_MATCH_ALREADY_SETUP_TITLE);
84+
builder->Add("assistantVoiceMatchAlreadySetupMessage",
85+
IDS_ASSISTANT_VOICE_MATCH_ALREADY_SETUP_MESSAGE);
8286
builder->Add("assistantOptinOKButton", IDS_OOBE_OK_BUTTON_TEXT);
87+
builder->Add("assistantOptinNoThanksButton", IDS_ASSISTANT_NO_THANKS_BUTTON);
88+
builder->Add("assistantOptinLaterButton", IDS_ASSISTANT_LATER_BUTTON);
89+
builder->Add("assistantOptinAgreeButton", IDS_ASSISTANT_AGREE_BUTTON);
90+
builder->Add("assistantOptinSaveButton", IDS_ASSISTANT_SAVE_BUTTON);
91+
builder->Add("assistantOptinWaitMessage", IDS_ASSISTANT_WAIT_MESSAGE);
8392
builder->Add("assistantReadyTitle", IDS_ASSISTANT_READY_SCREEN_TITLE);
8493
builder->Add("assistantReadyMessage", IDS_ASSISTANT_READY_SCREEN_MESSAGE);
8594
builder->Add("assistantReadyButton", IDS_ASSISTANT_DONE_BUTTON);
@@ -166,6 +175,7 @@ void AssistantOptInFlowScreenHandler::OnProcessingHotword() {
166175
}
167176

168177
void AssistantOptInFlowScreenHandler::OnSpeakerIdEnrollmentDone() {
178+
settings_manager_->StopSpeakerIdEnrollment(base::DoNothing());
169179
CallJSWithPrefix("onVoiceMatchUpdate", base::Value("done"));
170180
}
171181

@@ -227,7 +237,15 @@ void AssistantOptInFlowScreenHandler::OnEmailOptInResult(bool opted_in) {
227237
void AssistantOptInFlowScreenHandler::OnStateChanged(
228238
ash::mojom::VoiceInteractionState state) {
229239
if (state != ash::mojom::VoiceInteractionState::NOT_READY) {
230-
BindAssistantSettingsManager();
240+
if (voice_enrollment_pending) {
241+
voice_enrollment_pending = false;
242+
DCHECK(settings_manager_.is_bound() &&
243+
base::FeatureList::IsEnabled(
244+
assistant::features::kAssistantVoiceMatch));
245+
settings_manager_->StartSpeakerIdEnrollment(true, std::move(client_ptr_));
246+
} else {
247+
BindAssistantSettingsManager();
248+
}
231249
arc::VoiceInteractionControllerClient::Get()->RemoveObserver(this);
232250
}
233251
}
@@ -244,7 +262,9 @@ void AssistantOptInFlowScreenHandler::BindAssistantSettingsManager() {
244262
mojo::MakeRequest(&settings_manager_));
245263
client_binding_.Bind(mojo::MakeRequest(&client_ptr_));
246264

247-
SendGetSettingsRequest();
265+
if (initialized_) {
266+
SendGetSettingsRequest();
267+
}
248268
}
249269

250270
void AssistantOptInFlowScreenHandler::SendGetSettingsRequest() {
@@ -337,7 +357,11 @@ void AssistantOptInFlowScreenHandler::OnGetSettingsResponse(
337357
}
338358

339359
// Pass string constants dictionary.
340-
ReloadContent(GetSettingsUiStrings(settings_ui, activity_control_needed_));
360+
auto dictionary = GetSettingsUiStrings(settings_ui, activity_control_needed_);
361+
dictionary.SetKey("voiceMatchFeatureEnabled",
362+
base::Value(base::FeatureList::IsEnabled(
363+
assistant::features::kAssistantVoiceMatch)));
364+
ReloadContent(dictionary);
341365
}
342366

343367
void AssistantOptInFlowScreenHandler::OnUpdateSettingsResponse(
@@ -395,11 +419,6 @@ void AssistantOptInFlowScreenHandler::HandleThirdPartyScreenUserAction(
395419
if (action == kNextPressed) {
396420
RecordAssistantOptInStatus(THIRD_PARTY_CONTINUED);
397421
ShowNextScreen();
398-
if (!base::FeatureList::IsEnabled(
399-
assistant::features::kAssistantVoiceMatch)) {
400-
// Skip the voice match enrollment if feature is disabled.
401-
ShowNextScreen();
402-
}
403422
}
404423
}
405424

@@ -409,10 +428,24 @@ void AssistantOptInFlowScreenHandler::HandleVoiceMatchScreenUserAction(
409428
assistant::features::kAssistantVoiceMatch)) {
410429
return;
411430
}
412-
if (action == kNextPressed || action == kSkipPressed) {
431+
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
432+
433+
if (action == kNextPressed) {
434+
ShowNextScreen();
435+
} else if (action == kSkipPressed) {
436+
prefs->SetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled, false);
437+
settings_manager_->StopSpeakerIdEnrollment(base::DoNothing());
413438
ShowNextScreen();
414439
} else if (action == kRecordPressed) {
415-
settings_manager_->StartSpeakerIdEnrollment(true, std::move(client_ptr_));
440+
if (!prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled)) {
441+
// Turn on hotword will restart the Assistant service. Thus the enrollment
442+
// request should be sent after the service restart complete.
443+
voice_enrollment_pending = true;
444+
prefs->SetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled, true);
445+
arc::VoiceInteractionControllerClient::Get()->AddObserver(this);
446+
} else {
447+
settings_manager_->StartSpeakerIdEnrollment(true, std::move(client_ptr_));
448+
}
416449
}
417450
}
418451

@@ -475,6 +508,12 @@ void AssistantOptInFlowScreenHandler::HandleFlowFinished() {
475508
CallJSWithPrefix("closeDialog");
476509
}
477510

478-
void AssistantOptInFlowScreenHandler::HandleFlowInitialized() {}
511+
void AssistantOptInFlowScreenHandler::HandleFlowInitialized() {
512+
initialized_ = true;
513+
514+
if (settings_manager_.is_bound()) {
515+
SendGetSettingsRequest();
516+
}
517+
}
479518

480519
} // namespace chromeos

chrome/browser/ui/webui/chromeos/login/assistant_optin_flow_screen_handler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ class AssistantOptInFlowScreenHandler
118118
// Counter for the number of loading timeout happens.
119119
int loading_timeout_counter_ = 0;
120120

121+
// Whether the screen has been initialized.
122+
bool initialized_ = false;
123+
124+
// Whether there is a pending voice match enrollment request.
125+
bool voice_enrollment_pending = false;
126+
121127
mojo::Binding<assistant::mojom::SpeakerIdEnrollmentClient> client_binding_;
122128
assistant::mojom::SpeakerIdEnrollmentClientPtr client_ptr_;
123129
assistant::mojom::AssistantSettingsManagerPtr settings_manager_;

0 commit comments

Comments
 (0)