diff --git a/biometrics/fingerprint/2.2/Android.bp b/biometrics/fingerprint/2.2/Android.bp new file mode 100644 index 0000000000..6c769ac22e --- /dev/null +++ b/biometrics/fingerprint/2.2/Android.bp @@ -0,0 +1,19 @@ +// This file is autogenerated by hidl-gen -Landroidbp. + +hidl_interface { + name: "android.hardware.biometrics.fingerprint@2.2", + root: "android.hardware", + vndk: { + enabled: true, + }, + srcs: [ + "types.hal", + "IBiometricsFingerprint.hal", + "IBiometricsFingerprintClientCallback.hal", + ], + interfaces: [ + "android.hardware.biometrics.fingerprint@2.1", + "android.hidl.base@1.0", + ], + gen_java: true, +} diff --git a/biometrics/fingerprint/2.2/IBiometricsFingerprint.hal b/biometrics/fingerprint/2.2/IBiometricsFingerprint.hal new file mode 100644 index 0000000000..06510344ef --- /dev/null +++ b/biometrics/fingerprint/2.2/IBiometricsFingerprint.hal @@ -0,0 +1,58 @@ +/* + * Copyright 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. + */ + +package android.hardware.biometrics.fingerprint@2.2; + +import @2.1::IBiometricsFingerprint; +import @2.1::RequestStatus; + +interface IBiometricsFingerprint extends @2.1::IBiometricsFingerprint { + /** + * Fingerprint enroll request: + * Switches the HAL state machine to collect and store a new fingerprint + * template. Switches back as soon as enroll is complete, signalled by + * (fingerprintMsg.type == FINGERPRINT_TEMPLATE_ENROLLING && + * fingerprintMsg.data.enroll.samplesRemaining == 0) + * or after timeoutSec seconds. + * The fingerprint template must be assigned to the group gid. + * + * @param hat a valid Hardware Authentication Token (HAT), generated + * as a result of a preEnroll() call. + * @param gid a framework defined fingerprint set (group) id. + * @param timeoutSec a timeout in seconds. + * @param windowId optional ID of an illumination window for optical under + * display fingerprint sensors. Must contain a null pointer if not used. + * + * @return debugErrno is a value the framework logs in case it is not 0. + * + * A notify() function may be called with a more detailed error structure. + */ + enroll_2_2(vec hat, uint32_t gid, uint32_t timeoutSec, handle windowId) + generates (RequestStatus debugErrno); + + /** + * Authenticates an operation identified by operationId + * + * @param operationId operation id. + * @param gid fingerprint group id. + * @param windowId optional ID of an illumination window for optical under + * display fingerprint sensors. Must contain a null pointer if not used. + * + * @return debugErrno is a value the framework logs in case it is not 0. + */ + authenticate_2_2(uint64_t operationId, uint32_t gid, handle windowId) + generates (RequestStatus debugErrno); +}; diff --git a/biometrics/fingerprint/2.2/IBiometricsFingerprintClientCallback.hal b/biometrics/fingerprint/2.2/IBiometricsFingerprintClientCallback.hal new file mode 100644 index 0000000000..14c2b12b76 --- /dev/null +++ b/biometrics/fingerprint/2.2/IBiometricsFingerprintClientCallback.hal @@ -0,0 +1,35 @@ +/* + * Copyright 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. + */ + +package android.hardware.biometrics.fingerprint@2.2; + +import @2.1::IBiometricsFingerprintClientCallback; + +/* + * This HAL interface communicates asynchronous results from the + * fingerprint driver in response to user actions on the fingerprint sensor + */ +interface IBiometricsFingerprintClientCallback extends @2.1::IBiometricsFingerprintClientCallback { + /** + * Sent when a fingerprint image is acquired by the sensor + * @param deviceId the instance of this fingerprint device + * @param acquiredInfo a message about the quality of the acquired image + * @param vendorCode a vendor-specific message about the quality of the image. Only + * valid when acquiredInfo == ACQUIRED_VENDOR + */ + oneway onAcquired_2_2(uint64_t deviceId, FingerprintAcquiredInfo acquiredInfo, + int32_t vendorCode); +}; diff --git a/biometrics/fingerprint/2.2/types.hal b/biometrics/fingerprint/2.2/types.hal new file mode 100644 index 0000000000..2c1d3f374c --- /dev/null +++ b/biometrics/fingerprint/2.2/types.hal @@ -0,0 +1,42 @@ +/* + * Copyright 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. + */ + +package android.hardware.biometrics.fingerprint@2.2; + +import @2.1::FingerprintAcquiredInfo; + +/** + * Fingerprint acquisition info is meant as feedback for the current operation. + * Anything but START and ACQUIRED_GOOD must be shown to the user as feedback on + * how to take action on the current operation. For example, + * ACQUIRED_IMAGER_DIRTY may be used to tell the user to clean the sensor if it + * is detected to be dirty. + * If this causes the current operation to fail, an additional ERROR_CANCELED + * must be sent to stop the operation in progress (e.g. enrollment). + * In general, these messages will result in a "Try again" message. + */ +enum FingerprintAcquiredInfo : @2.1::FingerprintAcquiredInfo { + /** + * This message represents the earliest message sent at the beginning of the + * authentication pipeline. It is expected to be used to measure latency. For + * example, in a camera-based authentication system it's expected to be sent + * prior to camera initialization. Note this should be sent whenever + * authentication is restarted (see IBiometricsFace#userActivity). + * The framework will measure latency based on the time between the last START + * message and the onAuthenticated callback. + */ + START = 7, +}; diff --git a/biometrics/fingerprint/2.2/vts/functional/Android.bp b/biometrics/fingerprint/2.2/vts/functional/Android.bp new file mode 100644 index 0000000000..496570c64c --- /dev/null +++ b/biometrics/fingerprint/2.2/vts/functional/Android.bp @@ -0,0 +1,29 @@ +/* + * Copyright 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. + */ + +cc_test { + name: "VtsHalBiometricsFingerprintV2_2TargetTest", + defaults: ["VtsHalTargetTestDefaults"], + srcs: ["VtsHalBiometricsFingerprintV2_2TargetTest.cpp"], + static_libs: [ + "android.hardware.biometrics.fingerprint@2.1", + "android.hardware.biometrics.fingerprint@2.2", + ], + test_suites: [ + "general-tests", + "vts-core", + ], +} diff --git a/biometrics/fingerprint/2.2/vts/functional/VtsHalBiometricsFingerprintV2_2TargetTest.cpp b/biometrics/fingerprint/2.2/vts/functional/VtsHalBiometricsFingerprintV2_2TargetTest.cpp new file mode 100644 index 0000000000..50bd4ab5e0 --- /dev/null +++ b/biometrics/fingerprint/2.2/vts/functional/VtsHalBiometricsFingerprintV2_2TargetTest.cpp @@ -0,0 +1,166 @@ +/* + * 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. + */ + +#define LOG_TAG "fingerprint_hidl_hal_test" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using android::sp; +using android::base::GetUintProperty; +using android::hardware::hidl_handle; +using android::hardware::hidl_vec; +using android::hardware::Return; +using android::hardware::Void; +using android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo; +using android::hardware::biometrics::fingerprint::V2_1::FingerprintError; +using android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback; +using android::hardware::biometrics::fingerprint::V2_1::RequestStatus; +using android::hardware::biometrics::fingerprint::V2_2::IBiometricsFingerprint; + +namespace { + +constexpr uint32_t kTimeoutSec = 3; +constexpr auto kTimeout = std::chrono::seconds(kTimeoutSec); +constexpr uint32_t kGroupId = 99; +constexpr char kCallbackNameOnError[] = "onError"; + +// Callback arguments that need to be captured for the tests. +struct FingerprintCallbackArgs { + // The error passed to the last onError() callback. + FingerprintError error; + + // The deviceId passed to the last callback. + uint64_t deviceId; +}; + +// Test callback class for the BiometricsFingerprint HAL. +// The HAL will call these callback methods to notify about completed operations +// or encountered errors. +class FingerprintCallback : public ::testing::VtsHalHidlTargetCallbackBase, + public IBiometricsFingerprintClientCallback { + public: + Return onEnrollResult(uint64_t, uint32_t, uint32_t, uint32_t) override { return Void(); } + + Return onAcquired(uint64_t, FingerprintAcquiredInfo, int32_t) override { return Void(); } + + Return onAuthenticated(uint64_t, uint32_t, uint32_t, const hidl_vec&) override { + return Void(); + } + + Return onError(uint64_t deviceId, FingerprintError error, int32_t) override { + FingerprintCallbackArgs args = {}; + args.error = error; + args.deviceId = deviceId; + NotifyFromCallback(kCallbackNameOnError, args); + return Void(); + } + + Return onRemoved(uint64_t, uint32_t, uint32_t, uint32_t) override { return Void(); } + + Return onEnumerate(uint64_t, uint32_t, uint32_t, uint32_t) override { return Void(); } +}; + +class FingerprintHidlTest : public ::testing::TestWithParam { + public: + void SetUp() override { + mService = IBiometricsFingerprint::getService(GetParam()); + ASSERT_NE(mService, nullptr); + mCallback = new FingerprintCallback(); + mCallback->SetWaitTimeoutDefault(kTimeout); + Return ret1 = mService->setNotify(mCallback); + ASSERT_NE(0UL, static_cast(ret1)); + + /* + * Devices shipped from now on will instead store + * fingerprint data under /data/vendor_de//fpdata. + * Support for /data/vendor_de and /data/vendor_ce has been added to vold. + */ + + auto api_level = GetUintProperty("ro.product.first_api_level", 0); + if (api_level == 0) { + api_level = GetUintProperty("ro.build.version.sdk", 0); + } + ASSERT_NE(api_level, 0); + + // 27 is the API number for O-MR1 + string tmpDir; + if (api_level <= 27) { + tmpDir = "/data/system/users/0/fpdata/"; + } else { + tmpDir = "/data/vendor_de/0/fpdata/"; + } + + Return res = mService->setActiveGroup(kGroupId, tmpDir); + ASSERT_EQ(RequestStatus::SYS_OK, static_cast(res)); + } + + sp mService; + sp mCallback; +}; + +// Enroll with an invalid (all zeroes) HAT should fail. +TEST_P(FingerprintHidlTest, EnrollZeroHatTest) { + // Filling HAT with zeros + hidl_vec token(69); + for (size_t i = 0; i < 69; i++) { + token[i] = 0; + } + + hidl_handle windowId = nullptr; + Return ret = mService->enroll_2_2(token, kGroupId, kTimeoutSec, windowId); + ASSERT_EQ(RequestStatus::SYS_OK, static_cast(ret)); + + // At least one call to onError should occur + auto res = mCallback->WaitForCallback(kCallbackNameOnError); + ASSERT_NE(FingerprintError::ERROR_NO_ERROR, res.args->error); +} + +// Enroll with an invalid (null) HAT should fail. +TEST_P(FingerprintHidlTest, EnrollGarbageHatTest) { + // Filling HAT with pseudorandom invalid data. + // Using default seed to make the test reproducible. + std::mt19937 gen(std::mt19937::default_seed); + std::uniform_int_distribution dist; + hidl_vec token(69); + for (size_t i = 0; i < 69; ++i) { + token[i] = dist(gen); + } + + hidl_handle windowId = nullptr; + Return ret = mService->enroll_2_2(token, kGroupId, kTimeoutSec, windowId); + ASSERT_EQ(RequestStatus::SYS_OK, static_cast(ret)); + + // At least one call to onError should occur + auto res = mCallback->WaitForCallback(kCallbackNameOnError); + ASSERT_NE(FingerprintError::ERROR_NO_ERROR, res.args->error); +} + +} // anonymous namespace + +INSTANTIATE_TEST_SUITE_P(PerInstance, FingerprintHidlTest, + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + IBiometricsFingerprint::descriptor)), + android::hardware::PrintInstanceNameToString);