[autotest] cras_utils: Use SetActiveInputNode and SetActiveOutputNode API
To align the usage of setting active input/output nodes in Chrome, we
should use SetActiveInputNode and SetActiveOutputNode for single node
case.
BUG=chromium:534953
TEST=run audio_AudioBasicBluetoothRecord test to make sure the method to
set active input node does not break
Change-Id: I5fade12636124e7d50ec5e3a50694ad2fd430e25
Reviewed-on: https://chromium-review.googlesource.com/301752
Commit-Ready: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@chromium.org>
diff --git a/client/cros/audio/cras_utils.py b/client/cros/audio/cras_utils.py
index 6403ca7..a307e24 100644
--- a/client/cros/audio/cras_utils.py
+++ b/client/cros/audio/cras_utils.py
@@ -353,12 +353,50 @@
@param input_node_types: A list of input node types. None to skip setting.
"""
- if output_node_types:
+ if len(output_node_types) == 1:
+ set_single_selected_output_node(output_node_types[0])
+ elif output_node_types:
set_selected_output_nodes(output_node_types)
- if input_node_types:
+ if len(input_node_types) == 1:
+ set_single_selected_input_node(input_node_types[0])
+ elif input_node_types:
set_selected_input_nodes(input_node_types)
+def set_single_selected_output_node(node_type):
+ """Sets one selected output node.
+
+ Note that Chrome UI uses SetActiveOutputNode of Cras DBus API
+ to select one output node.
+
+ @param node_type: A node type.
+
+ """
+ nodes = get_cras_nodes()
+ for node in nodes:
+ if node['IsInput']:
+ continue
+ if node['Type'] == node_type:
+ set_active_output_node(node['Id'])
+
+
+def set_single_selected_input_node(node_type):
+ """Sets one selected input node.
+
+ Note that Chrome UI uses SetActiveInputNode of Cras DBus API
+ to select one input node.
+
+ @param node_type: A node type.
+
+ """
+ nodes = get_cras_nodes()
+ for node in nodes:
+ if not node['IsInput']:
+ continue
+ if node['Type'] == node_type:
+ set_active_input_node(node['Id'])
+
+
def set_selected_output_nodes(types):
"""Sets selected output node types.
@@ -399,6 +437,24 @@
remove_active_input_node(node['Id'])
+def set_active_input_node(node_id):
+ """Sets one active input node.
+
+ @param node_id: node id.
+
+ """
+ get_cras_control_interface().SetActiveInputNode(node_id)
+
+
+def set_active_output_node(node_id):
+ """Sets one active output node.
+
+ @param node_id: node id.
+
+ """
+ get_cras_control_interface().SetActiveOutputNode(node_id)
+
+
def add_active_output_node(node_id):
"""Adds an active output node.