summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenny Zhang <jennyz@chromium.org>2015-07-29 16:26:16 -0700
committerJenny Zhang <jennyz@chromium.org>2015-07-29 23:27:58 +0000
commitd7ba885a83fd3435d533516872a0aef36f527de8 (patch)
treeddf011d8dba6b09ea37192def07a0f852237b81f
parent30c5650db8d38f6cad3218869a1a6ab71aaf96c1 (diff)
downloadchromium_src-d7ba885a83fd3435d533516872a0aef36f527de8.zip
chromium_src-d7ba885a83fd3435d533516872a0aef36f527de8.tar.gz
chromium_src-d7ba885a83fd3435d533516872a0aef36f527de8.tar.bz2
Fix the UI issue for showing output muted in ash tray after the device wakes up with hdmi output removed.
BUG=512601 TBR=mnissler@chromium.org, derat@chromium.org, rkc@chromium.org Review URL: https://codereview.chromium.org/1262723002 Cr-Commit-Position: refs/heads/master@{#340794} Review URL: https://codereview.chromium.org/1268593002 . Cr-Commit-Position: refs/branch-heads/2454@{#176} Cr-Branched-From: 12bfc3360892ec53cd00fc239a47e5298beb063b-refs/heads/master@{#338390}
-rw-r--r--ash/system/audio/audio_observer.h7
-rw-r--r--ash/system/audio/tray_audio.cc4
-rw-r--r--ash/system/audio/tray_audio.h2
-rw-r--r--ash/system/tray/system_tray_notifier.cc5
-rw-r--r--ash/system/tray/system_tray_notifier.h2
-rw-r--r--chrome/browser/policy/policy_browsertest.cc3
-rw-r--r--chrome/browser/ui/ash/system_tray_delegate_chromeos.cc5
-rw-r--r--chrome/browser/ui/ash/system_tray_delegate_chromeos.h2
-rw-r--r--chrome/browser/ui/ash/volume_controller_chromeos.cc3
-rw-r--r--chrome/browser/ui/ash/volume_controller_chromeos.h2
-rw-r--r--chromeos/audio/cras_audio_handler.cc17
-rw-r--r--chromeos/audio/cras_audio_handler.h7
-rw-r--r--chromeos/audio/cras_audio_handler_unittest.cc75
-rw-r--r--extensions/browser/api/audio/audio_service_chromeos.cc4
-rw-r--r--extensions/shell/browser/shell_audio_controller_chromeos.cc4
-rw-r--r--extensions/shell/browser/shell_audio_controller_chromeos.h2
16 files changed, 111 insertions, 33 deletions
diff --git a/ash/system/audio/audio_observer.h b/ash/system/audio/audio_observer.h
index 3b94ebc8..7a18e17 100644
--- a/ash/system/audio/audio_observer.h
+++ b/ash/system/audio/audio_observer.h
@@ -19,7 +19,12 @@ class AudioObserver {
virtual void OnOutputNodeVolumeChanged(uint64_t node_id, double volume) = 0;
// Called when output mute state changed.
- virtual void OnOutputMuteChanged(bool mute_on) = 0;
+ // |mute_on|: True if output is muted.
+ // |system_adjust|: True if the mute state is adjusted by the system
+ // automatically, UI should be consistent with the system's mute state,
+ // but it should not be too loud, e.g., the volume pop up window should not
+ // be triggered.
+ virtual void OnOutputMuteChanged(bool mute_on, bool system_adjust) = 0;
// Called when audio nodes changed.
virtual void OnAudioNodesChanged() = 0;
diff --git a/ash/system/audio/tray_audio.cc b/ash/system/audio/tray_audio.cc
index 13269bc..c3efc29 100644
--- a/ash/system/audio/tray_audio.cc
+++ b/ash/system/audio/tray_audio.cc
@@ -113,14 +113,14 @@ void TrayAudio::OnOutputNodeVolumeChanged(uint64_t /* node_id */,
PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false);
}
-void TrayAudio::OnOutputMuteChanged(bool /* mute_on */) {
+void TrayAudio::OnOutputMuteChanged(bool /* mute_on */, bool system_adjust) {
if (tray_view())
tray_view()->SetVisible(GetInitialVisibility());
if (volume_view_) {
volume_view_->Update();
SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds);
- } else {
+ } else if (!system_adjust) {
pop_up_volume_view_ = true;
PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false);
}
diff --git a/ash/system/audio/tray_audio.h b/ash/system/audio/tray_audio.h
index caf5760..9621eb8 100644
--- a/ash/system/audio/tray_audio.h
+++ b/ash/system/audio/tray_audio.h
@@ -60,7 +60,7 @@ class TrayAudio : public TrayImageItem,
// Overridden from AudioObserver.
void OnOutputNodeVolumeChanged(uint64_t node_id, double volume) override;
- void OnOutputMuteChanged(bool mute_on) override;
+ void OnOutputMuteChanged(bool mute_on, bool system_adjust) override;
void OnAudioNodesChanged() override;
void OnActiveOutputNodeChanged() override;
void OnActiveInputNodeChanged() override;
diff --git a/ash/system/tray/system_tray_notifier.cc b/ash/system/tray/system_tray_notifier.cc
index 40e7050..ec5bd8d 100644
--- a/ash/system/tray/system_tray_notifier.cc
+++ b/ash/system/tray/system_tray_notifier.cc
@@ -201,9 +201,10 @@ void SystemTrayNotifier::NotifyAudioOutputVolumeChanged(uint64_t node_id,
OnOutputNodeVolumeChanged(node_id, volume));
}
-void SystemTrayNotifier::NotifyAudioOutputMuteChanged(bool mute_on) {
+void SystemTrayNotifier::NotifyAudioOutputMuteChanged(bool mute_on,
+ bool system_adjust) {
FOR_EACH_OBSERVER(AudioObserver, audio_observers_,
- OnOutputMuteChanged(mute_on));
+ OnOutputMuteChanged(mute_on, system_adjust));
}
void SystemTrayNotifier::NotifyAudioNodesChanged() {
diff --git a/ash/system/tray/system_tray_notifier.h b/ash/system/tray/system_tray_notifier.h
index b46cb9a..e9a61fb 100644
--- a/ash/system/tray/system_tray_notifier.h
+++ b/ash/system/tray/system_tray_notifier.h
@@ -111,7 +111,7 @@ class ASH_EXPORT SystemTrayNotifier {
void NotifyAccessibilityModeChanged(
ui::AccessibilityNotificationVisibility notify);
void NotifyAudioOutputVolumeChanged(uint64_t node_id, double volume);
- void NotifyAudioOutputMuteChanged(bool mute_on);
+ void NotifyAudioOutputMuteChanged(bool mute_on, bool system_adjust);
void NotifyAudioNodesChanged();
void NotifyAudioActiveOutputNodeChanged();
void NotifyAudioActiveInputNodeChanged();
diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc
index 8c20f2c7..4d76d96 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -524,7 +524,8 @@ class TestAudioObserver : public chromeos::CrasAudioHandler::AudioObserver {
protected:
// chromeos::CrasAudioHandler::AudioObserver overrides.
- void OnOutputMuteChanged(bool /* mute_on */) override {
+ void OnOutputMuteChanged(bool /* mute_on */,
+ bool /* system_adjust */) override {
++output_mute_changed_count_;
}
diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc
index 188df6a..6e09998 100644
--- a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc
+++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc
@@ -1235,8 +1235,9 @@ void SystemTrayDelegateChromeOS::OnOutputNodeVolumeChanged(uint64_t node_id,
GetSystemTrayNotifier()->NotifyAudioOutputVolumeChanged(node_id, volume);
}
-void SystemTrayDelegateChromeOS::OnOutputMuteChanged(bool mute_on) {
- GetSystemTrayNotifier()->NotifyAudioOutputMuteChanged(mute_on);
+void SystemTrayDelegateChromeOS::OnOutputMuteChanged(bool mute_on,
+ bool system_adjust) {
+ GetSystemTrayNotifier()->NotifyAudioOutputMuteChanged(mute_on, system_adjust);
}
void SystemTrayDelegateChromeOS::OnInputNodeGainChanged(uint64_t /* node_id */,
diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos.h b/chrome/browser/ui/ash/system_tray_delegate_chromeos.h
index 0c5bdfb..ff9e126 100644
--- a/chrome/browser/ui/ash/system_tray_delegate_chromeos.h
+++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos.h
@@ -222,7 +222,7 @@ class SystemTrayDelegateChromeOS
// Overridden from CrasAudioHandler::AudioObserver.
void OnOutputNodeVolumeChanged(uint64_t node_id, int volume) override;
- void OnOutputMuteChanged(bool mute_on) override;
+ void OnOutputMuteChanged(bool mute_on, bool system_adjust) override;
void OnInputNodeGainChanged(uint64_t node_id, int gain) override;
void OnInputMuteChanged(bool mute_on) override;
void OnAudioNodesChanged() override;
diff --git a/chrome/browser/ui/ash/volume_controller_chromeos.cc b/chrome/browser/ui/ash/volume_controller_chromeos.cc
index 5079c06..1dc51a7 100644
--- a/chrome/browser/ui/ash/volume_controller_chromeos.cc
+++ b/chrome/browser/ui/ash/volume_controller_chromeos.cc
@@ -99,7 +99,8 @@ void VolumeController::OnOutputNodeVolumeChanged(uint64_t node_id, int volume) {
audio_handler->IsOutputMuted());
}
-void VolumeController::OnOutputMuteChanged(bool /* mute_on */) {
+void VolumeController::OnOutputMuteChanged(bool /* mute_on */,
+ bool /* system_adjust */) {
CrasAudioHandler* audio_handler = CrasAudioHandler::Get();
extensions::DispatchVolumeChangedEvent(
audio_handler->GetOutputVolumePercent(),
diff --git a/chrome/browser/ui/ash/volume_controller_chromeos.h b/chrome/browser/ui/ash/volume_controller_chromeos.h
index 4e94ae4..e1b2737 100644
--- a/chrome/browser/ui/ash/volume_controller_chromeos.h
+++ b/chrome/browser/ui/ash/volume_controller_chromeos.h
@@ -24,7 +24,7 @@ class VolumeController : public ash::VolumeControlDelegate,
// Overridden from chromeos::CrasAudioHandler::AudioObserver.
void OnOutputNodeVolumeChanged(uint64_t node_id, int volume) override;
- void OnOutputMuteChanged(bool mute_on) override;
+ void OnOutputMuteChanged(bool mute_on, bool system_adjust) override;
private:
diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc
index 1cf03d1..8ee6009 100644
--- a/chromeos/audio/cras_audio_handler.cc
+++ b/chromeos/audio/cras_audio_handler.cc
@@ -69,8 +69,9 @@ void CrasAudioHandler::AudioObserver::OnInputNodeGainChanged(
int /* gain */) {
}
-void CrasAudioHandler::AudioObserver::OnOutputMuteChanged(bool /* mute_on */) {
-}
+void CrasAudioHandler::AudioObserver::OnOutputMuteChanged(
+ bool /* mute_on */,
+ bool /* system_adjust */) {}
void CrasAudioHandler::AudioObserver::OnInputMuteChanged(bool /* mute_on */) {
}
@@ -370,8 +371,9 @@ void CrasAudioHandler::SetOutputMute(bool mute_on) {
}
}
- FOR_EACH_OBSERVER(AudioObserver, observers_,
- OnOutputMuteChanged(output_mute_on_));
+ FOR_EACH_OBSERVER(
+ AudioObserver, observers_,
+ OnOutputMuteChanged(output_mute_on_, false /* system_adjust */));
}
void CrasAudioHandler::AdjustOutputVolumeToAudibleLevel() {
@@ -1014,8 +1016,13 @@ void CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod() {
hdmi_rediscovering_ = false;
if (!IsOutputMutedForDevice(active_output_node_id_)) {
// Unmute the audio output after the HDMI transition period.
- VLOG(1) << "Unmute output after HDMI rediscovring grace period.";
+ VLOG(1) << "Unmute output after HDMI rediscovering grace period.";
SetOutputMuteInternal(false);
+
+ // Notify UI about the mute state change.
+ FOR_EACH_OBSERVER(
+ AudioObserver, observers_,
+ OnOutputMuteChanged(output_mute_on_, true /* system adjustment */));
}
}
diff --git a/chromeos/audio/cras_audio_handler.h b/chromeos/audio/cras_audio_handler.h
index 10c77a4..60a3131 100644
--- a/chromeos/audio/cras_audio_handler.h
+++ b/chromeos/audio/cras_audio_handler.h
@@ -41,7 +41,12 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
virtual void OnOutputNodeVolumeChanged(uint64_t node_id, int volume);
// Called when output mute state changed.
- virtual void OnOutputMuteChanged(bool mute_on);
+ // |mute_on|: True if output is muted.
+ // |system_adjust|: True if the mute state is adjusted by the system
+ // automatically(i.e. not by user). UI should reflect the system's mute
+ // state, but it should not be too loud, e.g., the volume pop up window
+ // should not be triggered.
+ virtual void OnOutputMuteChanged(bool mute_on, bool system_adjust);
// Called when active input node's gain changed.
virtual void OnInputNodeGainChanged(uint64_t node_id, int gain);
diff --git a/chromeos/audio/cras_audio_handler_unittest.cc b/chromeos/audio/cras_audio_handler_unittest.cc
index 1a01d2e..4633d87 100644
--- a/chromeos/audio/cras_audio_handler_unittest.cc
+++ b/chromeos/audio/cras_audio_handler_unittest.cc
@@ -192,14 +192,15 @@ const AudioNode kUSBCameraInput(true,
class TestObserver : public chromeos::CrasAudioHandler::AudioObserver {
public:
- TestObserver() : active_output_node_changed_count_(0),
- active_input_node_changed_count_(0),
- audio_nodes_changed_count_(0),
- output_mute_changed_count_(0),
- input_mute_changed_count_(0),
- output_volume_changed_count_(0),
- input_gain_changed_count_(0) {
- }
+ TestObserver()
+ : active_output_node_changed_count_(0),
+ active_input_node_changed_count_(0),
+ audio_nodes_changed_count_(0),
+ output_mute_changed_count_(0),
+ input_mute_changed_count_(0),
+ output_volume_changed_count_(0),
+ input_gain_changed_count_(0),
+ output_mute_by_system_(false) {}
int active_output_node_changed_count() const {
return active_output_node_changed_count_;
@@ -225,6 +226,8 @@ class TestObserver : public chromeos::CrasAudioHandler::AudioObserver {
return output_mute_changed_count_;
}
+ void reset_output_mute_changed_count() { input_mute_changed_count_ = 0; }
+
int input_mute_changed_count() const {
return input_mute_changed_count_;
}
@@ -237,6 +240,8 @@ class TestObserver : public chromeos::CrasAudioHandler::AudioObserver {
return input_gain_changed_count_;
}
+ bool output_mute_by_system() const { return output_mute_by_system_; }
+
~TestObserver() override {}
protected:
@@ -251,8 +256,9 @@ class TestObserver : public chromeos::CrasAudioHandler::AudioObserver {
void OnAudioNodesChanged() override { ++audio_nodes_changed_count_; }
- void OnOutputMuteChanged(bool /* mute_on */) override {
+ void OnOutputMuteChanged(bool /* mute_on */, bool system_adjust) override {
++output_mute_changed_count_;
+ output_mute_by_system_ = system_adjust;
}
void OnInputMuteChanged(bool /* mute_on */) override {
@@ -276,6 +282,7 @@ class TestObserver : public chromeos::CrasAudioHandler::AudioObserver {
int input_mute_changed_count_;
int output_volume_changed_count_;
int input_gain_changed_count_;
+ bool output_mute_by_system_; // output mute state adjusted by system.
DISALLOW_COPY_AND_ASSIGN(TestObserver);
};
@@ -2600,4 +2607,54 @@ TEST_F(CrasAudioHandlerTest, HDMIOutputRediscover) {
EXPECT_FALSE(cras_audio_handler_->IsOutputMuted());
}
+// This tests the case of output unmuting event is notified after the hdmi
+// output re-discover grace period ends, see crbug.com/512601.
+TEST_F(CrasAudioHandlerTest, HDMIOutputUnplugDuringSuspension) {
+ AudioNodeList audio_nodes;
+ audio_nodes.push_back(kInternalSpeaker);
+ audio_nodes.push_back(kHDMIOutput);
+ SetUpCrasAudioHandler(audio_nodes);
+
+ // Verify the HDMI device has been selected as the active output, and audio
+ // output is not muted.
+ AudioDevice active_output;
+ EXPECT_TRUE(
+ cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output));
+ EXPECT_EQ(kHDMIOutput.id, active_output.id);
+ EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode());
+ EXPECT_TRUE(cras_audio_handler_->has_alternative_output());
+ EXPECT_FALSE(cras_audio_handler_->IsOutputMuted());
+
+ // Trigger HDMI rediscovering grace period, and remove the HDMI node.
+ const int grace_period_in_ms = 200;
+ SetHDMIRediscoverGracePeriodDuration(grace_period_in_ms);
+ SetActiveHDMIRediscover();
+ AudioNodeList audio_nodes_lost_hdmi;
+ audio_nodes_lost_hdmi.push_back(kInternalSpeaker);
+ ChangeAudioNodes(audio_nodes_lost_hdmi);
+
+ // Verify the active output is switched to internal speaker, it is not muted
+ // by preference, but the system output is muted during the grace period.
+ EXPECT_TRUE(
+ cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output));
+ EXPECT_EQ(kInternalSpeaker.id, active_output.id);
+ EXPECT_FALSE(
+ cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id));
+ EXPECT_TRUE(cras_audio_handler_->IsOutputMuted());
+
+ // After HDMI re-discover grace period, verify internal speaker is still the
+ // active output and not muted, and unmute event by system is notified.
+ test_observer_->reset_output_mute_changed_count();
+ HDMIRediscoverWaiter waiter(this, grace_period_in_ms);
+ waiter.WaitUntilHDMIRediscoverGracePeriodEnd();
+ EXPECT_TRUE(
+ cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output));
+ EXPECT_EQ(kInternalSpeaker.id, active_output.id);
+ EXPECT_EQ(kInternalSpeaker.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
+ EXPECT_FALSE(cras_audio_handler_->IsOutputMuted());
+ EXPECT_EQ(1, test_observer_->output_mute_changed_count());
+ EXPECT_TRUE(test_observer_->output_mute_by_system());
+}
+
} // namespace chromeos
diff --git a/extensions/browser/api/audio/audio_service_chromeos.cc b/extensions/browser/api/audio/audio_service_chromeos.cc
index 0ac4711..7f7e856 100644
--- a/extensions/browser/api/audio/audio_service_chromeos.cc
+++ b/extensions/browser/api/audio/audio_service_chromeos.cc
@@ -41,7 +41,7 @@ class AudioServiceImpl : public AudioService,
// chromeos::CrasAudioHandler::AudioObserver overrides.
void OnOutputNodeVolumeChanged(uint64_t id, int volume) override;
void OnInputNodeGainChanged(uint64_t id, int gain) override;
- void OnOutputMuteChanged(bool mute_on) override;
+ void OnOutputMuteChanged(bool mute_on, bool system_adjust) override;
void OnInputMuteChanged(bool mute_on) override;
void OnAudioNodesChanged() override;
void OnActiveOutputNodeChanged() override;
@@ -199,7 +199,7 @@ void AudioServiceImpl::OnOutputNodeVolumeChanged(uint64_t id, int volume) {
NotifyLevelChanged(id, volume);
}
-void AudioServiceImpl::OnOutputMuteChanged(bool mute_on) {
+void AudioServiceImpl::OnOutputMuteChanged(bool mute_on, bool system_adjust) {
NotifyMuteChanged(false, mute_on);
}
diff --git a/extensions/shell/browser/shell_audio_controller_chromeos.cc b/extensions/shell/browser/shell_audio_controller_chromeos.cc
index 550c56c..19e34ce2 100644
--- a/extensions/shell/browser/shell_audio_controller_chromeos.cc
+++ b/extensions/shell/browser/shell_audio_controller_chromeos.cc
@@ -39,8 +39,8 @@ void ShellAudioController::OnOutputNodeVolumeChanged(uint64_t /* node_id */,
int /* volume */) {
}
-void ShellAudioController::OnOutputMuteChanged(bool /* mute_on */) {
-}
+void ShellAudioController::OnOutputMuteChanged(bool /* mute_on */,
+ bool /* system_adjust */) {}
void ShellAudioController::OnInputNodeGainChanged(uint64_t /* node_id */,
int /* gain */) {
diff --git a/extensions/shell/browser/shell_audio_controller_chromeos.h b/extensions/shell/browser/shell_audio_controller_chromeos.h
index 0f47352..e93a66d 100644
--- a/extensions/shell/browser/shell_audio_controller_chromeos.h
+++ b/extensions/shell/browser/shell_audio_controller_chromeos.h
@@ -18,7 +18,7 @@ class ShellAudioController : public chromeos::CrasAudioHandler::AudioObserver {
// chromeos::CrasAudioHandler::Observer implementation:
void OnOutputNodeVolumeChanged(uint64_t node_id, int volume) override;
- void OnOutputMuteChanged(bool mute_on) override;
+ void OnOutputMuteChanged(bool mute_on, bool system_adjust) override;
void OnInputNodeGainChanged(uint64_t node_id, int gain) override;
void OnInputMuteChanged(bool mute_on) override;
void OnAudioNodesChanged() override;