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