blob: 3cdfc700080201dc0e503a07344146a9fd749b79 [file] [log] [blame]
Jeff Pu63f33c72022-07-28 16:06:23 -04001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "FakeFingerprintEngineUdfps.h"
18
19#include <android-base/logging.h>
20
21#include <fingerprint.sysprop.h>
22
23#include "util/CancellationSignal.h"
24#include "util/Util.h"
25
Jeff Pu52653182022-10-12 16:27:23 -040026#undef LOG_TAG
27#define LOG_TAG "FingerprintVirtualHalUdfps"
28
Jeff Pu63f33c72022-07-28 16:06:23 -040029using namespace ::android::fingerprint::virt;
30
31namespace aidl::android::hardware::biometrics::fingerprint {
32
Jeff Pu52653182022-10-12 16:27:23 -040033FakeFingerprintEngineUdfps::FakeFingerprintEngineUdfps()
34 : FakeFingerprintEngine(), mWorkMode(WorkMode::kIdle), mPointerDownTime(0), mUiReadyTime(0) {}
35
Jeff Pu63f33c72022-07-28 16:06:23 -040036SensorLocation FakeFingerprintEngineUdfps::defaultSensorLocation() {
37 return {0 /* displayId (not used) */, defaultSensorLocationX /* sensorLocationX */,
38 defaultSensorLocationY /* sensorLocationY */, defaultSensorRadius /* sensorRadius */,
39 "" /* display */};
40}
41
42ndk::ScopedAStatus FakeFingerprintEngineUdfps::onPointerDownImpl(int32_t /*pointerId*/,
43 int32_t /*x*/, int32_t /*y*/,
44 float /*minor*/, float /*major*/) {
45 BEGIN_OP(0);
Jeff Pu52653182022-10-12 16:27:23 -040046 // verify whetehr touch coordinates/area matching sensor location ?
47 mPointerDownTime = Util::getSystemNanoTime();
48 if (FingerprintHalProperties::control_illumination().value_or(false)) {
49 fingerDownAction();
50 }
Jeff Pu63f33c72022-07-28 16:06:23 -040051 return ndk::ScopedAStatus::ok();
52}
53
54ndk::ScopedAStatus FakeFingerprintEngineUdfps::onPointerUpImpl(int32_t /*pointerId*/) {
55 BEGIN_OP(0);
Jeff Pu52653182022-10-12 16:27:23 -040056 mUiReadyTime = 0;
57 mPointerDownTime = 0;
Jeff Pu63f33c72022-07-28 16:06:23 -040058 return ndk::ScopedAStatus::ok();
59}
60
61ndk::ScopedAStatus FakeFingerprintEngineUdfps::onUiReadyImpl() {
62 BEGIN_OP(0);
Jeff Pu52653182022-10-12 16:27:23 -040063
64 if (Util::hasElapsed(mPointerDownTime, uiReadyTimeoutInMs * 100)) {
65 LOG(ERROR) << "onUiReady() arrives too late after onPointerDown()";
66 } else {
67 fingerDownAction();
68 }
Jeff Pu63f33c72022-07-28 16:06:23 -040069 return ndk::ScopedAStatus::ok();
70}
71
Jeff Pu52653182022-10-12 16:27:23 -040072void FakeFingerprintEngineUdfps::fingerDownAction() {
73 switch (mWorkMode) {
74 case WorkMode::kAuthenticate:
75 onAuthenticateFingerDown();
76 break;
77 case WorkMode::kEnroll:
78 onEnrollFingerDown();
79 break;
80 case WorkMode::kDetectInteract:
81 onDetectInteractFingerDown();
82 break;
83 default:
84 LOG(WARNING) << "unexpected call: onUiReady()";
85 break;
86 }
87
88 mUiReadyTime = 0;
89 mPointerDownTime = 0;
90}
91
92void FakeFingerprintEngineUdfps::onAuthenticateFingerDown() {
93 FakeFingerprintEngine::authenticateImpl(mCb, mOperationId, mCancelVec[0]);
94}
95
96void FakeFingerprintEngineUdfps::onEnrollFingerDown() {
97 // Any use case to emulate display touch for each capture during enrollment?
98 FakeFingerprintEngine::enrollImpl(mCb, mHat, mCancelVec[0]);
99}
100
101void FakeFingerprintEngineUdfps::onDetectInteractFingerDown() {
102 FakeFingerprintEngine::detectInteractionImpl(mCb, mCancelVec[0]);
103}
104
105void FakeFingerprintEngineUdfps::enrollImpl(ISessionCallback* cb,
106 const keymaster::HardwareAuthToken& hat,
107 const std::future<void>& cancel) {
108 updateContext(WorkMode::kEnroll, cb, const_cast<std::future<void>&>(cancel), 0, hat);
109}
110
111void FakeFingerprintEngineUdfps::authenticateImpl(ISessionCallback* cb, int64_t operationId,
112 const std::future<void>& cancel) {
113 updateContext(WorkMode::kAuthenticate, cb, const_cast<std::future<void>&>(cancel), operationId,
114 keymaster::HardwareAuthToken());
115}
116
117void FakeFingerprintEngineUdfps::detectInteractionImpl(ISessionCallback* cb,
118 const std::future<void>& cancel) {
119 updateContext(WorkMode::kDetectInteract, cb, const_cast<std::future<void>&>(cancel), 0,
120 keymaster::HardwareAuthToken());
121}
122
123void FakeFingerprintEngineUdfps::updateContext(WorkMode mode, ISessionCallback* cb,
124 std::future<void>& cancel, int64_t operationId,
125 const keymaster::HardwareAuthToken& hat) {
126 mPointerDownTime = 0;
127 mUiReadyTime = 0;
128 mCancelVec.clear();
129
130 mCancelVec.push_back(std::move(cancel));
131 mWorkMode = mode;
132 mCb = cb;
133 mOperationId = operationId;
134 mHat = hat;
135}
136
Jeff Pu63f33c72022-07-28 16:06:23 -0400137} // namespace aidl::android::hardware::biometrics::fingerprint