diff --git a/audio/7.0/config/audio_policy_configuration.xsd b/audio/7.0/config/audio_policy_configuration.xsd index 531572b777..ccaaf98288 100644 --- a/audio/7.0/config/audio_policy_configuration.xsd +++ b/audio/7.0/config/audio_policy_configuration.xsd @@ -310,13 +310,17 @@ - - + diff --git a/audio/common/7.0/enums/include/android_audio_policy_configuration_V7_0-enums.h b/audio/common/7.0/enums/include/android_audio_policy_configuration_V7_0-enums.h index b427f3a0d4..ada0d3eb9b 100644 --- a/audio/common/7.0/enums/include/android_audio_policy_configuration_V7_0-enums.h +++ b/audio/common/7.0/enums/include/android_audio_policy_configuration_V7_0-enums.h @@ -18,8 +18,8 @@ #define ANDROID_AUDIO_POLICY_CONFIGURATION_V7_0_ENUMS_H #include -#include -#include +#include +#include #include @@ -219,11 +219,9 @@ static inline bool maybeVendorExtension(const std::string& s) { } static inline bool isVendorExtension(const std::string& s) { - // Must match the "vendorExtension" rule from the XSD file. - static const std::string vendorPrefix = "VX_"; - return maybeVendorExtension(s) && - std::all_of(s.begin() + vendorPrefix.size(), s.end(), - [](unsigned char c) { return c == '_' || std::isalnum(c); }); + // Must be the same as the "vendorExtension" rule from the XSD file. + static const std::regex vendorExtension("VX_[A-Z0-9]{3,}_[_A-Z0-9]+"); + return std::regex_match(s.begin(), s.end(), vendorExtension); } static inline bool isUnknownAudioChannelMask(const std::string& mask) { diff --git a/audio/common/all-versions/default/tests/hidlutils_tests.cpp b/audio/common/all-versions/default/tests/hidlutils_tests.cpp index ec6bdf38ef..e154453e2b 100644 --- a/audio/common/all-versions/default/tests/hidlutils_tests.cpp +++ b/audio/common/all-versions/default/tests/hidlutils_tests.cpp @@ -432,10 +432,16 @@ TEST(HidlUtils, ConvertDeviceType) { // The enums module is too small to have unit tests on its own. TEST(HidlUtils, VendorExtension) { EXPECT_TRUE(xsd::isVendorExtension("VX_GOOGLE_VR_42")); + EXPECT_TRUE(xsd::isVendorExtension("VX_QCM_SPK")); EXPECT_FALSE(xsd::isVendorExtension("")); EXPECT_FALSE(xsd::isVendorExtension("random string")); EXPECT_FALSE(xsd::isVendorExtension("VX_")); + EXPECT_FALSE(xsd::isVendorExtension("VX_X")); + EXPECT_FALSE(xsd::isVendorExtension("VX_X_")); + EXPECT_FALSE(xsd::isVendorExtension("VX_X_X")); + EXPECT_FALSE(xsd::isVendorExtension("VX_XX_X")); EXPECT_FALSE(xsd::isVendorExtension("VX_GOOGLE_$$")); + EXPECT_FALSE(xsd::isVendorExtension("VX_$CM_SPK")); } TEST(HidlUtils, ConvertInvalidDeviceAddress) {