Add volume group addresses check among volume groups

The check verifies that within the same audio zone configuration, the
volume group audio device address should not repeat. This check does
not apply to configurable audio policy engine, since the configurable
audio policy engine allows for volume to be managed indepently for each
volume group for the same device.

Bug: 359686069
Bug: 379199006
Test: atest com.android.car.audio
Flag: android.car.feature.audio_control_hal_configuration
Change-Id: I682d013338acbbb92bef35b1d83508b17a37453b
diff --git a/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp b/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
index c01c0d6..6781a81 100644
--- a/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
+++ b/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
@@ -149,7 +149,9 @@
         return false;
     }
     if (groupDevices.contains(address)) {
-        message = " Audio device address can not repeat in the same volume group";
+        message =
+                " Audio device address can not repeat in the same volume group or within audio"
+                " zone configuration if not using configurable audio policy engine";
         return false;
     }
     groupDevices.insert(address);
@@ -196,7 +198,8 @@
 
 void validateVolumeGroupInfo(const AudioZoneConfig& audioZoneConfig,
                              const VolumeGroupConfig& volumeGroupConfig,
-                             const AudioDeviceConfiguration& deviceConfig) {
+                             const AudioDeviceConfiguration& deviceConfig,
+                             std::set<std::string>& groupDevices) {
     std::string zoneConfigName = testutils::toAlphaNumeric(ToString(audioZoneConfig.name));
     std::string volumeGroupName = testutils::toAlphaNumeric(ToString(volumeGroupConfig.name));
     std::string volumeGroupInfo =
@@ -209,7 +212,6 @@
         EXPECT_FALSE(volumeGroupConfig.name.empty())
                 << volumeGroupInfo << " must have a non-empty volume name";
     }
-    std::set<std::string> groupDevices;
     for (const auto& audioRoute : volumeGroupConfig.carAudioRoutes) {
         std::string routeMessage;
         EXPECT_TRUE(hasValidAudioRoute(audioRoute, routeMessage, groupDevices))
@@ -254,6 +256,7 @@
     std::set<std::string> contextInfoNames;
     EXPECT_FALSE(audioZoneConfig.volumeGroups.empty())
             << "Volume groups for zone config " << zoneConfigName.c_str();
+    std::set<std::string> groupDevices;
     for (const auto& volumeGroup : audioZoneConfig.volumeGroups) {
         ALOGI("Zone config name %s volume group test %s", zoneConfigName.c_str(),
               ToString(volumeGroup.name).c_str());
@@ -264,7 +267,11 @@
                     << "Context " << context << " repeats in zone config " << zoneConfigName;
             contextInfoNames.insert(context);
         }
-        validateVolumeGroupInfo(audioZoneConfig, volumeGroup, deviceConfig);
+        // Configurable audio policy engine can share devices among volume groups
+        if (deviceConfig.routingConfig == CONFIGURABLE_AUDIO_ENGINE_ROUTING) {
+            groupDevices.clear();
+        }
+        validateVolumeGroupInfo(audioZoneConfig, volumeGroup, deviceConfig, groupDevices);
     }
     const auto& audioZoneContexts = carAudioZone.audioZoneContext.audioContextInfos;
     std::map<std::string, AudioZoneContextInfo> infoNameToInfo;