blob: 496b5e3f12a666d94e05dec83619f6c3d44eba67 [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
Jeff Pu6ccd9562024-02-21 10:46:35 -050023#include "Fingerprint.h"
Jeff Pu63f33c72022-07-28 16:06:23 -040024#include "util/CancellationSignal.h"
25#include "util/Util.h"
26
Jeff Pu52653182022-10-12 16:27:23 -040027#undef LOG_TAG
28#define LOG_TAG "FingerprintVirtualHalUdfps"
29
Jeff Pu63f33c72022-07-28 16:06:23 -040030using namespace ::android::fingerprint::virt;
31
32namespace aidl::android::hardware::biometrics::fingerprint {
33
Jeff Pu52653182022-10-12 16:27:23 -040034FakeFingerprintEngineUdfps::FakeFingerprintEngineUdfps()
Jeff Pudef5b042023-05-25 14:28:16 -040035 : FakeFingerprintEngine(), mPointerDownTime(0), mUiReadyTime(0) {}
Jeff Pu52653182022-10-12 16:27:23 -040036
Jeff Pu63f33c72022-07-28 16:06:23 -040037SensorLocation FakeFingerprintEngineUdfps::defaultSensorLocation() {
Jeff Pudef5b042023-05-25 14:28:16 -040038 return SensorLocation{.sensorLocationX = defaultSensorLocationX,
39 .sensorLocationY = defaultSensorLocationY,
40 .sensorRadius = defaultSensorRadius};
Jeff Pu63f33c72022-07-28 16:06:23 -040041}
42
43ndk::ScopedAStatus FakeFingerprintEngineUdfps::onPointerDownImpl(int32_t /*pointerId*/,
44 int32_t /*x*/, int32_t /*y*/,
45 float /*minor*/, float /*major*/) {
46 BEGIN_OP(0);
Jeff Pu52653182022-10-12 16:27:23 -040047 // verify whetehr touch coordinates/area matching sensor location ?
48 mPointerDownTime = Util::getSystemNanoTime();
Jeff Pu6ccd9562024-02-21 10:46:35 -050049 if (Fingerprint::cfg().get<bool>("control_illumination")) {
Jeff Pu52653182022-10-12 16:27:23 -040050 fingerDownAction();
51 }
Jeff Pu63f33c72022-07-28 16:06:23 -040052 return ndk::ScopedAStatus::ok();
53}
54
55ndk::ScopedAStatus FakeFingerprintEngineUdfps::onPointerUpImpl(int32_t /*pointerId*/) {
56 BEGIN_OP(0);
Jeff Pu52653182022-10-12 16:27:23 -040057 mUiReadyTime = 0;
58 mPointerDownTime = 0;
Jeff Pu63f33c72022-07-28 16:06:23 -040059 return ndk::ScopedAStatus::ok();
60}
61
62ndk::ScopedAStatus FakeFingerprintEngineUdfps::onUiReadyImpl() {
63 BEGIN_OP(0);
Jeff Pu52653182022-10-12 16:27:23 -040064
65 if (Util::hasElapsed(mPointerDownTime, uiReadyTimeoutInMs * 100)) {
66 LOG(ERROR) << "onUiReady() arrives too late after onPointerDown()";
67 } else {
68 fingerDownAction();
69 }
Jeff Pu63f33c72022-07-28 16:06:23 -040070 return ndk::ScopedAStatus::ok();
71}
72
Jeff Pu52653182022-10-12 16:27:23 -040073void FakeFingerprintEngineUdfps::fingerDownAction() {
Jeff Pudef5b042023-05-25 14:28:16 -040074 FakeFingerprintEngine::fingerDownAction();
Jeff Pu52653182022-10-12 16:27:23 -040075 mUiReadyTime = 0;
76 mPointerDownTime = 0;
77}
78
Jeff Pu52653182022-10-12 16:27:23 -040079void FakeFingerprintEngineUdfps::updateContext(WorkMode mode, ISessionCallback* cb,
80 std::future<void>& cancel, int64_t operationId,
81 const keymaster::HardwareAuthToken& hat) {
Jeff Pudef5b042023-05-25 14:28:16 -040082 FakeFingerprintEngine::updateContext(mode, cb, cancel, operationId, hat);
Jeff Pu52653182022-10-12 16:27:23 -040083 mPointerDownTime = 0;
84 mUiReadyTime = 0;
Jeff Pu52653182022-10-12 16:27:23 -040085}
86
Jeff Pu63f33c72022-07-28 16:06:23 -040087} // namespace aidl::android::hardware::biometrics::fingerprint