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/MatrixInstance.cpp b/MatrixInstance.cpp
index caf6861..e4e731e 100644
--- a/MatrixInstance.cpp
+++ b/MatrixInstance.cpp
@@ -18,6 +18,8 @@
#include <utility>
+#include "Regex.h"
+
namespace android {
namespace vintf {
@@ -68,16 +70,21 @@
if (!isRegex()) {
return exactInstance() == e;
}
- return false; // FIXME: do matching.
+ details::Regex regex;
+ if (!regex.compile(regexPattern())) {
+ return false;
+ }
+ return regex.matches(e);
}
const std::string& MatrixInstance::regexPattern() const {
static const std::string kEmptyString;
- return kEmptyString;
+ return isRegex() ? mFqInstance.getInstance() : kEmptyString;
}
const std::string& MatrixInstance::exactInstance() const {
- return mFqInstance.getInstance();
+ static const std::string kEmptyString;
+ return isRegex() ? kEmptyString : mFqInstance.getInstance();
}
bool MatrixInstance::isRegex() const {