[REFACTOR] embed file name into manifest/matrix object
Instead of attaching name to the object as a new type Named<T>,
embed the file name or file path of the object into the object
directly.
The type Named<T> is re-written so that its subclass extends its
setFileName() and fileName() methods.
Test: libvintf_test, vintf_object_test
Bug: 118757553
Change-Id: Ib3356cf56632b00c77c26df1cfa1a1aaf8878876
diff --git a/AssembleVintf.cpp b/AssembleVintf.cpp
index a954acd..f084076 100644
--- a/AssembleVintf.cpp
+++ b/AssembleVintf.cpp
@@ -294,18 +294,16 @@
return true;
}
- template <typename S>
- using Schemas = std::vector<Named<S>>;
- using HalManifests = Schemas<HalManifest>;
- using CompatibilityMatrices = Schemas<CompatibilityMatrix>;
+ using HalManifests = std::vector<HalManifest>;
+ using CompatibilityMatrices = std::vector<CompatibilityMatrix>;
template <typename M>
- void outputInputs(const Schemas<M>& inputs) {
+ void outputInputs(const std::vector<M>& inputs) {
out() << "<!--" << std::endl;
out() << " Input:" << std::endl;
for (const auto& e : inputs) {
- if (!e.name.empty()) {
- out() << " " << base::Basename(e.name) << std::endl;
+ if (!e.fileName().empty()) {
+ out() << " " << base::Basename(e.fileName()) << std::endl;
}
}
out() << "-->" << std::endl;
@@ -364,17 +362,17 @@
bool assembleHalManifest(HalManifests* halManifests) {
std::string error;
- HalManifest* halManifest = &halManifests->front().object;
+ HalManifest* halManifest = &halManifests->front();
for (auto it = halManifests->begin() + 1; it != halManifests->end(); ++it) {
- const std::string& path = it->name;
- HalManifest& manifestToAdd = it->object;
+ const std::string& path = it->fileName();
+ HalManifest& manifestToAdd = *it;
if (manifestToAdd.level() != Level::UNSPECIFIED) {
if (halManifest->level() == Level::UNSPECIFIED) {
halManifest->mLevel = manifestToAdd.level();
} else if (halManifest->level() != manifestToAdd.level()) {
std::cerr << "Inconsistent FCM Version in HAL manifests:" << std::endl
- << " File '" << halManifests->front().name << "' has level "
+ << " File '" << halManifests->front().fileName() << "' has level "
<< halManifest->level() << std::endl
<< " File '" << path << "' has level " << manifestToAdd.level()
<< std::endl;
@@ -516,8 +514,8 @@
Level getLowestFcmVersion(const CompatibilityMatrices& matrices) {
Level ret = Level::UNSPECIFIED;
for (const auto& e : matrices) {
- if (ret == Level::UNSPECIFIED || ret > e.object.level()) {
- ret = e.object.level();
+ if (ret == Level::UNSPECIFIED || ret > e.level()) {
+ ret = e.level();
}
}
return ret;
@@ -537,7 +535,7 @@
}
}
- if (matrices->front().object.mType == SchemaType::DEVICE) {
+ if (matrices->front().mType == SchemaType::DEVICE) {
builtMatrix = CompatibilityMatrix::combineDeviceMatrices(matrices, &error);
matrix = builtMatrix.get();
@@ -551,7 +549,7 @@
auto& valueInMatrix = matrix->device.mVendorNdk;
if (!valueInMatrix.version().empty() && valueInMatrix.version() != vndkVersion) {
std::cerr << "Hard-coded <vendor-ndk> version in device compatibility matrix ("
- << matrices->front().name << "), '" << valueInMatrix.version()
+ << matrices->front().fileName() << "), '" << valueInMatrix.version()
<< "', does not match value inferred "
<< "from BOARD_VNDK_VERSION '" << vndkVersion << "'" << std::endl;
return false;
@@ -564,7 +562,7 @@
}
}
- if (matrices->front().object.mType == SchemaType::FRAMEWORK) {
+ if (matrices->front().mType == SchemaType::FRAMEWORK) {
Level deviceLevel =
checkManifest != nullptr ? checkManifest->level() : Level::UNSPECIFIED;
if (deviceLevel == Level::UNSPECIFIED) {
@@ -638,17 +636,19 @@
template <typename Schema, typename AssembleFunc>
AssembleStatus tryAssemble(const XmlConverter<Schema>& converter, const std::string& schemaName,
AssembleFunc assemble, std::string* error) {
- Schemas<Schema> schemas;
+ std::vector<Schema> schemas;
Schema schema;
+ schema.setFileName(mInFiles.front().name());
if (!converter(&schema, read(mInFiles.front().stream()), error)) {
return TRY_NEXT;
}
auto firstType = schema.type();
- schemas.emplace_back(mInFiles.front().name(), std::move(schema));
+ schemas.emplace_back(std::move(schema));
for (auto it = mInFiles.begin() + 1; it != mInFiles.end(); ++it) {
Schema additionalSchema;
const std::string& fileName = it->name();
+ additionalSchema.setFileName(fileName);
if (!converter(&additionalSchema, read(it->stream()), error)) {
std::cerr << "File \"" << fileName << "\" is not a valid " << firstType << " "
<< schemaName << " (but the first file is a valid " << firstType << " "
@@ -662,7 +662,7 @@
return FAIL_AND_EXIT;
}
- schemas.emplace_back(fileName, std::move(additionalSchema));
+ schemas.emplace_back(std::move(additionalSchema));
}
return assemble(&schemas) ? SUCCESS : FAIL_AND_EXIT;
}
diff --git a/CompatibilityMatrix.cpp b/CompatibilityMatrix.cpp
index a2ef873..ae13d99 100644
--- a/CompatibilityMatrix.cpp
+++ b/CompatibilityMatrix.cpp
@@ -303,6 +303,7 @@
}
bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) {
+ // ignore fileName().
return lft.mType == rgt.mType && lft.mLevel == rgt.mLevel && lft.mHals == rgt.mHals &&
lft.mXmlFiles == rgt.mXmlFiles &&
(lft.mType != SchemaType::DEVICE ||
@@ -320,12 +321,12 @@
}
std::unique_ptr<CompatibilityMatrix> CompatibilityMatrix::combine(
- Level deviceLevel, std::vector<Named<CompatibilityMatrix>>* matrices, std::string* error) {
+ Level deviceLevel, std::vector<CompatibilityMatrix>* matrices, std::string* error) {
// Check type.
for (const auto& e : *matrices) {
- if (e.object.type() != SchemaType::FRAMEWORK) {
+ if (e.type() != SchemaType::FRAMEWORK) {
if (error) {
- *error = "File \"" + e.name + "\" is not a framework compatibility matrix.";
+ *error = "File \"" + e.fileName() + "\" is not a framework compatibility matrix.";
return nullptr;
}
}
@@ -333,15 +334,15 @@
// Matrices with unspecified (empty) level are auto-filled with deviceLevel.
for (auto& e : *matrices) {
- if (e.object.level() == Level::UNSPECIFIED) {
- e.object.mLevel = deviceLevel;
+ if (e.level() == Level::UNSPECIFIED) {
+ e.mLevel = deviceLevel;
}
}
// Add from low to high FCM version so that optional <kernel> requirements are added correctly.
// See comment in addAllAsOptional.
std::sort(matrices->begin(), matrices->end(),
- [](const auto& x, const auto& y) { return x.object.level() < y.object.level(); });
+ [](const auto& x, const auto& y) { return x.level() < y.level(); });
auto baseMatrix = std::make_unique<CompatibilityMatrix>();
baseMatrix->mLevel = deviceLevel;
@@ -349,31 +350,31 @@
std::vector<std::string> parsedFiles;
for (auto& e : *matrices) {
- if (e.object.level() < deviceLevel) {
+ if (e.level() < deviceLevel) {
continue;
}
bool success = false;
- if (e.object.level() == deviceLevel) {
+ if (e.level() == deviceLevel) {
success = baseMatrix->addAll(&e, error);
} else {
success = baseMatrix->addAllAsOptional(&e, error);
}
if (!success) {
if (error) {
- *error = "Conflict when merging \"" + e.name + "\": " + *error + "\n" +
+ *error = "Conflict when merging \"" + e.fileName() + "\": " + *error + "\n" +
"Previous files:\n" + base::Join(parsedFiles, "\n");
}
return nullptr;
}
- parsedFiles.push_back(e.name);
+ parsedFiles.push_back(e.fileName());
}
return baseMatrix;
}
std::unique_ptr<CompatibilityMatrix> CompatibilityMatrix::combineDeviceMatrices(
- std::vector<Named<CompatibilityMatrix>>* matrices, std::string* error) {
+ std::vector<CompatibilityMatrix>* matrices, std::string* error) {
auto baseMatrix = std::make_unique<CompatibilityMatrix>();
baseMatrix->mType = SchemaType::DEVICE;
@@ -382,36 +383,34 @@
bool success = baseMatrix->addAll(&e, error);
if (!success) {
if (error) {
- *error = "Conflict when merging \"" + e.name + "\": " + *error + "\n" +
+ *error = "Conflict when merging \"" + e.fileName() + "\": " + *error + "\n" +
"Previous files:\n" + base::Join(parsedFiles, "\n");
}
return nullptr;
}
- parsedFiles.push_back(e.name);
+ parsedFiles.push_back(e.fileName());
}
return baseMatrix;
}
-bool CompatibilityMatrix::addAll(Named<CompatibilityMatrix>* inputMatrix, std::string* error) {
- if (!addAllHals(&inputMatrix->object, error) || !addAllXmlFiles(&inputMatrix->object, error) ||
- !addAllKernels(&inputMatrix->object, error) || !addSepolicy(&inputMatrix->object, error) ||
- !addAvbMetaVersion(&inputMatrix->object, error) || !addVndk(&inputMatrix->object, error) ||
- !addVendorNdk(&inputMatrix->object, error) || !addSystemSdk(&inputMatrix->object, error)) {
+bool CompatibilityMatrix::addAll(CompatibilityMatrix* inputMatrix, std::string* error) {
+ if (!addAllHals(inputMatrix, error) || !addAllXmlFiles(inputMatrix, error) ||
+ !addAllKernels(inputMatrix, error) || !addSepolicy(inputMatrix, error) ||
+ !addAvbMetaVersion(inputMatrix, error) || !addVndk(inputMatrix, error) ||
+ !addVendorNdk(inputMatrix, error) || !addSystemSdk(inputMatrix, error)) {
if (error) {
- *error = "File \"" + inputMatrix->name + "\" cannot be added: " + *error + ".";
+ *error = "File \"" + inputMatrix->fileName() + "\" cannot be added: " + *error + ".";
}
return false;
}
return true;
}
-bool CompatibilityMatrix::addAllAsOptional(Named<CompatibilityMatrix>* inputMatrix,
- std::string* error) {
- if (!addAllHalsAsOptional(&inputMatrix->object, error) ||
- !addAllXmlFilesAsOptional(&inputMatrix->object, error) ||
- !addAllKernels(&inputMatrix->object, error)) {
+bool CompatibilityMatrix::addAllAsOptional(CompatibilityMatrix* inputMatrix, std::string* error) {
+ if (!addAllHalsAsOptional(inputMatrix, error) ||
+ !addAllXmlFilesAsOptional(inputMatrix, error) || !addAllKernels(inputMatrix, error)) {
if (error) {
- *error = "File \"" + inputMatrix->name + "\" cannot be added: " + *error;
+ *error = "File \"" + inputMatrix->fileName() + "\" cannot be added: " + *error;
}
return false;
}
diff --git a/HalManifest.cpp b/HalManifest.cpp
index 9118773..7ce58b9 100644
--- a/HalManifest.cpp
+++ b/HalManifest.cpp
@@ -465,6 +465,7 @@
}
bool operator==(const HalManifest &lft, const HalManifest &rgt) {
+ // ignore fileName().
return lft.mType == rgt.mType && lft.mLevel == rgt.mLevel && lft.mHals == rgt.mHals &&
lft.mXmlFiles == rgt.mXmlFiles &&
(lft.mType != SchemaType::DEVICE ||
diff --git a/VintfObject.cpp b/VintfObject.cpp
index 2611a56..090f582 100644
--- a/VintfObject.cpp
+++ b/VintfObject.cpp
@@ -148,7 +148,7 @@
status_t VintfObject::getCombinedFrameworkMatrix(
const std::shared_ptr<const HalManifest>& deviceManifest, CompatibilityMatrix* out,
std::string* error) {
- std::vector<Named<CompatibilityMatrix>> matrixFragments;
+ std::vector<CompatibilityMatrix> matrixFragments;
auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error);
if (matrixFragmentsStatus != OK) {
return matrixFragmentsStatus;
@@ -177,8 +177,8 @@
if (deviceLevel == Level::UNSPECIFIED) {
// Cannot infer FCM version. Combine all matrices by assuming
// Shipping FCM Version == min(all supported FCM Versions in the framework)
- for (auto&& pair : matrixFragments) {
- Level fragmentLevel = pair.object.level();
+ for (auto&& fragment : matrixFragments) {
+ Level fragmentLevel = fragment.level();
if (fragmentLevel != Level::UNSPECIFIED && deviceLevel > fragmentLevel) {
deviceLevel = fragmentLevel;
}
@@ -426,24 +426,24 @@
}
}
-status_t VintfObject::getOneMatrix(const std::string& path, Named<CompatibilityMatrix>* out,
+status_t VintfObject::getOneMatrix(const std::string& path, CompatibilityMatrix* out,
std::string* error) {
std::string content;
status_t status = getFileSystem()->fetch(path, &content, error);
if (status != OK) {
return status;
}
- if (!gCompatibilityMatrixConverter(&out->object, content, error)) {
+ if (!gCompatibilityMatrixConverter(out, content, error)) {
if (error) {
error->insert(0, "Cannot parse " + path + ": ");
}
return BAD_VALUE;
}
- out->name = path;
+ out->setFileName(path);
return OK;
}
-status_t VintfObject::getAllFrameworkMatrixLevels(std::vector<Named<CompatibilityMatrix>>* results,
+status_t VintfObject::getAllFrameworkMatrixLevels(std::vector<CompatibilityMatrix>* results,
std::string* error) {
std::vector<std::string> dirs = {
kSystemVintfDir,
@@ -461,7 +461,7 @@
}
for (const std::string& fileName : fileNames) {
std::string path = dir + fileName;
- Named<CompatibilityMatrix> namedMatrix;
+ CompatibilityMatrix namedMatrix;
std::string matrixError;
status_t matrixStatus = getOneMatrix(path, &namedMatrix, &matrixError);
if (matrixStatus != OK) {
@@ -819,7 +819,7 @@
int32_t VintfObject::checkDeprecation(const ListInstances& listInstances,
const std::vector<HidlInterfaceMetadata>& hidlMetadata,
std::string* error) {
- std::vector<Named<CompatibilityMatrix>> matrixFragments;
+ std::vector<CompatibilityMatrix> matrixFragments;
auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error);
if (matrixFragmentsStatus != OK) {
return matrixFragmentsStatus;
@@ -843,8 +843,8 @@
const CompatibilityMatrix* targetMatrix = nullptr;
for (const auto& namedMatrix : matrixFragments) {
- if (namedMatrix.object.level() == deviceLevel) {
- targetMatrix = &namedMatrix.object;
+ if (namedMatrix.level() == deviceLevel) {
+ targetMatrix = &namedMatrix;
}
}
if (targetMatrix == nullptr) {
@@ -864,11 +864,10 @@
// Matrices with unspecified level are considered "current".
bool isDeprecated = false;
for (const auto& namedMatrix : matrixFragments) {
- if (namedMatrix.object.level() == Level::UNSPECIFIED) continue;
- if (namedMatrix.object.level() >= deviceLevel) continue;
+ if (namedMatrix.level() == Level::UNSPECIFIED) continue;
+ if (namedMatrix.level() >= deviceLevel) continue;
- const auto& oldMatrix = namedMatrix.object;
- for (const MatrixHal& hal : oldMatrix.getHals()) {
+ for (const MatrixHal& hal : namedMatrix.getHals()) {
if (IsHalDeprecated(hal, *targetMatrix, listInstances, childrenMap, error)) {
isDeprecated = true;
}
@@ -924,7 +923,7 @@
}
android::base::Result<bool> VintfObject::hasFrameworkCompatibilityMatrixExtensions() {
- std::vector<Named<CompatibilityMatrix>> matrixFragments;
+ std::vector<CompatibilityMatrix> matrixFragments;
std::string error;
status_t status = getAllFrameworkMatrixLevels(&matrixFragments, &error);
if (status != OK) {
@@ -933,17 +932,16 @@
}
for (const auto& namedMatrix : matrixFragments) {
// Returns true if product matrix exists.
- if (android::base::StartsWith(namedMatrix.name, kProductVintfDir)) {
+ if (android::base::StartsWith(namedMatrix.fileName(), kProductVintfDir)) {
return true;
}
// Returns true if system_ext matrix exists.
- if (android::base::StartsWith(namedMatrix.name, kSystemExtVintfDir)) {
+ if (android::base::StartsWith(namedMatrix.fileName(), kSystemExtVintfDir)) {
return true;
}
// Returns true if device system matrix exists.
- if (android::base::StartsWith(namedMatrix.name, kSystemVintfDir) &&
- namedMatrix.object.level() == Level::UNSPECIFIED &&
- !namedMatrix.object.getHals().empty()) {
+ if (android::base::StartsWith(namedMatrix.fileName(), kSystemVintfDir) &&
+ namedMatrix.level() == Level::UNSPECIFIED && !namedMatrix.getHals().empty()) {
return true;
}
}
diff --git a/include/vintf/CompatibilityMatrix.h b/include/vintf/CompatibilityMatrix.h
index 6bb8fe6..6985eca 100644
--- a/include/vintf/CompatibilityMatrix.h
+++ b/include/vintf/CompatibilityMatrix.h
@@ -30,19 +30,21 @@
#include "MatrixHal.h"
#include "MatrixInstance.h"
#include "MatrixKernel.h"
-#include "Named.h"
#include "SchemaType.h"
#include "Sepolicy.h"
#include "SystemSdk.h"
#include "VendorNdk.h"
#include "Vndk.h"
+#include "WithFileName.h"
#include "XmlFileGroup.h"
namespace android {
namespace vintf {
// Compatibility matrix defines what hardware does the framework requires.
-struct CompatibilityMatrix : public HalGroup<MatrixHal>, public XmlFileGroup<MatrixXmlFile> {
+struct CompatibilityMatrix : public HalGroup<MatrixHal>,
+ public XmlFileGroup<MatrixXmlFile>,
+ public WithFileName {
// Create a framework compatibility matrix.
CompatibilityMatrix() : mType(SchemaType::FRAMEWORK) {}
@@ -69,7 +71,7 @@
private:
// Add everything in inputMatrix to "this" as requirements.
- bool addAll(Named<CompatibilityMatrix>* inputMatrix, std::string* error);
+ bool addAll(CompatibilityMatrix* inputMatrix, std::string* error);
// Add all <kernel> from other to "this". Error if there is a conflict.
bool addAllKernels(CompatibilityMatrix* other, std::string* error);
@@ -93,7 +95,7 @@
bool addSystemSdk(CompatibilityMatrix* other, std::string* error);
// Add everything in inputMatrix to "this" as optional.
- bool addAllAsOptional(Named<CompatibilityMatrix>* inputMatrix, std::string* error);
+ bool addAllAsOptional(CompatibilityMatrix* inputMatrix, std::string* error);
// Add all HALs as optional HALs from "other". This function moves MatrixHal objects
// from "other".
@@ -114,12 +116,13 @@
// with lower level()
// - <sepolicy>, <avb><vbmeta-version> is ignored
// Return the combined matrix, nullptr if any error (e.g. conflict of information).
- static std::unique_ptr<CompatibilityMatrix> combine(
- Level deviceLevel, std::vector<Named<CompatibilityMatrix>>* matrices, std::string* error);
+ static std::unique_ptr<CompatibilityMatrix> combine(Level deviceLevel,
+ std::vector<CompatibilityMatrix>* matrices,
+ std::string* error);
// Combine a set of device compatibility matrices.
static std::unique_ptr<CompatibilityMatrix> combineDeviceMatrices(
- std::vector<Named<CompatibilityMatrix>>* matrices, std::string* error);
+ std::vector<CompatibilityMatrix>* matrices, std::string* error);
status_t fetchAllInformation(const FileSystem* fileSystem, const std::string& path,
std::string* error = nullptr);
diff --git a/include/vintf/HalManifest.h b/include/vintf/HalManifest.h
index 41298f0..db53aa7 100644
--- a/include/vintf/HalManifest.h
+++ b/include/vintf/HalManifest.h
@@ -39,6 +39,7 @@
#include "VendorNdk.h"
#include "Version.h"
#include "Vndk.h"
+#include "WithFileName.h"
#include "XmlFileGroup.h"
namespace android {
@@ -55,7 +56,9 @@
// A HalManifest is reported by the hardware and query-able from
// framework code. This is the API for the framework.
-struct HalManifest : public HalGroup<ManifestHal>, public XmlFileGroup<ManifestXmlFile> {
+struct HalManifest : public HalGroup<ManifestHal>,
+ public XmlFileGroup<ManifestXmlFile>,
+ public WithFileName {
public:
// Construct a device HAL manifest.
@@ -227,7 +230,6 @@
} framework;
};
-
} // namespace vintf
} // namespace android
diff --git a/include/vintf/Named.h b/include/vintf/Named.h
deleted file mode 100644
index eacb70b..0000000
--- a/include/vintf/Named.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_VINTF_NAMED_H
-#define ANDROID_VINTF_NAMED_H
-
-#include <string>
-
-template <typename T>
-struct Named {
- std::string name;
- T object;
-
- Named() = default;
- Named(const std::string& n, const T& o) : name(n), object(o) {}
- Named(std::string&& n, T&& o) : name(std::move(n)), object(std::move(o)) {}
-};
-
-#endif // ANDROID_VINTF_NAMED_H
diff --git a/include/vintf/VintfObject.h b/include/vintf/VintfObject.h
index fa25669..4fb19bd 100644
--- a/include/vintf/VintfObject.h
+++ b/include/vintf/VintfObject.h
@@ -32,7 +32,6 @@
#include "FileSystem.h"
#include "HalManifest.h"
#include "Level.h"
-#include "Named.h"
#include "ObjectFactory.h"
#include "PropertyFetcher.h"
#include "RuntimeInfo.h"
@@ -308,9 +307,9 @@
private:
status_t getCombinedFrameworkMatrix(const std::shared_ptr<const HalManifest>& deviceManifest,
CompatibilityMatrix* out, std::string* error = nullptr);
- status_t getAllFrameworkMatrixLevels(std::vector<Named<CompatibilityMatrix>>* out,
+ status_t getAllFrameworkMatrixLevels(std::vector<CompatibilityMatrix>* out,
std::string* error = nullptr);
- status_t getOneMatrix(const std::string& path, Named<CompatibilityMatrix>* out,
+ status_t getOneMatrix(const std::string& path, CompatibilityMatrix* out,
std::string* error = nullptr);
status_t addDirectoryManifests(const std::string& directory, HalManifest* manifests,
std::string* error = nullptr);
diff --git a/include/vintf/WithFileName.h b/include/vintf/WithFileName.h
new file mode 100644
index 0000000..beed3e2
--- /dev/null
+++ b/include/vintf/WithFileName.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+
+namespace android::vintf {
+
+// WithFileName is a class that attaches a name to an object.
+// The name is often the file name or path of the source file where the object
+// is deserialized from. The name is used for informational and debugging
+// purposes. It is not retained when the object is serialized.
+// It is not meant to be used as an identifier of the object:
+// - there may be duplicated names;
+// - name may be empty.
+struct WithFileName {
+ WithFileName() = default;
+ WithFileName(const std::string& fileName) : mFileName(fileName) {}
+ const std::string& fileName() const { return mFileName; }
+ void setFileName(std::string&& fileName) { mFileName = std::move(fileName); }
+ void setFileName(const std::string& fileName) { mFileName = fileName; }
+
+ private:
+ std::string mFileName;
+};
+
+} // namespace android::vintf
diff --git a/test/LibVintfTest.cpp b/test/LibVintfTest.cpp
index fac2306..6ec89f7 100644
--- a/test/LibVintfTest.cpp
+++ b/test/LibVintfTest.cpp
@@ -3945,33 +3945,32 @@
struct FrameworkCompatibilityMatrixCombineTest : public LibVintfTest {
virtual void SetUp() override {
- matrices = {
- {"compatibility_matrix.1_1.xml", CompatibilityMatrix{}},
- {"compatibility_matrix.1_2.xml", CompatibilityMatrix{}},
- };
+ matrices.resize(2);
+ matrices[0].setFileName("compatibility_matrix.1_1.xml");
+ matrices[1].setFileName("compatibility_matrix.1_2.xml");
}
// Access to private methods.
std::unique_ptr<CompatibilityMatrix> combine(Level deviceLevel,
- std::vector<Named<CompatibilityMatrix>>* matrices,
+ std::vector<CompatibilityMatrix>* matrices,
std::string* error) {
return CompatibilityMatrix::combine(deviceLevel, matrices, error);
}
- std::vector<Named<CompatibilityMatrix>> matrices;
+ std::vector<CompatibilityMatrix> matrices;
std::string error;
};
// Combining framework compatibility matrix with conflicting minlts fails
TEST_F(FrameworkCompatibilityMatrixCombineTest, ConflictMinlts) {
ASSERT_TRUE(gCompatibilityMatrixConverter(
- &matrices[0].object,
+ &matrices[0],
"<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
" <kernel version=\"3.18.5\" />\n"
"</compatibility-matrix>\n",
&error))
<< error;
ASSERT_TRUE(gCompatibilityMatrixConverter(
- &matrices[1].object,
+ &matrices[1],
"<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
" <kernel version=\"3.18.6\" />\n"
"</compatibility-matrix>\n",
@@ -4007,14 +4006,14 @@
" </kernel>\n";
ASSERT_TRUE(gCompatibilityMatrixConverter(
- &matrices[0].object,
+ &matrices[0],
"<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
" <kernel version=\"3.18.5\" />\n" +
conditionedKernel + "</compatibility-matrix>\n",
&error))
<< error;
ASSERT_TRUE(gCompatibilityMatrixConverter(
- &matrices[1].object,
+ &matrices[1],
"<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n" + simpleKernel +
"</compatibility-matrix>\n",
&error))
@@ -4031,7 +4030,7 @@
// Combining framework compatibility matrix with conflicting sepolicy fails
TEST_F(FrameworkCompatibilityMatrixCombineTest, ConflictSepolicy) {
ASSERT_TRUE(gCompatibilityMatrixConverter(
- &matrices[0].object,
+ &matrices[0],
"<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
" <sepolicy>\n"
" <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
@@ -4040,7 +4039,7 @@
&error))
<< error;
ASSERT_TRUE(gCompatibilityMatrixConverter(
- &matrices[1].object,
+ &matrices[1],
"<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
" <sepolicy>\n"
" <kernel-sepolicy-version>29</kernel-sepolicy-version>\n"
@@ -4057,7 +4056,7 @@
// Combining framework compatibility matrix with conflicting avb fails
TEST_F(FrameworkCompatibilityMatrixCombineTest, ConflictAvb) {
ASSERT_TRUE(gCompatibilityMatrixConverter(
- &matrices[0].object,
+ &matrices[0],
"<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
" <avb>\n"
" <vbmeta-version>1.1</vbmeta-version>\n"
@@ -4066,7 +4065,7 @@
&error))
<< error;
ASSERT_TRUE(gCompatibilityMatrixConverter(
- &matrices[1].object,
+ &matrices[1],
"<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
" <avb>\n"
" <vbmeta-version>1.0</vbmeta-version>\n"
@@ -4105,9 +4104,9 @@
std::string hidlOptional = std::string(hidl).replace(hidl.find("false"), 5, "true");
std::string error;
{
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0].object, head1 + aidl + tail, &error))
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], head1 + aidl + tail, &error))
<< error;
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1].object, head1 + hidl + tail, &error))
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], head1 + hidl + tail, &error))
<< error;
auto combined = combine(Level{1}, &matrices, &error);
@@ -4118,9 +4117,9 @@
EXPECT_IN(hidl, combinedXml);
}
{
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0].object, head1 + aidl + tail, &error))
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], head1 + aidl + tail, &error))
<< error;
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1].object, head2 + hidl + tail, &error))
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], head2 + hidl + tail, &error))
<< error;
auto combined = combine(Level{1}, &matrices, &error);
@@ -4131,9 +4130,9 @@
EXPECT_IN(hidlOptional, combinedXml);
}
{
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0].object, head2 + aidl + tail, &error))
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], head2 + aidl + tail, &error))
<< error;
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1].object, head1 + hidl + tail, &error))
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], head1 + hidl + tail, &error))
<< error;
auto combined = combine(Level{1}, &matrices, &error);
@@ -4147,18 +4146,17 @@
struct DeviceCompatibilityMatrixCombineTest : public LibVintfTest {
virtual void SetUp() override {
- matrices = {
- {"compatibility_matrix.1.xml", CompatibilityMatrix{}},
- {"compatibility_matrix.2.xml", CompatibilityMatrix{}},
- };
+ matrices.resize(2);
+ matrices[0].setFileName("compatibility_matrix.1.xml");
+ matrices[1].setFileName("compatibility_matrix.2.xml");
}
// Access to private methods.
- std::unique_ptr<CompatibilityMatrix> combine(std::vector<Named<CompatibilityMatrix>>* matrices,
+ std::unique_ptr<CompatibilityMatrix> combine(std::vector<CompatibilityMatrix>* matrices,
std::string* error) {
return CompatibilityMatrix::combineDeviceMatrices(matrices, error);
}
- std::vector<Named<CompatibilityMatrix>> matrices;
+ std::vector<CompatibilityMatrix> matrices;
std::string error;
};
@@ -4183,9 +4181,9 @@
" <instance>default</instance>\n"
" </interface>\n"
" </hal>\n"};
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0].object, head + halFoo + tail, &error))
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], head + halFoo + tail, &error))
<< error;
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1].object, head + halBar + tail, &error))
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], head + halBar + tail, &error))
<< error;
auto combined = combine(&matrices, &error);
@@ -4209,8 +4207,8 @@
" <version>Q</version>\n"
" </vendor-ndk>\n"
"</compatibility-matrix>\n"};
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0].object, vendorNdkP, &error)) << error;
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1].object, vendorNdkQ, &error)) << error;
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], vendorNdkP, &error)) << error;
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], vendorNdkQ, &error)) << error;
auto combined = combine(&matrices, &error);
ASSERT_EQ(nullptr, combined) << gCompatibilityMatrixConverter(*combined);
@@ -4237,9 +4235,9 @@
" <instance>default</instance>\n"
" </interface>\n"
" </hal>\n";
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0].object, head + aidl + tail, &error))
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], head + aidl + tail, &error))
<< error;
- ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1].object, head + hidl + tail, &error))
+ ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], head + hidl + tail, &error))
<< error;
auto combined = combine(&matrices, &error);