summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorjennyz <jennyz@chromium.org>2016-03-08 10:18:10 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-08 18:19:10 +0000
commitb46664f407fa853f2573f05db37784b04f5a013c (patch)
treed5c1914ea015e9d0c2bf1293a40ec83a783f5a39 /chromeos
parente246e4c702d03cde59f044748dc4a8f04b92d269 (diff)
downloadchromium_src-b46664f407fa853f2573f05db37784b04f5a013c.zip
chromium_src-b46664f407fa853f2573f05db37784b04f5a013c.tar.gz
chromium_src-b46664f407fa853f2573f05db37784b04f5a013c.tar.bz2
Exclude non-simple-usage audio nodes from being selected as primary node, and do not persist their active state in prefs.
BUG=591777 Review URL: https://codereview.chromium.org/1759103003 Cr-Commit-Position: refs/heads/master@{#379861}
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/audio/cras_audio_handler.cc20
-rw-r--r--chromeos/audio/cras_audio_handler_unittest.cc21
2 files changed, 37 insertions, 4 deletions
diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc
index 64114c9..d008d86 100644
--- a/chromeos/audio/cras_audio_handler.cc
+++ b/chromeos/audio/cras_audio_handler.cc
@@ -425,6 +425,11 @@ void CrasAudioHandler::SetActiveDevice(const AudioDevice& active_device,
void CrasAudioHandler::SaveDeviceState(const AudioDevice& device,
bool active,
DeviceActivateType activate_by) {
+ // Don't save the active state for non-simple usage device, which is invisible
+ // to end users.
+ if (!device.is_for_simple_usage())
+ return;
+
if (!active) {
audio_pref_handler_->SetDeviceActive(device, false, false);
} else {
@@ -924,7 +929,7 @@ bool CrasAudioHandler::GetActiveDeviceFromUserPref(bool is_input,
for (AudioDeviceMap::const_iterator it = audio_devices_.begin();
it != audio_devices_.end(); ++it) {
AudioDevice device = it->second;
- if (device.is_input != is_input)
+ if (device.is_input != is_input || !device.is_for_simple_usage())
continue;
bool active = false;
@@ -993,7 +998,6 @@ void CrasAudioHandler::HandleNonHotplugNodesChange(
return;
if (hotplug_nodes.empty()) {
- // Unplugged a non-active device.
if (has_device_removed) {
if (!active_device_removed && has_current_active_node) {
// Removed a non-active device, keep the current active device.
@@ -1010,7 +1014,7 @@ void CrasAudioHandler::HandleNonHotplugNodesChange(
// Some unexpected error happens on cras side. See crbug.com/586026.
// Either cras sent stale nodes to chrome again or cras triggered some
// error. Restore the previously selected active.
- VLOG(1) << "Odd case from cras, the active node is lost unexpectedly. ";
+ VLOG(1) << "Odd case from cras, the active node is lost unexpectedly.";
SwitchToPreviousActiveDeviceIfAvailable(is_input);
} else {
// Looks like a new chrome session starts.
@@ -1021,6 +1025,12 @@ void CrasAudioHandler::HandleNonHotplugNodesChange(
void CrasAudioHandler::HandleHotPlugDevice(
const AudioDevice& hotplug_device,
const AudioDevicePriorityQueue& device_priority_queue) {
+ // This most likely may happen during the transition period of cras
+ // initialization phase, in which a non-simple-usage node may appear like
+ // a hotplug node.
+ if (!hotplug_device.is_for_simple_usage())
+ return;
+
bool last_state_active = false;
bool last_activate_by_user = false;
if (!audio_pref_handler_->GetDeviceActive(hotplug_device, &last_state_active,
@@ -1046,12 +1056,14 @@ void CrasAudioHandler::HandleHotPlugDevice(
void CrasAudioHandler::SwitchToTopPriorityDevice(bool is_input) {
AudioDevice top_device =
is_input ? input_devices_pq_.top() : output_devices_pq_.top();
- SwitchToDevice(top_device, true, ACTIVATE_BY_PRIORITY);
+ if (top_device.is_for_simple_usage())
+ SwitchToDevice(top_device, true, ACTIVATE_BY_PRIORITY);
}
void CrasAudioHandler::SwitchToPreviousActiveDeviceIfAvailable(bool is_input) {
AudioDevice previous_active_device;
if (GetActiveDeviceFromUserPref(is_input, &previous_active_device)) {
+ DCHECK(previous_active_device.is_for_simple_usage());
// Switch to previous active device stored in user prefs.
SwitchToDevice(previous_active_device, true,
ACTIVATE_BY_RESTORE_PREVIOUS_STATE);
diff --git a/chromeos/audio/cras_audio_handler_unittest.cc b/chromeos/audio/cras_audio_handler_unittest.cc
index 9566065..5fadd6f 100644
--- a/chromeos/audio/cras_audio_handler_unittest.cc
+++ b/chromeos/audio/cras_audio_handler_unittest.cc
@@ -575,6 +575,27 @@ TEST_F(CrasAudioHandlerTest, SetKeyboardMicActive) {
EXPECT_FALSE(inactive_keyboard_mic->active);
}
+TEST_F(CrasAudioHandlerTest, KeyboardMicNotSetAsPrimaryActive) {
+ AudioNodeList audio_nodes;
+ audio_nodes.push_back(kKeyboardMic);
+ SetUpCrasAudioHandler(audio_nodes);
+
+ // Verify keyboard mic is not set as primary active input.
+ AudioDeviceList audio_devices;
+ cras_audio_handler_->GetAudioDevices(&audio_devices);
+ EXPECT_EQ(audio_nodes.size(), audio_devices.size());
+ EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic());
+ EXPECT_EQ(0u, cras_audio_handler_->GetPrimaryActiveInputNode());
+
+ // Verify the internal mic is set as primary input.
+ audio_nodes.push_back(kInternalMic);
+ ChangeAudioNodes(audio_nodes);
+ cras_audio_handler_->GetAudioDevices(&audio_devices);
+ EXPECT_EQ(audio_nodes.size(), audio_devices.size());
+ EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic());
+ EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode());
+}
+
TEST_F(CrasAudioHandlerTest, SwitchActiveOutputDevice) {
AudioNodeList audio_nodes;
audio_nodes.push_back(kInternalSpeaker);