No need to update devices when they are the same as original ones.
The audio framework will call create_audio_patch to update the new
input/output devices. When the new devices are the same as the original
ones, there is no need to update.
Bug: 188843084
Test: play audio via USB
Change-Id: I4bf2a51a0e88797f2d78513962e18009c59f46c3
diff --git a/modules/usbaudio/audio_hal.c b/modules/usbaudio/audio_hal.c
index c847ae0..9ab2859 100644
--- a/modules/usbaudio/audio_hal.c
+++ b/modules/usbaudio/audio_hal.c
@@ -432,6 +432,41 @@
return num_sample_rates;
}
+static bool are_all_devices_found(unsigned int num_devices_to_find,
+ const int cards_to_find[],
+ const int devices_to_find[],
+ unsigned int num_devices,
+ const int cards[],
+ const int devices[]) {
+ for (unsigned int i = 0; i < num_devices_to_find; ++i) {
+ unsigned int j = 0;
+ for (; j < num_devices; ++j) {
+ if (cards_to_find[i] == cards[j] && devices_to_find[i] == devices[j]) {
+ break;
+ }
+ }
+ if (j >= num_devices) {
+ return false;
+ }
+ }
+ return true;
+}
+
+static bool are_devices_the_same(unsigned int left_num_devices,
+ const int left_cards[],
+ const int left_devices[],
+ unsigned int right_num_devices,
+ const int right_cards[],
+ const int right_devices[]) {
+ if (left_num_devices != right_num_devices) {
+ return false;
+ }
+ return are_all_devices_found(left_num_devices, left_cards, left_devices,
+ right_num_devices, right_cards, right_devices) &&
+ are_all_devices_found(right_num_devices, right_cards, right_devices,
+ left_num_devices, left_cards, left_devices);
+}
+
/*
* HAl Functions
*/
@@ -1620,6 +1655,13 @@
saved_devices[num_saved_devices++] = device_info->profile.device;
}
+ if (are_devices_the_same(
+ num_configs, cards, devices, num_saved_devices, saved_cards, saved_devices)) {
+ // The new devices are the same as original ones. No need to update.
+ stream_unlock(lock);
+ return 0;
+ }
+
device_lock(adev);
stream_standby_l(alsa_devices, out == NULL ? &in->standby : &out->standby);
device_unlock(adev);