blob: 68b0f0d0deaf0fe4791cc4f4ec8722c832be8252 [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()
Jeff Pudef5b042023-05-25 14:28:16 -040034 : FakeFingerprintEngine(), mPointerDownTime(0), mUiReadyTime(0) {}
Jeff Pu52653182022-10-12 16:27:23 -040035
Jeff Pu63f33c72022-07-28 16:06:23 -040036SensorLocation FakeFingerprintEngineUdfps::defaultSensorLocation() {
Jeff Pudef5b042023-05-25 14:28:16 -040037 return SensorLocation{.sensorLocationX = defaultSensorLocationX,
38 .sensorLocationY = defaultSensorLocationY,
39 .sensorRadius = defaultSensorRadius};
Jeff Pu63f33c72022-07-28 16:06:23 -040040}
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() {
Jeff Pudef5b042023-05-25 14:28:16 -040073 FakeFingerprintEngine::fingerDownAction();
Jeff Pu52653182022-10-12 16:27:23 -040074 mUiReadyTime = 0;
75 mPointerDownTime = 0;
76}
77
Jeff Pu52653182022-10-12 16:27:23 -040078void FakeFingerprintEngineUdfps::updateContext(WorkMode mode, ISessionCallback* cb,
79 std::future<void>& cancel, int64_t operationId,
80 const keymaster::HardwareAuthToken& hat) {
Jeff Pudef5b042023-05-25 14:28:16 -040081 FakeFingerprintEngine::updateContext(mode, cb, cancel, operationId, hat);
Jeff Pu52653182022-10-12 16:27:23 -040082 mPointerDownTime = 0;
83 mUiReadyTime = 0;
Jeff Pu52653182022-10-12 16:27:23 -040084}
85
Jeff Pu63f33c72022-07-28 16:06:23 -040086} // namespace aidl::android::hardware::biometrics::fingerprint