Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 "Fingerprint.h" |
| 18 | #include "Session.h" |
| 19 | |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 20 | #include <fingerprint.sysprop.h> |
| 21 | |
| 22 | #include <android-base/file.h> |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 23 | #include <android-base/logging.h> |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 24 | #include <android-base/stringprintf.h> |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 25 | |
| 26 | using namespace ::android::fingerprint::virt; |
| 27 | |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 28 | namespace aidl::android::hardware::biometrics::fingerprint { |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 29 | namespace { |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 30 | constexpr size_t MAX_WORKER_QUEUE_SIZE = 5; |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 31 | constexpr int SENSOR_ID = 5; |
Kevin Chyn | 0ec2e0c | 2021-03-26 18:07:24 -0700 | [diff] [blame] | 32 | constexpr common::SensorStrength SENSOR_STRENGTH = common::SensorStrength::STRONG; |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 33 | constexpr int MAX_ENROLLMENTS_PER_USER = 5; |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 34 | constexpr bool SUPPORTS_NAVIGATION_GESTURES = true; |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 35 | constexpr char HW_COMPONENT_ID[] = "fingerprintSensor"; |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 36 | constexpr char HW_VERSION[] = "vendor/model/revision"; |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 37 | constexpr char FW_VERSION[] = "1.01"; |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 38 | constexpr char SERIAL_NUMBER[] = "00000001"; |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 39 | constexpr char SW_COMPONENT_ID[] = "matchingAlgorithm"; |
| 40 | constexpr char SW_VERSION[] = "vendor/version/revision"; |
Kevin Chyn | 7d3fdf5 | 2020-09-15 13:01:40 -0700 | [diff] [blame] | 41 | |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 42 | } // namespace |
Kevin Chyn | c306b76 | 2020-09-17 12:40:09 -0700 | [diff] [blame] | 43 | |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 44 | Fingerprint::Fingerprint() : mWorker(MAX_WORKER_QUEUE_SIZE) { |
| 45 | std::string sensorTypeProp = FingerprintHalProperties::type().value_or(""); |
| 46 | if (sensorTypeProp == "" || sensorTypeProp == "default" || sensorTypeProp == "rear") { |
| 47 | mSensorType = FingerprintSensorType::REAR; |
| 48 | mEngine = std::make_unique<FakeFingerprintEngineRear>(); |
| 49 | } else if (sensorTypeProp == "udfps") { |
| 50 | mSensorType = FingerprintSensorType::UNDER_DISPLAY_OPTICAL; |
| 51 | mEngine = std::make_unique<FakeFingerprintEngineUdfps>(); |
| 52 | } else if (sensorTypeProp == "side") { |
| 53 | mSensorType = FingerprintSensorType::POWER_BUTTON; |
| 54 | mEngine = std::make_unique<FakeFingerprintEngineSide>(); |
| 55 | } else { |
| 56 | mSensorType = FingerprintSensorType::UNKNOWN; |
| 57 | mEngine = std::make_unique<FakeFingerprintEngineRear>(); |
| 58 | UNIMPLEMENTED(FATAL) << "unrecognized or unimplemented fingerprint behavior: " |
| 59 | << sensorTypeProp; |
| 60 | } |
| 61 | LOG(INFO) << "sensorTypeProp:" << sensorTypeProp; |
| 62 | } |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 63 | |
| 64 | ndk::ScopedAStatus Fingerprint::getSensorProps(std::vector<SensorProps>* out) { |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 65 | std::vector<common::ComponentInfo> componentInfo = { |
| 66 | {HW_COMPONENT_ID, HW_VERSION, FW_VERSION, SERIAL_NUMBER, "" /* softwareVersion */}, |
| 67 | {SW_COMPONENT_ID, "" /* hardwareVersion */, "" /* firmwareVersion */, |
| 68 | "" /* serialNumber */, SW_VERSION}}; |
Jeff Pu | 343ca94 | 2022-09-14 15:56:30 -0400 | [diff] [blame] | 69 | auto sensorId = FingerprintHalProperties::sensor_id().value_or(SENSOR_ID); |
| 70 | auto sensorStrength = |
| 71 | FingerprintHalProperties::sensor_strength().value_or((int)SENSOR_STRENGTH); |
| 72 | auto maxEnrollments = |
| 73 | FingerprintHalProperties::max_enrollments().value_or(MAX_ENROLLMENTS_PER_USER); |
| 74 | auto navigationGuesture = FingerprintHalProperties::navigation_guesture().value_or(false); |
| 75 | auto detectInteraction = FingerprintHalProperties::detect_interaction().value_or(false); |
| 76 | auto displayTouch = FingerprintHalProperties::display_touch().value_or(true); |
| 77 | auto controlIllumination = FingerprintHalProperties::control_illumination().value_or(false); |
| 78 | |
| 79 | common::CommonProps commonProps = {sensorId, (common::SensorStrength)sensorStrength, |
| 80 | maxEnrollments, componentInfo}; |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 81 | |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 82 | SensorLocation sensorLocation = mEngine->getSensorLocation(); |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 83 | |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 84 | LOG(INFO) << "sensor type:" << ::android::internal::ToString(mSensorType) |
| 85 | << " location:" << sensorLocation.toString(); |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 86 | |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 87 | *out = {{commonProps, |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 88 | mSensorType, |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 89 | {sensorLocation}, |
Jeff Pu | 343ca94 | 2022-09-14 15:56:30 -0400 | [diff] [blame] | 90 | navigationGuesture, |
| 91 | detectInteraction, |
| 92 | displayTouch, |
Austin Delgado | 88ded64 | 2023-02-16 11:34:50 -0800 | [diff] [blame] | 93 | controlIllumination, |
| 94 | std::nullopt}}; |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 95 | return ndk::ScopedAStatus::ok(); |
| 96 | } |
| 97 | |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 98 | ndk::ScopedAStatus Fingerprint::createSession(int32_t sensorId, int32_t userId, |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 99 | const std::shared_ptr<ISessionCallback>& cb, |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 100 | std::shared_ptr<ISession>* out) { |
Ilya Matyukhin | c605e0b | 2021-02-25 16:04:34 -0800 | [diff] [blame] | 101 | CHECK(mSession == nullptr || mSession->isClosed()) << "Open session already exists!"; |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 102 | |
Ilya Matyukhin | c605e0b | 2021-02-25 16:04:34 -0800 | [diff] [blame] | 103 | mSession = SharedRefBase::make<Session>(sensorId, userId, cb, mEngine.get(), &mWorker); |
| 104 | *out = mSession; |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 105 | |
Jeff Pu | 87e9f2b | 2023-05-03 17:59:21 +0000 | [diff] [blame^] | 106 | mSession->linkToDeath(cb->asBinder().get()); |
| 107 | |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 108 | LOG(INFO) << "createSession: sensorId:" << sensorId << " userId:" << userId; |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 109 | return ndk::ScopedAStatus::ok(); |
| 110 | } |
Ilya Matyukhin | 71005c5 | 2021-02-17 12:44:14 -0800 | [diff] [blame] | 111 | |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 112 | binder_status_t Fingerprint::dump(int fd, const char** /*args*/, uint32_t numArgs) { |
| 113 | if (fd < 0) { |
| 114 | LOG(ERROR) << "Fingerprint::dump fd invalid: " << fd; |
| 115 | return STATUS_BAD_VALUE; |
| 116 | } else { |
| 117 | LOG(INFO) << "Fingerprint::dump fd:" << fd << "numArgs:" << numArgs; |
| 118 | } |
| 119 | |
| 120 | dprintf(fd, "----- FingerprintVirtualHal::dump -----\n"); |
| 121 | std::vector<SensorProps> sps(1); |
| 122 | getSensorProps(&sps); |
| 123 | for (auto& sp : sps) { |
| 124 | ::android::base::WriteStringToFd(sp.toString(), fd); |
| 125 | } |
| 126 | ::android::base::WriteStringToFd(mEngine->toString(), fd); |
| 127 | |
| 128 | fsync(fd); |
| 129 | return STATUS_OK; |
| 130 | } |
| 131 | |
| 132 | binder_status_t Fingerprint::handleShellCommand(int in, int out, int err, const char** args, |
| 133 | uint32_t numArgs) { |
| 134 | LOG(INFO) << "Fingerprint::handleShellCommand in:" << in << " out:" << out << " err:" << err |
| 135 | << " numArgs:" << numArgs; |
| 136 | |
| 137 | if (numArgs == 0) { |
| 138 | LOG(INFO) << "Fingerprint::handleShellCommand: available commands"; |
| 139 | onHelp(out); |
| 140 | return STATUS_OK; |
| 141 | } |
| 142 | |
| 143 | for (auto&& str : std::vector<std::string_view>(args, args + numArgs)) { |
| 144 | std::string option = str.data(); |
| 145 | if (option.find("clearconfig") != std::string::npos || |
| 146 | option.find("resetconfig") != std::string::npos) { |
| 147 | resetConfigToDefault(); |
| 148 | } |
| 149 | if (option.find("help") != std::string::npos) { |
| 150 | onHelp(out); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | return STATUS_OK; |
| 155 | } |
| 156 | |
| 157 | void Fingerprint::onHelp(int fd) { |
| 158 | dprintf(fd, "Virtual HAL commands:\n"); |
| 159 | dprintf(fd, " help: print this help\n"); |
| 160 | dprintf(fd, " resetconfig: reset all configuration to default\n"); |
| 161 | dprintf(fd, "\n"); |
| 162 | fsync(fd); |
| 163 | } |
| 164 | |
| 165 | void Fingerprint::resetConfigToDefault() { |
| 166 | LOG(INFO) << "reset virtual HAL configuration to default"; |
| 167 | #define RESET_CONFIG_O(__NAME__) \ |
| 168 | if (FingerprintHalProperties::__NAME__()) FingerprintHalProperties::__NAME__(std::nullopt) |
| 169 | #define RESET_CONFIG_V(__NAME__) \ |
| 170 | if (!FingerprintHalProperties::__NAME__().empty()) \ |
| 171 | FingerprintHalProperties::__NAME__({std::nullopt}) |
| 172 | |
| 173 | RESET_CONFIG_O(type); |
| 174 | RESET_CONFIG_V(enrollments); |
| 175 | RESET_CONFIG_O(enrollment_hit); |
| 176 | RESET_CONFIG_O(authenticator_id); |
| 177 | RESET_CONFIG_O(challenge); |
| 178 | RESET_CONFIG_O(lockout); |
| 179 | RESET_CONFIG_O(operation_authenticate_fails); |
| 180 | RESET_CONFIG_O(operation_detect_interaction_error); |
| 181 | RESET_CONFIG_O(operation_enroll_error); |
| 182 | RESET_CONFIG_V(operation_authenticate_latency); |
| 183 | RESET_CONFIG_V(operation_detect_interaction_latency); |
| 184 | RESET_CONFIG_V(operation_enroll_latency); |
| 185 | RESET_CONFIG_O(operation_authenticate_duration); |
| 186 | RESET_CONFIG_O(operation_authenticate_error); |
| 187 | RESET_CONFIG_O(sensor_location); |
| 188 | RESET_CONFIG_O(operation_authenticate_acquired); |
| 189 | RESET_CONFIG_O(operation_detect_interaction_duration); |
| 190 | RESET_CONFIG_O(operation_detect_interaction_acquired); |
| 191 | RESET_CONFIG_O(sensor_id); |
| 192 | RESET_CONFIG_O(sensor_strength); |
| 193 | RESET_CONFIG_O(max_enrollments); |
| 194 | RESET_CONFIG_O(navigation_guesture); |
| 195 | RESET_CONFIG_O(detect_interaction); |
| 196 | RESET_CONFIG_O(display_touch); |
| 197 | RESET_CONFIG_O(control_illumination); |
| 198 | RESET_CONFIG_O(lockout_enable); |
| 199 | RESET_CONFIG_O(lockout_timed_threshold); |
| 200 | RESET_CONFIG_O(lockout_timed_duration); |
| 201 | RESET_CONFIG_O(lockout_permanent_threshold); |
| 202 | } |
| 203 | |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 204 | } // namespace aidl::android::hardware::biometrics::fingerprint |