• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
getDefaultSensorLocation(std::vector<SensorLocation> & sensorLocation)37 void FakeFingerprintEngineUdfps::getDefaultSensorLocation(
38         std::vector<SensorLocation>& sensorLocation) {
39     sensorLocation.clear();
40     sensorLocation.push_back(SensorLocation{
41             .sensorLocationX = defaultSensorLocationX,
42             .sensorLocationY = defaultSensorLocationY,
43             .sensorRadius = defaultSensorRadius,
44     });
45 }
46 
onPointerDownImpl(int32_t,int32_t,int32_t,float,float)47 ndk::ScopedAStatus FakeFingerprintEngineUdfps::onPointerDownImpl(int32_t /*pointerId*/,
48                                                                  int32_t /*x*/, int32_t /*y*/,
49                                                                  float /*minor*/, float /*major*/) {
50     BEGIN_OP(0);
51     // verify whetehr touch coordinates/area matching sensor location ?
52     mPointerDownTime = Util::getSystemNanoTime();
53     if (Fingerprint::cfg().get<bool>("control_illumination")) {
54         fingerDownAction();
55     }
56     return ndk::ScopedAStatus::ok();
57 }
58 
onPointerUpImpl(int32_t)59 ndk::ScopedAStatus FakeFingerprintEngineUdfps::onPointerUpImpl(int32_t /*pointerId*/) {
60     BEGIN_OP(0);
61     mUiReadyTime = 0;
62     mPointerDownTime = 0;
63     return ndk::ScopedAStatus::ok();
64 }
65 
onUiReadyImpl()66 ndk::ScopedAStatus FakeFingerprintEngineUdfps::onUiReadyImpl() {
67     BEGIN_OP(0);
68 
69     if (Util::hasElapsed(mPointerDownTime, uiReadyTimeoutInMs * 100)) {
70         LOG(ERROR) << "onUiReady() arrives too late after onPointerDown()";
71     } else {
72         fingerDownAction();
73     }
74     return ndk::ScopedAStatus::ok();
75 }
76 
fingerDownAction()77 void FakeFingerprintEngineUdfps::fingerDownAction() {
78     FakeFingerprintEngine::fingerDownAction();
79     mUiReadyTime = 0;
80     mPointerDownTime = 0;
81 }
82 
updateContext(WorkMode mode,ISessionCallback * cb,std::future<void> & cancel,int64_t operationId,const keymaster::HardwareAuthToken & hat)83 void FakeFingerprintEngineUdfps::updateContext(WorkMode mode, ISessionCallback* cb,
84                                                std::future<void>& cancel, int64_t operationId,
85                                                const keymaster::HardwareAuthToken& hat) {
86     FakeFingerprintEngine::updateContext(mode, cb, cancel, operationId, hat);
87     mPointerDownTime = 0;
88     mUiReadyTime = 0;
89 }
90 
91 }  // namespace aidl::android::hardware::biometrics::fingerprint
92