Loading biometrics/common/config/Config.cpp +15 −9 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ ConfigValue Config::parseBool(const std::string& value) { else if (value == "false") res.emplace(false); else LOG(ERROR) << "ERROR: invalid bool " << value; LOG(FATAL) << "ERROR: invalid bool " << value; return res; } Loading @@ -48,7 +48,11 @@ ConfigValue Config::parseInt32(const std::string& value) { 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; } Loading @@ -59,6 +63,8 @@ ConfigValue Config::parseInt64(const std::string& value) { 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; Loading Loading @@ -87,7 +93,7 @@ void Config::init() { 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; Loading @@ -102,7 +108,7 @@ bool Config::setParam(const std::string& name, const std::string& value) { 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(); Loading @@ -111,10 +117,10 @@ ConfigValue Config::getInternal(const std::string& name) { 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; } Loading @@ -127,7 +133,7 @@ ConfigValue Config::getDefault(const std::string& name) { 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: Loading @@ -138,10 +144,10 @@ bool Config::setInternal(const std::string& name, const ConfigValue& val) { 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; } Loading biometrics/common/config/include/config/Config.h +27 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,33 @@ class Config { 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); Loading biometrics/common/config/tests/ConfigTest.cpp +6 −17 Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ class ConfigTest : public ::testing::Test { void SetUp() override { cfg.init(); } void TearDown() override {} void switch2aidl() { cfg.setParam("astring", "astring"); } void switch2aidl() { cfg.sourcedFromAidl(); } TestConfig cfg; }; Loading @@ -129,7 +129,6 @@ TEST_F(ConfigTest, parseInt32) { {"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), Loading @@ -143,8 +142,10 @@ TEST_F(ConfigTest, parseInt64) { 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), Loading @@ -160,8 +161,6 @@ TEST_F(ConfigTest, parseBool) { } 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), Loading @@ -174,9 +173,7 @@ TEST_F(ConfigTest, parseIntVec) { 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); } Loading Loading @@ -255,12 +252,4 @@ TEST_F(ConfigTest, setters_aidl) { 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 biometrics/fingerprint/aidl/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -57,5 +57,5 @@ aidl_interface { }, ], frozen: true, frozen: false, } biometrics/fingerprint/aidl/aidl_api/android.hardware.biometrics.fingerprint/current/android/hardware/biometrics/fingerprint/IVirtualHal.aidl 0 → 100644 +68 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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. */ /////////////////////////////////////////////////////////////////////////////// // THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // /////////////////////////////////////////////////////////////////////////////// // This file is a snapshot of an AIDL file. Do not edit it manually. There are // two cases: // 1). this is a frozen version file - do not edit this in any case. // 2). this is a 'current' file. If you make a backwards compatible change to // the interface (from the latest frozen version), the build system will // prompt you to update this file with `m <name>-update-api`. // // You must not make a backward incompatible change to any AIDL file built // with the aidl_interface module type with versions property set. The module // type is used to build AIDL files in a way that they can be used across // independently updatable components of the system. If a device is shipped // with such a backward incompatible change, it has a high risk of breaking // later when a module using the interface is updated, e.g., Mainline modules. package android.hardware.biometrics.fingerprint; /* @hide */ @VintfStability interface IVirtualHal { oneway void setEnrollments(in int[] id); oneway void setEnrollmentHit(in int hit_id); oneway void setAuthenticatorId(in long id); oneway void setChallenge(in long challenge); oneway void setOperationAuthenticateFails(in boolean fail); oneway void setOperationAuthenticateLatency(in int[] latencyMs); oneway void setOperationAuthenticateDuration(in int durationMs); oneway void setOperationAuthenticateError(in int error); oneway void setOperationAuthenticateAcquired(in int[] acquired); oneway void setOperationEnrollError(in int error); oneway void setOperationEnrollLatency(in int[] latencyMs); oneway void setOperationDetectInteractionLatency(in int[] latencyMs); oneway void setOperationDetectInteractionError(in int error); oneway void setOperationDetectInteractionDuration(in int durationMs); oneway void setOperationDetectInteractionAcquired(in int[] acquired); oneway void setLockout(in boolean lockout); oneway void setLockoutEnable(in boolean enable); oneway void setLockoutTimedThreshold(in int threshold); oneway void setLockoutTimedDuration(in int durationMs); oneway void setLockoutPermanentThreshold(in int threshold); oneway void setType(in android.hardware.biometrics.fingerprint.FingerprintSensorType type); oneway void setSensorId(in int id); oneway void setSensorStrength(in android.hardware.biometrics.common.SensorStrength strength); oneway void setMaxEnrollmentPerUser(in int max); oneway void setSensorLocation(in android.hardware.biometrics.fingerprint.SensorLocation loc); oneway void setNavigationGuesture(in boolean v); oneway void setDetectInteraction(in boolean v); oneway void setDisplayTouch(in boolean v); oneway void setControlIllumination(in boolean v); const int STATUS_INVALID_PARAMETER = 1; } Loading
biometrics/common/config/Config.cpp +15 −9 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ ConfigValue Config::parseBool(const std::string& value) { else if (value == "false") res.emplace(false); else LOG(ERROR) << "ERROR: invalid bool " << value; LOG(FATAL) << "ERROR: invalid bool " << value; return res; } Loading @@ -48,7 +48,11 @@ ConfigValue Config::parseInt32(const std::string& value) { 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; } Loading @@ -59,6 +63,8 @@ ConfigValue Config::parseInt64(const std::string& value) { 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; Loading Loading @@ -87,7 +93,7 @@ void Config::init() { 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; Loading @@ -102,7 +108,7 @@ bool Config::setParam(const std::string& name, const std::string& value) { 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(); Loading @@ -111,10 +117,10 @@ ConfigValue Config::getInternal(const std::string& name) { 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; } Loading @@ -127,7 +133,7 @@ ConfigValue Config::getDefault(const std::string& name) { 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: Loading @@ -138,10 +144,10 @@ bool Config::setInternal(const std::string& name, const ConfigValue& val) { 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; } Loading
biometrics/common/config/include/config/Config.h +27 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,33 @@ class Config { 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); Loading
biometrics/common/config/tests/ConfigTest.cpp +6 −17 Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ class ConfigTest : public ::testing::Test { void SetUp() override { cfg.init(); } void TearDown() override {} void switch2aidl() { cfg.setParam("astring", "astring"); } void switch2aidl() { cfg.sourcedFromAidl(); } TestConfig cfg; }; Loading @@ -129,7 +129,6 @@ TEST_F(ConfigTest, parseInt32) { {"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), Loading @@ -143,8 +142,10 @@ TEST_F(ConfigTest, parseInt64) { 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), Loading @@ -160,8 +161,6 @@ TEST_F(ConfigTest, parseBool) { } 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), Loading @@ -174,9 +173,7 @@ TEST_F(ConfigTest, parseIntVec) { 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); } Loading Loading @@ -255,12 +252,4 @@ TEST_F(ConfigTest, setters_aidl) { 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
biometrics/fingerprint/aidl/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -57,5 +57,5 @@ aidl_interface { }, ], frozen: true, frozen: false, }
biometrics/fingerprint/aidl/aidl_api/android.hardware.biometrics.fingerprint/current/android/hardware/biometrics/fingerprint/IVirtualHal.aidl 0 → 100644 +68 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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. */ /////////////////////////////////////////////////////////////////////////////// // THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // /////////////////////////////////////////////////////////////////////////////// // This file is a snapshot of an AIDL file. Do not edit it manually. There are // two cases: // 1). this is a frozen version file - do not edit this in any case. // 2). this is a 'current' file. If you make a backwards compatible change to // the interface (from the latest frozen version), the build system will // prompt you to update this file with `m <name>-update-api`. // // You must not make a backward incompatible change to any AIDL file built // with the aidl_interface module type with versions property set. The module // type is used to build AIDL files in a way that they can be used across // independently updatable components of the system. If a device is shipped // with such a backward incompatible change, it has a high risk of breaking // later when a module using the interface is updated, e.g., Mainline modules. package android.hardware.biometrics.fingerprint; /* @hide */ @VintfStability interface IVirtualHal { oneway void setEnrollments(in int[] id); oneway void setEnrollmentHit(in int hit_id); oneway void setAuthenticatorId(in long id); oneway void setChallenge(in long challenge); oneway void setOperationAuthenticateFails(in boolean fail); oneway void setOperationAuthenticateLatency(in int[] latencyMs); oneway void setOperationAuthenticateDuration(in int durationMs); oneway void setOperationAuthenticateError(in int error); oneway void setOperationAuthenticateAcquired(in int[] acquired); oneway void setOperationEnrollError(in int error); oneway void setOperationEnrollLatency(in int[] latencyMs); oneway void setOperationDetectInteractionLatency(in int[] latencyMs); oneway void setOperationDetectInteractionError(in int error); oneway void setOperationDetectInteractionDuration(in int durationMs); oneway void setOperationDetectInteractionAcquired(in int[] acquired); oneway void setLockout(in boolean lockout); oneway void setLockoutEnable(in boolean enable); oneway void setLockoutTimedThreshold(in int threshold); oneway void setLockoutTimedDuration(in int durationMs); oneway void setLockoutPermanentThreshold(in int threshold); oneway void setType(in android.hardware.biometrics.fingerprint.FingerprintSensorType type); oneway void setSensorId(in int id); oneway void setSensorStrength(in android.hardware.biometrics.common.SensorStrength strength); oneway void setMaxEnrollmentPerUser(in int max); oneway void setSensorLocation(in android.hardware.biometrics.fingerprint.SensorLocation loc); oneway void setNavigationGuesture(in boolean v); oneway void setDetectInteraction(in boolean v); oneway void setDisplayTouch(in boolean v); oneway void setControlIllumination(in boolean v); const int STATUS_INVALID_PARAMETER = 1; }