Added Fingerprint Virtual HAL AIDL extension

Bug: 326227403
Test: atest android.hardware.biometrics.fingerprint.* -c
Change-Id: I967c009c99f8dc279f89c21a59cf0462d9590296
diff --git a/biometrics/common/config/Config.cpp b/biometrics/common/config/Config.cpp
index 01ae864..a13bdf0 100644
--- a/biometrics/common/config/Config.cpp
+++ b/biometrics/common/config/Config.cpp
@@ -34,7 +34,7 @@
     else if (value == "false")
         res.emplace(false);
     else
-        LOG(ERROR) << "ERROR: invalid bool " << value;
+        LOG(FATAL) << "ERROR: invalid bool " << value;
     return res;
 }
 
@@ -48,7 +48,11 @@
     OptInt32 res;
     if (!value.empty()) {
         std::int32_t val;
-        if (ParseInt(value, &val)) res.emplace(val);
+        if (ParseInt(value, &val)) {
+            res.emplace(val);
+        } else {
+            LOG(FATAL) << "ERROR: Could not parse " << value << " as Int32";
+        }
     }
     return res;
 }
@@ -59,6 +63,8 @@
         std::int64_t val = std::strtoull(value.c_str(), nullptr, 10);
         if (val != 0LL or (val == 0LL && value == "0")) {
             res.emplace(val);
+        } else {
+            LOG(FATAL) << "ERROR: Could not parse " << value << " as Int64";
         }
     }
     return res;
