Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -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 | |
Jeff Pu | 1e93ca6 | 2024-01-24 10:51:31 -0500 | [diff] [blame^] | 17 | #undef LOG_TAG |
| 18 | #define LOG_TAG "FaceVirtualHal" |
| 19 | |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 20 | #include "Face.h" |
| 21 | #include "Session.h" |
| 22 | |
Joshua McCloskey | db009a5 | 2022-05-10 05:18:20 +0000 | [diff] [blame] | 23 | #include "FakeFaceEngine.h" |
| 24 | |
Jeff Pu | 1e93ca6 | 2024-01-24 10:51:31 -0500 | [diff] [blame^] | 25 | #include <android-base/properties.h> |
| 26 | #include <face.sysprop.h> |
| 27 | |
| 28 | #include <android-base/file.h> |
| 29 | #include <android-base/logging.h> |
| 30 | #include <android-base/stringprintf.h> |
| 31 | |
| 32 | using namespace ::android::face::virt; |
| 33 | |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 34 | namespace aidl::android::hardware::biometrics::face { |
| 35 | |
Kevin Chyn | 4e7c016 | 2020-12-11 15:45:54 -0800 | [diff] [blame] | 36 | const int kSensorId = 4; |
Joshua McCloskey | db009a5 | 2022-05-10 05:18:20 +0000 | [diff] [blame] | 37 | const common::SensorStrength kSensorStrength = FakeFaceEngine::GetSensorStrength(); |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 38 | const int kMaxEnrollmentsPerUser = 5; |
Joshua McCloskey | db009a5 | 2022-05-10 05:18:20 +0000 | [diff] [blame] | 39 | const FaceSensorType kSensorType = FakeFaceEngine::GetSensorType(); |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 40 | const bool kHalControlsPreview = true; |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 41 | const std::string kHwComponentId = "faceSensor"; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 42 | const std::string kHardwareVersion = "vendor/model/revision"; |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 43 | const std::string kFirmwareVersion = "1.01"; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 44 | const std::string kSerialNumber = "00000001"; |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 45 | const std::string kSwComponentId = "matchingAlgorithm"; |
| 46 | const std::string kSoftwareVersion = "vendor/version/revision"; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 47 | |
| 48 | ndk::ScopedAStatus Face::getSensorProps(std::vector<SensorProps>* return_val) { |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 49 | common::ComponentInfo hw_component_info; |
| 50 | hw_component_info.componentId = kHwComponentId; |
| 51 | hw_component_info.hardwareVersion = kHardwareVersion; |
| 52 | hw_component_info.firmwareVersion = kFirmwareVersion; |
| 53 | hw_component_info.serialNumber = kSerialNumber; |
| 54 | hw_component_info.softwareVersion = ""; |
| 55 | |
| 56 | common::ComponentInfo sw_component_info; |
| 57 | sw_component_info.componentId = kSwComponentId; |
| 58 | sw_component_info.hardwareVersion = ""; |
| 59 | sw_component_info.firmwareVersion = ""; |
| 60 | sw_component_info.serialNumber = ""; |
| 61 | sw_component_info.softwareVersion = kSoftwareVersion; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 62 | |
| 63 | common::CommonProps commonProps; |
| 64 | commonProps.sensorId = kSensorId; |
| 65 | commonProps.sensorStrength = kSensorStrength; |
| 66 | commonProps.maxEnrollmentsPerUser = kMaxEnrollmentsPerUser; |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 67 | commonProps.componentInfo = {std::move(hw_component_info), std::move(sw_component_info)}; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 68 | |
| 69 | SensorProps props; |
| 70 | props.commonProps = std::move(commonProps); |
| 71 | props.sensorType = kSensorType; |
| 72 | props.halControlsPreview = kHalControlsPreview; |
Kevin Chyn | bad7685 | 2020-11-11 13:23:35 -0800 | [diff] [blame] | 73 | props.enrollPreviewWidth = 1080; |
| 74 | props.enrollPreviewHeight = 1920; |
| 75 | props.enrollTranslationX = 100.f; |
| 76 | props.enrollTranslationY = 50.f; |
| 77 | props.enrollPreviewScale = 1.f; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 78 | |
| 79 | *return_val = {std::move(props)}; |
| 80 | return ndk::ScopedAStatus::ok(); |
| 81 | } |
| 82 | |
Jeff Pu | 1e93ca6 | 2024-01-24 10:51:31 -0500 | [diff] [blame^] | 83 | ndk::ScopedAStatus Face::createSession(int32_t sensorId, int32_t userId, |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 84 | const std::shared_ptr<ISessionCallback>& cb, |
| 85 | std::shared_ptr<ISession>* return_val) { |
Jeff Pu | 1e93ca6 | 2024-01-24 10:51:31 -0500 | [diff] [blame^] | 86 | mSession = SharedRefBase::make<Session>(std::make_unique<FakeFaceEngine>(), cb); |
| 87 | *return_val = mSession; |
| 88 | |
| 89 | mSession->linkToDeath(cb->asBinder().get()); |
| 90 | |
| 91 | LOG(INFO) << __func__ << ": sensorId:" << sensorId << " userId:" << userId; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 92 | return ndk::ScopedAStatus::ok(); |
| 93 | } |
| 94 | |
Jeff Pu | 1e93ca6 | 2024-01-24 10:51:31 -0500 | [diff] [blame^] | 95 | binder_status_t Face::dump(int fd, const char** /*args*/, uint32_t numArgs) { |
| 96 | if (fd < 0) { |
| 97 | LOG(ERROR) << __func__ << "fd invalid: " << fd; |
| 98 | return STATUS_BAD_VALUE; |
| 99 | } else { |
| 100 | LOG(INFO) << __func__ << " fd:" << fd << "numArgs:" << numArgs; |
| 101 | } |
| 102 | |
| 103 | dprintf(fd, "----- FaceVirtualHal::dump -----\n"); |
| 104 | std::vector<SensorProps> sps(1); |
| 105 | getSensorProps(&sps); |
| 106 | for (auto& sp : sps) { |
| 107 | ::android::base::WriteStringToFd(sp.toString(), fd); |
| 108 | } |
| 109 | if (mSession != nullptr) { |
| 110 | ::android::base::WriteStringToFd(mSession->toString(), fd); |
| 111 | } else { |
| 112 | dprintf(fd, "\nWARNING: no ISession found\n"); |
| 113 | } |
| 114 | |
| 115 | fsync(fd); |
| 116 | return STATUS_OK; |
| 117 | } |
| 118 | |
| 119 | binder_status_t Face::handleShellCommand(int in, int out, int err, const char** args, |
| 120 | uint32_t numArgs) { |
| 121 | LOG(INFO) << __func__ << " in:" << in << " out:" << out << " err:" << err |
| 122 | << " numArgs:" << numArgs; |
| 123 | |
| 124 | if (numArgs == 0) { |
| 125 | LOG(INFO) << __func__ << ": available commands"; |
| 126 | onHelp(out); |
| 127 | return STATUS_OK; |
| 128 | } |
| 129 | |
| 130 | for (auto&& str : std::vector<std::string_view>(args, args + numArgs)) { |
| 131 | std::string option = str.data(); |
| 132 | if (option.find("clearconfig") != std::string::npos || |
| 133 | option.find("resetconfig") != std::string::npos) { |
| 134 | resetConfigToDefault(); |
| 135 | } |
| 136 | if (option.find("help") != std::string::npos) { |
| 137 | onHelp(out); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | return STATUS_OK; |
| 142 | } |
| 143 | |
| 144 | void Face::onHelp(int fd) { |
| 145 | dprintf(fd, "Virtual Face HAL commands:\n"); |
| 146 | dprintf(fd, " help: print this help\n"); |
| 147 | dprintf(fd, " resetconfig: reset all configuration to default\n"); |
| 148 | dprintf(fd, "\n"); |
| 149 | fsync(fd); |
| 150 | } |
| 151 | |
| 152 | void Face::resetConfigToDefault() { |
| 153 | LOG(INFO) << __func__ << ": reset virtual Face HAL configuration to default"; |
| 154 | #define RESET_CONFIG_O(__NAME__) \ |
| 155 | if (FaceHalProperties::__NAME__()) FaceHalProperties::__NAME__(std::nullopt) |
| 156 | #define RESET_CONFIG_V(__NAME__) \ |
| 157 | if (!FaceHalProperties::__NAME__().empty()) FaceHalProperties::__NAME__({std::nullopt}) |
| 158 | |
| 159 | RESET_CONFIG_O(type); |
| 160 | RESET_CONFIG_O(strength); |
| 161 | RESET_CONFIG_V(enrollments); |
| 162 | RESET_CONFIG_O(enrollment_hit); |
| 163 | RESET_CONFIG_V(features); |
| 164 | RESET_CONFIG_O(next_enrollment); |
| 165 | RESET_CONFIG_O(authenticator_id); |
| 166 | RESET_CONFIG_O(challenge); |
| 167 | RESET_CONFIG_O(lockout); |
| 168 | RESET_CONFIG_O(operation_authenticate_fails); |
| 169 | RESET_CONFIG_O(operation_detect_interaction_fails); |
| 170 | RESET_CONFIG_O(operation_enroll_fails); |
| 171 | RESET_CONFIG_V(operation_authenticate_latency); |
| 172 | RESET_CONFIG_V(operation_detect_interaction_latency); |
| 173 | RESET_CONFIG_V(operation_enroll_latency); |
| 174 | RESET_CONFIG_O(operation_authenticate_duration); |
| 175 | RESET_CONFIG_O(operation_authenticate_error); |
| 176 | RESET_CONFIG_O(operation_authenticate_acquired); |
| 177 | RESET_CONFIG_O(lockout_enable); |
| 178 | RESET_CONFIG_O(lockout_timed_enable); |
| 179 | RESET_CONFIG_O(lockout_timed_threshold); |
| 180 | RESET_CONFIG_O(lockout_timed_duration); |
| 181 | RESET_CONFIG_O(lockout_permanent_threshold); |
| 182 | } |
| 183 | |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 184 | } // namespace aidl::android::hardware::biometrics::face |