Commit 5bd01444 authored by muyuanli's avatar muyuanli Committed by Commit Bot

add voice interaction preference.

There should be 3 states for voice interaction
preferences: undefined, enabled, disabled. It
starts at undefined and will do a one-time-only
fetch from Android to incorporate OOBE settings.
Then the switches are managed by Chrome completely.

BUG=b:38175284

Review-Url: https://codereview.chromium.org/2968073002
Cr-Commit-Position: refs/heads/master@{#487633}
parent 504ac1c3
...@@ -173,6 +173,9 @@ void ArcSessionManager::RegisterProfilePrefs( ...@@ -173,6 +173,9 @@ void ArcSessionManager::RegisterProfilePrefs(
registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false); registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false);
registry->RegisterBooleanPref(prefs::kArcVoiceInteractionValuePropAccepted, registry->RegisterBooleanPref(prefs::kArcVoiceInteractionValuePropAccepted,
false); false);
registry->RegisterBooleanPref(prefs::kVoiceInteractionEnabled, false);
registry->RegisterBooleanPref(prefs::kVoiceInteractionContextEnabled, false);
registry->RegisterBooleanPref(prefs::kVoiceInteractionPrefSynced, false);
// Note that ArcBackupRestoreEnabled and ArcLocationServiceEnabled prefs have // Note that ArcBackupRestoreEnabled and ArcLocationServiceEnabled prefs have
// to be off by default, until an explicit gesture from the user to enable // to be off by default, until an explicit gesture from the user to enable
// them is received. This is crucial in the cases when these prefs transition // them is received. This is crucial in the cases when these prefs transition
......
...@@ -191,6 +191,8 @@ void ArcVoiceInteractionArcHomeService::OnVoiceInteractionOobeSetupComplete() { ...@@ -191,6 +191,8 @@ void ArcVoiceInteractionArcHomeService::OnVoiceInteractionOobeSetupComplete() {
if (pai_starter) if (pai_starter)
pai_starter->ReleaseLock(); pai_starter->ReleaseLock();
chromeos::first_run::MaybeLaunchDialogImmediately(); chromeos::first_run::MaybeLaunchDialogImmediately();
arc::ArcVoiceInteractionFrameworkService::GetForBrowserContext(context_)
->UpdateVoiceInteractionPrefs();
} }
// static // static
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
...@@ -190,6 +191,15 @@ class ArcVoiceInteractionFrameworkServiceFactory ...@@ -190,6 +191,15 @@ class ArcVoiceInteractionFrameworkServiceFactory
} }
}; };
void SetVoiceInteractionPrefs(mojom::VoiceInteractionStatusPtr status) {
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
prefs->SetBoolean(prefs::kVoiceInteractionPrefSynced, status->configured);
prefs->SetBoolean(prefs::kVoiceInteractionEnabled,
status->configured && status->voice_interaction_enabled);
prefs->SetBoolean(prefs::kVoiceInteractionContextEnabled,
status->configured && status->context_enabled);
}
} // namespace } // namespace
// static // static
...@@ -209,6 +219,7 @@ ArcVoiceInteractionFrameworkService::ArcVoiceInteractionFrameworkService( ...@@ -209,6 +219,7 @@ ArcVoiceInteractionFrameworkService::ArcVoiceInteractionFrameworkService(
ArcBridgeService* bridge_service) ArcBridgeService* bridge_service)
: context_(context), arc_bridge_service_(bridge_service), binding_(this) { : context_(context), arc_bridge_service_(bridge_service), binding_(this) {
arc_bridge_service_->voice_interaction_framework()->AddObserver(this); arc_bridge_service_->voice_interaction_framework()->AddObserver(this);
ArcSessionManager::Get()->AddObserver(this);
} }
ArcVoiceInteractionFrameworkService::~ArcVoiceInteractionFrameworkService() { ArcVoiceInteractionFrameworkService::~ArcVoiceInteractionFrameworkService() {
...@@ -218,6 +229,8 @@ ArcVoiceInteractionFrameworkService::~ArcVoiceInteractionFrameworkService() { ...@@ -218,6 +229,8 @@ ArcVoiceInteractionFrameworkService::~ArcVoiceInteractionFrameworkService() {
// so do not touch it. // so do not touch it.
if (ArcServiceManager::Get()) if (ArcServiceManager::Get())
arc_bridge_service_->voice_interaction_framework()->RemoveObserver(this); arc_bridge_service_->voice_interaction_framework()->RemoveObserver(this);
ArcSessionManager::Get()->RemoveObserver(this);
ArcSessionManager::Get()->AddObserver(this);
} }
void ArcVoiceInteractionFrameworkService::OnInstanceReady() { void ArcVoiceInteractionFrameworkService::OnInstanceReady() {
...@@ -370,6 +383,18 @@ void ArcVoiceInteractionFrameworkService::HideMetalayer() { ...@@ -370,6 +383,18 @@ void ArcVoiceInteractionFrameworkService::HideMetalayer() {
SetMetalayerVisibility(false); SetMetalayerVisibility(false);
} }
void ArcVoiceInteractionFrameworkService::OnArcPlayStoreEnabledChanged(
bool enabled) {
if (enabled)
return;
mojom::VoiceInteractionStatusPtr status =
mojom::VoiceInteractionStatus::New();
status->configured = false;
status->voice_interaction_enabled = false;
status->context_enabled = false;
SetVoiceInteractionPrefs(std::move(status));
}
void ArcVoiceInteractionFrameworkService::StartVoiceInteractionSetupWizard() { void ArcVoiceInteractionFrameworkService::StartVoiceInteractionSetupWizard() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arc::mojom::VoiceInteractionFrameworkInstance* framework_instance = arc::mojom::VoiceInteractionFrameworkInstance* framework_instance =
...@@ -428,6 +453,21 @@ void ArcVoiceInteractionFrameworkService::SetVoiceInteractionContextEnabled( ...@@ -428,6 +453,21 @@ void ArcVoiceInteractionFrameworkService::SetVoiceInteractionContextEnabled(
framework_instance->SetVoiceInteractionContextEnabled(enable); framework_instance->SetVoiceInteractionContextEnabled(enable);
} }
void ArcVoiceInteractionFrameworkService::UpdateVoiceInteractionPrefs() {
if (ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean(
prefs::kVoiceInteractionPrefSynced)) {
return;
}
mojom::VoiceInteractionFrameworkInstance* framework_instance =
ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->voice_interaction_framework(),
GetVoiceInteractionSettings);
if (!framework_instance)
return;
framework_instance->GetVoiceInteractionSettings(
base::Bind(&SetVoiceInteractionPrefs));
}
void ArcVoiceInteractionFrameworkService::StartSessionFromUserInteraction( void ArcVoiceInteractionFrameworkService::StartSessionFromUserInteraction(
const gfx::Rect& rect) { const gfx::Rect& rect) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h"
#include "components/arc/arc_service.h"
#include "components/arc/common/voice_interaction_framework.mojom.h" #include "components/arc/common/voice_interaction_framework.mojom.h"
#include "components/arc/instance_holder.h" #include "components/arc/instance_holder.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
...@@ -38,8 +40,8 @@ class ArcVoiceInteractionFrameworkService ...@@ -38,8 +40,8 @@ class ArcVoiceInteractionFrameworkService
public mojom::VoiceInteractionFrameworkHost, public mojom::VoiceInteractionFrameworkHost,
public ui::AcceleratorTarget, public ui::AcceleratorTarget,
public ui::EventHandler, public ui::EventHandler,
public InstanceHolder< public InstanceHolder<mojom::VoiceInteractionFrameworkInstance>::Observer,
mojom::VoiceInteractionFrameworkInstance>::Observer { public ArcSessionManager::Observer {
public: public:
// Returns singleton instance for the given BrowserContext, // Returns singleton instance for the given BrowserContext,
// or nullptr if the browser |context| is not allowed to use ARC. // or nullptr if the browser |context| is not allowed to use ARC.
...@@ -76,6 +78,9 @@ class ArcVoiceInteractionFrameworkService ...@@ -76,6 +78,9 @@ class ArcVoiceInteractionFrameworkService
void ShowMetalayer(const base::Closure& closed); void ShowMetalayer(const base::Closure& closed);
void HideMetalayer(); void HideMetalayer();
// ArcSessionManager::Observer overrides.
void OnArcPlayStoreEnabledChanged(bool enabled) override;
// Starts a voice interaction session after user-initiated interaction. // Starts a voice interaction session after user-initiated interaction.
// Records a timestamp and sets number of allowed requests to 2 since by // Records a timestamp and sets number of allowed requests to 2 since by
// design, there will be one request for screenshot and the other for // design, there will be one request for screenshot and the other for
...@@ -102,6 +107,13 @@ class ArcVoiceInteractionFrameworkService ...@@ -102,6 +107,13 @@ class ArcVoiceInteractionFrameworkService
// Start the voice interaction setup wizard in container. // Start the voice interaction setup wizard in container.
void StartVoiceInteractionSetupWizard(); void StartVoiceInteractionSetupWizard();
// Updates voice interaction flags. These flags are set only once when ARC
// container is enabled.
void UpdateVoiceInteractionPrefs();
// For supporting ArcServiceManager::GetService<T>().
static const char kArcServiceName[];
private: private:
void SetMetalayerVisibility(bool visible); void SetMetalayerVisibility(bool visible);
......
...@@ -63,6 +63,11 @@ const char kVoiceInteractionEnabled[] = "settings.voice_interaction.enabled"; ...@@ -63,6 +63,11 @@ const char kVoiceInteractionEnabled[] = "settings.voice_interaction.enabled";
// voice interaction services. // voice interaction services.
const char kVoiceInteractionContextEnabled[] = const char kVoiceInteractionContextEnabled[] =
"settings.voice_interaction.context.enabled"; "settings.voice_interaction.context.enabled";
// A preference indicating whether voice interaction settings have been read
// from ARC. This synchronization only happens when user goes through the flow
// to set up voice interaction.
const char kVoiceInteractionPrefSynced[] =
"settings.voice_interaction.context.synced";
#endif #endif
// A bool pref that keeps whether the child status for this profile was already // A bool pref that keeps whether the child status for this profile was already
......
...@@ -36,6 +36,7 @@ extern const char kArcCompatibleFilesystemChosen[]; ...@@ -36,6 +36,7 @@ extern const char kArcCompatibleFilesystemChosen[];
extern const char kArcVoiceInteractionValuePropAccepted[]; extern const char kArcVoiceInteractionValuePropAccepted[];
extern const char kVoiceInteractionEnabled[]; extern const char kVoiceInteractionEnabled[];
extern const char kVoiceInteractionContextEnabled[]; extern const char kVoiceInteractionContextEnabled[];
extern const char kVoiceInteractionPrefSynced[];
#endif #endif
extern const char kChildAccountStatusKnown[]; extern const char kChildAccountStatusKnown[];
extern const char kDefaultApps[]; extern const char kDefaultApps[];
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// Next MinVersion: 7 // Next MinVersion: 8
module arc.mojom; module arc.mojom;
...@@ -30,8 +30,20 @@ interface VoiceInteractionFrameworkHost { ...@@ -30,8 +30,20 @@ interface VoiceInteractionFrameworkHost {
[MinVersion=6]SetVoiceInteractionRunning@4(bool running); [MinVersion=6]SetVoiceInteractionRunning@4(bool running);
}; };
// Indicates voice interaction configuration status.
struct VoiceInteractionStatus {
// Whether voice interaction is configured during OOBE flow. |false| if
// OOBE flow has been skipped.
bool configured;
// Whether voice interaction service is enabled.
bool voice_interaction_enabled;
// Whether allow voice interaction service to request screenshot
// and screen context.
bool context_enabled;
};
// Connects with Android system server. // Connects with Android system server.
// Next method ID: 7 // Next method ID: 8
interface VoiceInteractionFrameworkInstance { interface VoiceInteractionFrameworkInstance {
Init@0(VoiceInteractionFrameworkHost host_ptr); Init@0(VoiceInteractionFrameworkHost host_ptr);
...@@ -55,4 +67,8 @@ interface VoiceInteractionFrameworkInstance { ...@@ -55,4 +67,8 @@ interface VoiceInteractionFrameworkInstance {
// Starts the voice interaction setup wizard in container. // Starts the voice interaction setup wizard in container.
[MinVersion=5] StartVoiceInteractionSetupWizard@6(); [MinVersion=5] StartVoiceInteractionSetupWizard@6();
// Queries voice interaction settings status.
[MinVersion=7] GetVoiceInteractionSettings@7() =>
(VoiceInteractionStatus status);
}; };
\ No newline at end of file
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