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(
registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false);
registry->RegisterBooleanPref(prefs::kArcVoiceInteractionValuePropAccepted,
false);
registry->RegisterBooleanPref(prefs::kVoiceInteractionEnabled, false);
registry->RegisterBooleanPref(prefs::kVoiceInteractionContextEnabled, false);
registry->RegisterBooleanPref(prefs::kVoiceInteractionPrefSynced, false);
// Note that ArcBackupRestoreEnabled and ArcLocationServiceEnabled prefs have
// 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
......
......@@ -191,6 +191,8 @@ void ArcVoiceInteractionArcHomeService::OnVoiceInteractionOobeSetupComplete() {
if (pai_starter)
pai_starter->ReleaseLock();
chromeos::first_run::MaybeLaunchDialogImmediately();
arc::ArcVoiceInteractionFrameworkService::GetForBrowserContext(context_)
->UpdateVoiceInteractionPrefs();
}
// static
......
......@@ -24,6 +24,7 @@
#include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_impl.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_list.h"
#include "chrome/browser/ui/browser_window.h"
......@@ -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
// static
......@@ -209,6 +219,7 @@ ArcVoiceInteractionFrameworkService::ArcVoiceInteractionFrameworkService(
ArcBridgeService* bridge_service)
: context_(context), arc_bridge_service_(bridge_service), binding_(this) {
arc_bridge_service_->voice_interaction_framework()->AddObserver(this);
ArcSessionManager::Get()->AddObserver(this);
}
ArcVoiceInteractionFrameworkService::~ArcVoiceInteractionFrameworkService() {
......@@ -218,6 +229,8 @@ ArcVoiceInteractionFrameworkService::~ArcVoiceInteractionFrameworkService() {
// so do not touch it.
if (ArcServiceManager::Get())
arc_bridge_service_->voice_interaction_framework()->RemoveObserver(this);
ArcSessionManager::Get()->RemoveObserver(this);
ArcSessionManager::Get()->AddObserver(this);
}
void ArcVoiceInteractionFrameworkService::OnInstanceReady() {
......@@ -370,6 +383,18 @@ void ArcVoiceInteractionFrameworkService::HideMetalayer() {
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() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arc::mojom::VoiceInteractionFrameworkInstance* framework_instance =
......@@ -428,6 +453,21 @@ void ArcVoiceInteractionFrameworkService::SetVoiceInteractionContextEnabled(
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(
const gfx::Rect& rect) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
......
......@@ -9,6 +9,8 @@
#include "base/macros.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/instance_holder.h"
#include "components/keyed_service/core/keyed_service.h"
......@@ -38,8 +40,8 @@ class ArcVoiceInteractionFrameworkService
public mojom::VoiceInteractionFrameworkHost,
public ui::AcceleratorTarget,
public ui::EventHandler,
public InstanceHolder<
mojom::VoiceInteractionFrameworkInstance>::Observer {
public InstanceHolder<mojom::VoiceInteractionFrameworkInstance>::Observer,
public ArcSessionManager::Observer {
public:
// Returns singleton instance for the given BrowserContext,
// or nullptr if the browser |context| is not allowed to use ARC.
......@@ -76,6 +78,9 @@ class ArcVoiceInteractionFrameworkService
void ShowMetalayer(const base::Closure& closed);
void HideMetalayer();
// ArcSessionManager::Observer overrides.
void OnArcPlayStoreEnabledChanged(bool enabled) override;
// Starts a voice interaction session after user-initiated interaction.
// 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
......@@ -102,6 +107,13 @@ class ArcVoiceInteractionFrameworkService
// Start the voice interaction setup wizard in container.
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:
void SetMetalayerVisibility(bool visible);
......
......@@ -63,6 +63,11 @@ const char kVoiceInteractionEnabled[] = "settings.voice_interaction.enabled";
// voice interaction services.
const char kVoiceInteractionContextEnabled[] =
"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
// A bool pref that keeps whether the child status for this profile was already
......
......@@ -36,6 +36,7 @@ extern const char kArcCompatibleFilesystemChosen[];
extern const char kArcVoiceInteractionValuePropAccepted[];
extern const char kVoiceInteractionEnabled[];
extern const char kVoiceInteractionContextEnabled[];
extern const char kVoiceInteractionPrefSynced[];
#endif
extern const char kChildAccountStatusKnown[];
extern const char kDefaultApps[];
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Next MinVersion: 7
// Next MinVersion: 8
module arc.mojom;
......@@ -30,8 +30,20 @@ interface VoiceInteractionFrameworkHost {
[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.
// Next method ID: 7
// Next method ID: 8
interface VoiceInteractionFrameworkInstance {
Init@0(VoiceInteractionFrameworkHost host_ptr);
......@@ -55,4 +67,8 @@ interface VoiceInteractionFrameworkInstance {
// Starts the voice interaction setup wizard in container.
[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