Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7363426d authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Automerger Merge Worker
Browse files

Merge "audio: Put stronger rules on vendor extension enums" am: 2553d042

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1596938

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I19218c518ccf8cf6ba81c1459a1133f859d9a5b1
parents 5a899a38 2553d042
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -310,13 +310,17 @@
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="vendorExtension">
        <!-- Vendor extension names must be prefixed by "VX_" to distinguish them from AOSP values.
             Vendor are encouraged to namespace their module names to avoid conflicts.
             Example for an hypothetical Google virtual reality device:
                <devicePort tagName="VR" type="VX_GOOGLE_VR" role="sink">
        <!-- Vendor extension names must be prefixed by "VX_" to distinguish them from
             AOSP values. Vendors must namespace their names to avoid conflicts. The
             namespace part must only use capital latin characters and decimal digits and
             consist of at least 3 characters. The part of the extension name after the
             namespace may in addition include underscores. Example for a hypothetical
             Google virtual reality device:

                 <devicePort tagName="VR" type="VX_GOOGLE_VR" role="sink" />
        -->
        <xs:restriction base="xs:string">
            <xs:pattern value="VX_[_a-zA-Z0-9]+"/>
            <xs:pattern value="VX_[A-Z0-9]{3,}_[_A-Z0-9]+"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="extendableAudioDevice">
+5 −7
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@
#define ANDROID_AUDIO_POLICY_CONFIGURATION_V7_0__ENUMS_H

#include <sys/types.h>
#include <algorithm>
#include <cctype>
#include <regex>
#include <string>

#include <android_audio_policy_configuration_V7_0_enums.h>

@@ -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) {
+6 −0
Original line number Diff line number Diff line
@@ -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) {