1 /*
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
26 #undef LOG_TAG
27 #define LOG_TAG "FingerprintVirtualHalUdfps"
28
29 using namespace ::android::fingerprint::virt;
30
31 namespace aidl::android::hardware::biometrics::fingerprint {
32
FakeFingerprintEngineUdfps()33 FakeFingerprintEngineUdfps::FakeFingerprintEngineUdfps()
34 : FakeFingerprintEngine(), mPointerDownTime(0), mUiReadyTime(0) {}
35
defaultSensorLocation()36 SensorLocation FakeFingerprintEngineUdfps::defaultSensorLocation() {
37 return SensorLocation{.sensorLocationX = defaultSensorLocationX,
38 .sensorLocationY = defaultSensorLocationY,
39 .sensorRadius = defaultSensorRadius};
40 }
41
onPointerDownImpl(int32_t,int32_t,int32_t,float,float)42 ndk::ScopedAStatus FakeFingerprintEngineUdfps::onPointerDownImpl(int32_t /*pointerId*/,
43 int32_t /*x*/, int32_t /*y*/,
44 float /*minor*/, float /*major*/) {
45 BEGIN_OP(0);
46 // verify whetehr touch coordinates/area matching sensor location ?
47 mPointerDownTime = Util::getSystemNanoTime();
48 if (FingerprintHalProperties::control_illumination().value_or(false)) {
49 fingerDownAction();
50 }
51 return ndk::ScopedAStatus::ok();
52 }
53
onPointerUpImpl(int32_t)54 ndk::ScopedAStatus FakeFingerprintEngineUdfps::onPointerUpImpl(int32_t /*pointerId*/) {
55 BEGIN_OP(0);
56 mUiReadyTime = 0;
57 mPointerDownTime = 0;
58 return ndk::ScopedAStatus::ok();
59 }
60
onUiReadyImpl()61 ndk::ScopedAStatus FakeFingerprintEngineUdfps::onUiReadyImpl() {
62 BEGIN_OP(0);
63
64 if (Util::hasElapsed(mPointerDownTime, uiReadyTimeoutInMs * 100)) {
65 LOG(ERROR) << "onUiReady() arrives too late after onPointerDown()";
66 } else {
67 fingerDownAction();
68 }
69 return ndk::ScopedAStatus::ok();
70 }
71
fingerDownAction()72 void FakeFingerprintEngineUdfps::fingerDownAction() {
73 FakeFingerprintEngine::fingerDownAction();
74 mUiReadyTime = 0;
75 mPointerDownTime = 0;
76 }
77
updateContext(WorkMode mode,ISessionCallback * cb,std::future<void> & cancel,int64_t operationId,const keymaster::HardwareAuthToken & hat)78 void FakeFingerprintEngineUdfps::updateContext(WorkMode mode, ISessionCallback* cb,
79 std::future<void>& cancel, int64_t operationId,
80 const keymaster::HardwareAuthToken& hat) {
81 FakeFingerprintEngine::updateContext(mode, cb, cancel, operationId, hat);
82 mPointerDownTime = 0;
83 mUiReadyTime = 0;
84 }
85
86 } // namespace aidl::android::hardware::biometrics::fingerprint
87