regex-instance: Fix CompatibilityMatrix::combine to use regex API
combine() is used when a framework compatibility matrix is formed.
Fix it so that the generated FCM contains <regex-instance> as well.
Caveat: In the old code, combine() considered two HAL versions
replacement of each other when their package, interface and
instance are equal. (For example,
if 1.xml states audio@2.0::IDeviceFactory/default
and 2.xml states audio@4.0::IDeviceFactory/default
then generated matrix only requires one of them to exist.
With the introduction of <regex-instanece>, combine() only combines
two versions if the regex pattern *exactly matches*; that is (for
example)
if 1.xml states
camera@1.0::ICamera/legacy/0 AND camera@1.0::ICamera/legacy/[0-9]+
and 2.xml states
camera@3.0::ICamera/legacy/[0-9]+
combine() requires
camera@1.0::ICamera/legacy/0 AND
(camera@1.0::ICamera/legacy[0-9]+ OR camera@3.0::ICamera/legacy[0-9]+)
... because the pattern "legacy[0-9]+" are exactly the same. It will not
combine even if two regex patterns has the same meaning, e.g. when
one of them is "legacy/[0-9]{1,}".
Bug: 73738616
Test: libvintf_test
Test: vintf_object_test
Test: vts_treble_vintf_test
Change-Id: Ie34f0f1ccab1e942f6aa9e9e40aa20140f220844
diff --git a/MatrixHal.cpp b/MatrixHal.cpp
index da6b55f..86118b5 100644
--- a/MatrixHal.cpp
+++ b/MatrixHal.cpp
@@ -144,21 +144,12 @@
}
}
-void MatrixHal::insertInstance(const std::string& interface, const std::string& instance) {
+void MatrixHal::insertInstance(const std::string& interface, const std::string& instance,
+ bool isRegex) {
auto it = interfaces.find(interface);
if (it == interfaces.end())
it = interfaces.emplace(interface, HalInterface{interface, {}}).first;
- it->second.insertInstance(instance, false /* isRegex */);
-}
-
-bool MatrixHal::hasInstance(const std::string& interface, const std::string& instance) const {
- bool found = false;
- forEachInstance([&](const auto& matrixInstance) {
- found |= matrixInstance.interface() == interface && !matrixInstance.isRegex() &&
- matrixInstance.matchInstance(instance);
- return !found; // continue if not match
- });
- return found;
+ it->second.insertInstance(instance, isRegex);
}
size_t MatrixHal::instancesCount() const {
@@ -170,27 +161,11 @@
return count;
}
-bool MatrixHal::hasOnlyInstance(const std::string& interface, const std::string& instance) const {
- bool found = false;
- bool foundOthers = false;
-
- forEachInstance([&](const auto& matrixInstance) {
- bool match = matrixInstance.interface() == interface && !matrixInstance.isRegex() &&
- matrixInstance.matchInstance(instance);
-
- found |= match;
- foundOthers |= (!match);
-
- return !foundOthers;
- });
-
- return found && !foundOthers;
-}
-
-bool MatrixHal::removeInstance(const std::string& interface, const std::string& instance) {
+bool MatrixHal::removeInstance(const std::string& interface, const std::string& instance,
+ bool isRegex) {
auto it = interfaces.find(interface);
if (it == interfaces.end()) return false;
- bool removed = it->second.removeInstance(instance, false /* isRegex */);
+ bool removed = it->second.removeInstance(instance, isRegex);
if (!it->second.hasAnyInstance()) interfaces.erase(it);
return removed;
}