Remove SessionState from IFace VTS

Bug: 183570051
Test: atest VtsHalBiometricsFaceTargetTest
Change-Id: I2b106449cbafeaff1d683eb4ef87e022e12b4ee0
This commit is contained in:
Ilya Matyukhin
2021-03-23 23:08:41 -07:00
parent 66c6464a13
commit cc2b6943c6

View File

@@ -21,35 +21,31 @@
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <chrono>
#include <future>
namespace aidl::android::hardware::biometrics::face {
namespace {
using namespace std::literals::chrono_literals;
constexpr int kSensorId = 0;
constexpr int kUserId = 0;
constexpr auto kCallbackTimeout = std::chrono::seconds(1);
enum class SessionCallbackMethodName {
kOnStateChanged,
enum class MethodName {
kOnError,
kOnSessionClosed,
};
struct SessionCallbackInvocation {
SessionCallbackMethodName method_name;
SessionState state;
struct Invocation {
MethodName methodName;
Error error;
int32_t vendorCode;
};
class SessionCallback : public BnSessionCallback {
public:
explicit SessionCallback(std::promise<SessionCallbackInvocation> invocation_promise)
: invocation_promise_(std::move(invocation_promise)) {}
ndk::ScopedAStatus onStateChanged(int32_t /*cookie*/, SessionState state) override {
SessionCallbackInvocation invocation = {};
invocation.method_name = SessionCallbackMethodName::kOnStateChanged;
invocation.state = state;
invocation_promise_.set_value(invocation);
return ndk::ScopedAStatus::ok();
}
explicit SessionCallback(Invocation* inv) : mInv(inv) {}
ndk::ScopedAStatus onChallengeGenerated(int64_t /*challenge*/) override {
return ndk::ScopedAStatus::ok();
@@ -67,7 +63,12 @@ class SessionCallback : public BnSessionCallback {
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus onError(Error /*error*/, int32_t /*vendorCode*/) override {
ndk::ScopedAStatus onError(Error error, int32_t vendorCode) override {
*mInv = {};
mInv->methodName = MethodName::kOnError;
mInv->error = error;
mInv->vendorCode = vendorCode;
return ndk::ScopedAStatus::ok();
}
@@ -120,10 +121,15 @@ class SessionCallback : public BnSessionCallback {
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus onSessionClosed() override { return ndk::ScopedAStatus::ok(); }
ndk::ScopedAStatus onSessionClosed() override {
*mInv = {};
mInv->methodName = MethodName::kOnSessionClosed;
return ndk::ScopedAStatus::ok();
}
private:
std::promise<SessionCallbackInvocation> invocation_promise_;
Invocation* mInv;
};
class Face : public testing::TestWithParam<std::string> {
@@ -131,28 +137,34 @@ class Face : public testing::TestWithParam<std::string> {
void SetUp() override {
AIBinder* binder = AServiceManager_waitForService(GetParam().c_str());
ASSERT_NE(binder, nullptr);
hal_ = IFace::fromBinder(ndk::SpAIBinder(binder));
mHal = IFace::fromBinder(ndk::SpAIBinder(binder));
}
std::shared_ptr<IFace> hal_;
std::shared_ptr<IFace> mHal;
Invocation mInv;
};
TEST_P(Face, AuthenticateTest) {
std::promise<SessionCallbackInvocation> invocation_promise;
std::future<SessionCallbackInvocation> invocation_future = invocation_promise.get_future();
std::shared_ptr<SessionCallback> session_cb =
ndk::SharedRefBase::make<SessionCallback>(std::move(invocation_promise));
// Prepare the callback.
auto cb = ndk::SharedRefBase::make<SessionCallback>(&mInv);
// Create a session
std::shared_ptr<ISession> session;
ASSERT_TRUE(hal_->createSession(kSensorId, kUserId, session_cb, &session).isOk());
ASSERT_TRUE(mHal->createSession(kSensorId, kUserId, cb, &session).isOk());
std::shared_ptr<common::ICancellationSignal> cancel_cb;
ASSERT_TRUE(session->authenticate(0, 0, &cancel_cb).isOk());
ASSERT_EQ(invocation_future.wait_for(kCallbackTimeout), std::future_status::ready);
// Call authenticate
std::shared_ptr<common::ICancellationSignal> cancellationSignal;
ASSERT_TRUE(session->authenticate(0 /* operationId */, &cancellationSignal).isOk());
SessionCallbackInvocation invocation = invocation_future.get();
EXPECT_EQ(invocation.method_name, SessionCallbackMethodName::kOnStateChanged);
EXPECT_EQ(invocation.state, SessionState::AUTHENTICATING);
// Get the results
EXPECT_EQ(mInv.methodName, MethodName::kOnError);
EXPECT_EQ(mInv.error, Error::UNABLE_TO_PROCESS);
EXPECT_EQ(mInv.vendorCode, 0);
// Close the session
ASSERT_TRUE(session->close().isOk());
EXPECT_EQ(mInv.methodName, MethodName::kOnSessionClosed);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(Face);
@@ -161,6 +173,7 @@ INSTANTIATE_TEST_SUITE_P(IFace, Face,
::android::PrintInstanceNameToString);
} // namespace
} // namespace aidl::android::hardware::biometrics::face
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
@@ -169,4 +182,3 @@ int main(int argc, char** argv) {
return RUN_ALL_TESTS();
}
} // namespace aidl::android::hardware::biometrics::face