Audio HAL: Align V2 and V4 VTS

It was thought that the V2 VTS were not going to be supported after V4
VTS were created. Thus a large portion of the code was copy paste and
modified.

That assumption ended up wrong as a lot of OEM reported bugs that needed
to be fixed in both versions.

As a result align the code of both version VTS as much as possible.
The code will be merged in a follow up patch.

Bug: 118203066
Test: compile
Change-Id: I994232db237b5d7c52e7d796f199ab3c6eec21f4
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/audio/effect/2.0/vts/functional/Android.bp b/audio/effect/2.0/vts/functional/Android.bp
index f3fefc3..38ca315 100644
--- a/audio/effect/2.0/vts/functional/Android.bp
+++ b/audio/effect/2.0/vts/functional/Android.bp
@@ -32,5 +32,8 @@
         "libicuuc_stubdata",
         "libxml2",
     ],
+    header_libs: [
+        "android.hardware.audio.common.util@all-versions",
+    ],
     test_suites: ["general-tests"],
 }
diff --git a/audio/effect/2.0/vts/functional/ValidateAudioEffectsConfiguration.cpp b/audio/effect/2.0/vts/functional/ValidateAudioEffectsConfiguration.cpp
index bf080d3..040c93f 100644
--- a/audio/effect/2.0/vts/functional/ValidateAudioEffectsConfiguration.cpp
+++ b/audio/effect/2.0/vts/functional/ValidateAudioEffectsConfiguration.cpp
@@ -21,12 +21,19 @@
 
 #include "utility/ValidateXml.h"
 
+// Stringify the argument.
+#define QUOTE(x) #x
+#define STRINGIFY(x) QUOTE(x)
+
+#define AUDIO_HAL_VERSION V2_0
+
 TEST(CheckConfig, audioEffectsConfigurationValidation) {
     RecordProperty("description",
                    "Verify that the effects configuration file is valid according to the schema");
     using namespace android::effectsConfig;
 
     std::vector<const char*> locations(std::begin(DEFAULT_LOCATIONS), std::end(DEFAULT_LOCATIONS));
-    EXPECT_VALID_XML_MULTIPLE_LOCATIONS(DEFAULT_NAME, locations,
-                                        "/data/local/tmp/audio_effects_conf_V2_0.xsd");
+    const char* xsd = "/data/local/tmp/audio_effects_conf_" STRINGIFY(AUDIO_HAL_VERSION) ".xsd";
+    // In V2, audio effect XML is not required. .conf is still allowed though deprecated
+    EXPECT_VALID_XML_MULTIPLE_LOCATIONS(DEFAULT_NAME, locations, xsd);
 }
diff --git a/audio/effect/2.0/vts/functional/VtsHalAudioEffectTargetTest.cpp b/audio/effect/2.0/vts/functional/VtsHalAudioEffectTargetTest.cpp
index ea755ae..078e420 100644
--- a/audio/effect/2.0/vts/functional/VtsHalAudioEffectTargetTest.cpp
+++ b/audio/effect/2.0/vts/functional/VtsHalAudioEffectTargetTest.cpp
@@ -26,6 +26,8 @@
 #include <android/hidl/allocator/1.0/IAllocator.h>
 #include <android/hidl/memory/1.0/IMemory.h>
 
+#include <common/all-versions/VersionUtils.h>
+
 #include <VtsHalHidlTargetTestBase.h>
 #include <VtsHalHidlTargetTestEnvBase.h>
 
@@ -37,6 +39,7 @@
 using android::hardware::MQDescriptorSync;
 using android::hardware::Return;
 using android::hardware::Void;
+using android::hardware::audio::common::utils::mkEnumBitfield;
 using android::hardware::audio::common::V2_0::AudioDevice;
 using android::hardware::audio::common::V2_0::AudioHandleConsts;
 using android::hardware::audio::common::V2_0::AudioMode;
@@ -396,7 +399,7 @@
 
 TEST_F(AudioEffectHidlTest, SetDevice) {
     description("Verify that SetDevice works for an output chain effect");
-    Return<Result> ret = effect->setDevice(AudioDevice::OUT_SPEAKER);
+    Return<Result> ret = effect->setDevice(mkEnumBitfield(AudioDevice::OUT_SPEAKER));
     EXPECT_TRUE(ret.isOk());
     EXPECT_EQ(Result::OK, ret);
 }
@@ -446,7 +449,7 @@
 
 TEST_F(AudioEffectHidlTest, SetInputDevice) {
     description("Verify that SetInputDevice does not crash");
-    Return<Result> ret = effect->setInputDevice(AudioDevice::IN_BUILTIN_MIC);
+    Return<Result> ret = effect->setInputDevice(mkEnumBitfield(AudioDevice::IN_BUILTIN_MIC));
     EXPECT_TRUE(ret.isOk());
 }