@@ -87,7 +93,7 @@
 bool Config::setParam(const std::string& name, const std::string& value) {
     auto it = mMap.find(name);
     if (it == mMap.end()) {
-        LOG(ERROR) << "ERROR: setParam unknown config name " << name;
+        LOG(FATAL) << "ERROR: setParam unknown config name " << name;
         return false;
     }
     LOG(INFO) << "setParam name=" << name << "=" << value;
@@ -102,7 +108,7 @@
 ConfigValue Config::getInternal(const std::string& name) {
     ConfigValue res;
 
-    auto data = mMap[name];
+    auto& data = mMap[name];
     switch (mSource) {
         case ConfigSourceType::SOURCE_SYSPROP:
             res = data.getter();
@@ -111,10 +117,10 @@
             res = data.value;
             break;
         case ConfigSourceType::SOURCE_FILE:
-            LOG(WARNING) << "Unsupported";
+            UNIMPLEMENTED(ERROR) << " File-based config is not supported yet";
             break;
         default:
-            LOG(ERROR) << " wrong srouce type " << (int)mSource;
+            LOG(FATAL) << "Wrong srouce type " << (int)mSource;
             break;
     }
 
@@ -127,7 +133,7 @@
 
 bool Config::setInternal(const std::string& name, const ConfigValue& val) {
     bool res = false;
-    auto data = mMap[name];
+    auto& data = mMap[name];
 
     switch (mSource) {
         case ConfigSourceType::SOURCE_SYSPROP:
@@ -138,10 +144,10 @@
             res = true;
             break;
         case ConfigSourceType::SOURCE_FILE:
-            LOG(WARNING) << "Unsupported";
+            UNIMPLEMENTED(ERROR) << " File-based config is not supported yet";
             break;
         default:
-            LOG(ERROR) << " wrong srouce type " << (int)mSource;
+            LOG(FATAL) << "Wrong srouce type " << (int)mSource;
             break;
     }
 
diff --git a/biometrics/common/config/include/config/Config.h b/biometrics/common/config/include/config/Config.h
index 864e164..0367832 100644
--- a/biometrics/common/config/include/config/Config.h
+++ b/biometrics/common/config/include/config/Config.h
@@ -84,6 +84,33 @@
     virtual Config::Data* getConfigData(int* size) = 0;
     bool setParam(const std::string& name, const std::string& value);
 
+    void sourcedFromAidl() { mSource = ConfigSourceType::SOURCE_AIDL; }
+    std::string toString(const ConfigValue& v) const {
+        std::ostringstream os;
+        if (std::holds_alternative<OptInt32>(v)) {
+            OptInt32 ov = std::get<OptInt32>(v);
+            if (ov.has_value()) os << ov.value();
+        } else if (std::holds_alternative<OptInt64>(v)) {
+            OptInt64 ov = std::get<OptInt64>(v);
+            if (ov.has_value()) os << ov.value();
+        } else if (std::holds_alternative<OptBool>(v)) {
+            OptBool ov = std::get<OptBool>(v);
+            if (ov.has_value()) os << ov.value();
+            os << std::get<OptBool>(v).value();
+        } else if (std::holds_alternative<OptIntVec>(v)) {
+            for (auto x : std::get<OptIntVec>(v))
+                if (x.has_value()) os << x.value() << " ";
+        }
+        return os.str();
+    }
+    std::string toString() const {
+        std::ostringstream os;
+        for (auto const& [k, v] : mMap) {
+            os << k << ":" << toString(v.value) << std::endl;
+        }
+        return os.str();
+    }
+
     ConfigValue parseBool(const std::string& value);
     ConfigValue parseString(const std::string& name);
     ConfigValue parseInt32(const std::string& value);
diff --git a/biometrics/common/config/tests/ConfigTest.cpp b/biometrics/common/config/tests/ConfigTest.cpp
index d922040..9794b25 100644
--- a/biometrics/common/config/tests/ConfigTest.cpp
+++ b/biometrics/common/config/tests/ConfigTest.cpp
@@ -115,7 +115,7 @@
     void SetUp() override { cfg.init(); }
     void TearDown() override {}
 
-    void switch2aidl() { cfg.setParam("astring", "astring"); }
+    void switch2aidl() { cfg.sourcedFromAidl(); }
 
     TestConfig cfg;
 };
@@ -129,7 +129,6 @@
             {"1234", 1234},
             {"0", 0},
             {"", defval},
-            {"xyz", defval},
     };
     for (int i = 0; i < sizeof(values) / sizeof(values[0]); i++) {
         ASSERT_EQ((std::get<OptInt32>(cfg.parseInt32(values[i].strval))).value_or(defval),
@@ -143,8 +142,10 @@
         std::string strval;
         std::int64_t expval;
     } values[] = {
-            {"1234", 1234},  {"12345678909876", 12345678909876}, {"0", 0}, {"", defval},
-            {"xyz", defval},
+            {"1234", 1234},
+            {"12345678909876", 12345678909876},
+            {"0", 0},
+            {"", defval},
     };
     for (int i = 0; i < sizeof(values) / sizeof(values[0]); i++) {
         ASSERT_EQ((std::get<OptInt64>(cfg.parseInt64(values[i].strval))).value_or(defval),
@@ -160,8 +161,6 @@
     } values[] = {
             {"false", false},
             {"true", true},
-            {"", defval},
-            {"xyz", defval},
     };
     for (int i = 0; i < sizeof(values) / sizeof(values[0]); i++) {
         ASSERT_EQ((std::get<OptBool>(cfg.parseBool(values[i].strval))).value_or(defval),
@@ -174,9 +173,7 @@
     struct {
         std::string strval;
         std::vector<std::optional<int>> expval;
-    } values[] = {
-            {"1", {1}}, {"1,2,3", {1, 2, 3}}, {"1,2,b", defval}, {"", defval}, {"xyz", defval},
-    };
+    } values[] = {{"1", {1}}, {"1,2,3", {1, 2, 3}}, {"1,2,b", defval}, {"", defval}};
     for (int i = 0; i < sizeof(values) / sizeof(values[0]); i++) {
         ASSERT_EQ(std::get<OptIntVec>(cfg.parseIntVec(values[i].strval)), values[i].expval);
     }
@@ -255,12 +252,4 @@
     EXPECT_EQ(cfg.getopt<OptIntVec>("avector"), val_avector_new);
 }
 
-TEST_F(ConfigTest, setParam) {
-    ASSERT_TRUE(cfg.setParam("aint32", "789"));
-    ASSERT_EQ(cfg.get<std::int32_t>("aint32"), 789);
-    ASSERT_TRUE(cfg.setParam("avector", "7,8,9,10"));
-    OptIntVec val_avector_new{7, 8, 9, 10};
-    EXPECT_EQ(cfg.getopt<OptIntVec>("avector"), val_avector_new);
-    ASSERT_FALSE(cfg.setParam("unknown", "any"));
-}
 }  // namespace aidl::android::hardware::biometrics