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