Commit c1710c99 authored by Alexander Alekseev's avatar Alexander Alekseev Committed by Commit Bot

Chrome OS OOBE: Play startup sound only when sound device is present.

This CL delays startup sound playback until default sound output device
has known type.

Bug: 848485
Change-Id: I911e37afd34d28f142c46ef63b7b6345988d159b
Reviewed-on: https://chromium-review.googlesource.com/1160143Reviewed-by: default avatarJenny Zhang <jennyz@chromium.org>
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580648}
parent 4f763482
......@@ -348,6 +348,23 @@ class CloseAfterCommit : public ui::CompositorObserver,
DISALLOW_COPY_AND_ASSIGN(CloseAfterCommit);
};
// Returns true if we have default audio device.
bool CanPlayStartupSound() {
chromeos::AudioDevice device;
bool found =
chromeos::CrasAudioHandler::Get()->GetPrimaryActiveOutputDevice(&device);
return found && device.stable_device_id_version &&
device.type != chromeos::AudioDeviceType::AUDIO_TYPE_OTHER;
}
// Returns true if it is too late to play startup sound.
bool StartupSoundOutdated(base::TimeTicks login_prompt_visible_time) {
// Don't try to play startup sound if login prompt has been already visible
// for a long time.
return base::TimeTicks::Now() - login_prompt_visible_time >
base::TimeDelta::FromMilliseconds(kStartupSoundMaxDelayMs);
}
} // namespace
namespace chromeos {
......@@ -851,7 +868,7 @@ void LoginDisplayHostWebUI::EmitLoginPromptVisibleCalled() {
// LoginDisplayHostWebUI, chromeos::CrasAudioHandler::AudioObserver:
void LoginDisplayHostWebUI::OnActiveOutputNodeChanged() {
TryToPlayOobeStartupSound();
PlayStartupSoundIfPossible();
}
////////////////////////////////////////////////////////////////////////////////
......@@ -1102,25 +1119,8 @@ void LoginDisplayHostWebUI::SetOobeProgressBarVisible(bool visible) {
}
void LoginDisplayHostWebUI::TryToPlayOobeStartupSound() {
if (is_voice_interaction_oobe_)
return;
if (oobe_startup_sound_played_ || login_prompt_visible_time_.is_null() ||
!CrasAudioHandler::Get()->GetPrimaryActiveOutputNode()) {
return;
}
oobe_startup_sound_played_ = true;
// Don't try play startup sound if login prompt is already visible
// for a long time or can't be played.
if (base::TimeTicks::Now() - login_prompt_visible_time_ >
base::TimeDelta::FromMilliseconds(kStartupSoundMaxDelayMs)) {
return;
}
AccessibilityManager::Get()->PlayEarcon(SOUND_STARTUP,
PlaySoundOption::ALWAYS);
need_to_play_startup_sound_ = true;
PlayStartupSoundIfPossible();
}
void LoginDisplayHostWebUI::OnLoginPromptVisible() {
......@@ -1193,6 +1193,26 @@ void LoginDisplayHostWebUI::UpdateAddUserButtonStatus() {
NOTREACHED();
}
void LoginDisplayHostWebUI::PlayStartupSoundIfPossible() {
if (!need_to_play_startup_sound_ || oobe_startup_sound_played_)
return;
if (login_prompt_visible_time_.is_null())
return;
if (is_voice_interaction_oobe_ || !CanPlayStartupSound())
return;
need_to_play_startup_sound_ = false;
oobe_startup_sound_played_ = true;
if (StartupSoundOutdated(login_prompt_visible_time_))
return;
AccessibilityManager::Get()->PlayEarcon(SOUND_STARTUP,
PlaySoundOption::ALWAYS);
}
////////////////////////////////////////////////////////////////////////////////
// external
......
......@@ -185,6 +185,9 @@ class LoginDisplayHostWebUI : public LoginDisplayHostCommon,
// Creates or recreates |existing_user_controller_|.
void CreateExistingUserController();
// Plays startup sound if needed and audio device is ready.
void PlayStartupSoundIfPossible();
// Sign in screen controller.
std::unique_ptr<ExistingUserController> existing_user_controller_;
......@@ -259,6 +262,9 @@ class LoginDisplayHostWebUI : public LoginDisplayHostCommon,
bool is_voice_interaction_oobe_ = false;
// True if we need to play startup sound when audio device becomes available.
bool need_to_play_startup_sound_ = false;
base::WeakPtrFactory<LoginDisplayHostWebUI> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostWebUI);
......
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