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

Commit b644d44c authored by Pawin Vongmasa's avatar Pawin Vongmasa
Browse files

RESTRICT AUTOMERGE ValidateMediaProfiles searches multiple directories

The file "media_profiles_V1_0.xml" may reside in /product/etc, /odm/etc,
/vendor/etc or /system/etc. The current test code assumes the file lives
in /vendor/etc. This change makes the test search through the four
directories.

Test: atest VtsValidateMediaProfiles

Bug: 159576670
Change-Id: Icb763631192ca591768aa371bc31b4c722a75366
parent 5c124b62
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ cc_test {
        "libxml2",
    ],
    shared_libs: [
        "libbase",
        "liblog",
    ],
    cflags: [
+49 −3
Original line number Diff line number Diff line
@@ -14,15 +14,61 @@
 * limitations under the License.
 */

#include <fstream>
#include <string>

#include <android-base/file.h>
#include <android-base/properties.h>
#include "utility/ValidateXml.h"

bool isFileReadable(std::string const& path) {
  std::ifstream f(path);
  return f.good();
}

TEST(CheckConfig, mediaProfilesValidation) {
    RecordProperty("description",
                   "Verify that the media profiles file "
                   "is valid according to the schema");

    const char* location = "/vendor/etc";
    // Schema path.
    constexpr char const* xsdPath = "/data/local/tmp/media_profiles.xsd";

    // If "media.settings.xml" is set, it will be used as an absolute path.
    std::string mediaSettingsPath = android::base::GetProperty("media.settings.xml", "");
    if (mediaSettingsPath.empty()) {
        // If "media.settings.xml" is not set, we will search through a list of
        // file paths.

        constexpr char const* xmlSearchDirs[] = {
                "/product/etc/",
                "/odm/etc/",
                "/vendor/etc/",
                "/system/etc/", // Fallback directory
            };

    EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS("media_profiles_V1_0.xml", {location},
                                            "/data/local/tmp/media_profiles.xsd");
        const std::string fileName = "media_profiles_V1_0.xml";

        std::vector<std::string> xmlPaths = {
                xmlSearchDirs[0] + fileName,
                xmlSearchDirs[1] + fileName,
                xmlSearchDirs[2] + fileName,
                xmlSearchDirs[3] + fileName,
            };

        auto findXmlPath =
            std::find_if(xmlPaths.begin(), xmlPaths.end(), isFileReadable);
        ASSERT_TRUE(findXmlPath != xmlPaths.end())
                << "Cannot read from " << fileName
                << " in any search directories ("
                << xmlSearchDirs[0] << ", "
                << xmlSearchDirs[1] << ", "
                << xmlSearchDirs[2] << ", "
                << xmlSearchDirs[3] << ").";

        char const* xmlPath = findXmlPath->c_str();
        EXPECT_VALID_XML(xmlPath, xsdPath);
    } else {
        EXPECT_VALID_XML(mediaSettingsPath.c_str(), xsdPath);
    }
}