blob: 5ae0df6e56c676b4a802cafdb70cfd0179d27a2e [file] [log] [blame]
Ilya Matyukhin09166982020-10-12 13:41:03 -07001/*
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 Pu1e93ca62024-01-24 10:51:31 -050017#undef LOG_TAG
18#define LOG_TAG "FaceVirtualHal"
19
Ilya Matyukhin09166982020-10-12 13:41:03 -070020#include "Face.h"
21#include "Session.h"
22
Joshua McCloskeydb009a52022-05-10 05:18:20 +000023#include "FakeFaceEngine.h"
24
Jeff Pu1e93ca62024-01-24 10:51:31 -050025#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
32using namespace ::android::face::virt;
33
Ilya Matyukhin09166982020-10-12 13:41:03 -070034namespace aidl::android::hardware::biometrics::face {
35
Kevin Chyn4e7c0162020-12-11 15:45:54 -080036const int kSensorId = 4;
Joshua McCloskeydb009a52022-05-10 05:18:20 +000037const common::SensorStrength kSensorStrength = FakeFaceEngine::GetSensorStrength();
Ilya Matyukhin09166982020-10-12 13:41:03 -070038const int kMaxEnrollmentsPerUser = 5;
Joshua McCloskeydb009a52022-05-10 05:18:20 +000039const FaceSensorType kSensorType = FakeFaceEngine::GetSensorType();
Ilya Matyukhin09166982020-10-12 13:41:03 -070040const bool kHalControlsPreview = true;
Haining Chen48618552021-03-14 17:30:09 -070041const std::string kHwComponentId = "faceSensor";
Ilya Matyukhin09166982020-10-12 13:41:03 -070042const std::string kHardwareVersion = "vendor/model/revision";
Haining Chen48618552021-03-14 17:30:09 -070043const std::string kFirmwareVersion = "1.01";
Ilya Matyukhin09166982020-10-12 13:41:03 -070044const std::string kSerialNumber = "00000001";
Haining Chen48618552021-03-14 17:30:09 -070045const std::string kSwComponentId = "matchingAlgorithm";
46const std::string kSoftwareVersion = "vendor/version/revision";
Ilya Matyukhin09166982020-10-12 13:41:03 -070047
48ndk::ScopedAStatus Face::getSensorProps(std::vector<SensorProps>* return_val) {
Haining Chen48618552021-03-14 17:30:09 -070049 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 Matyukhin09166982020-10-12 13:41:03 -070062
63 common::CommonProps commonProps;
64 commonProps.sensorId = kSensorId;
65 commonProps.sensorStrength = kSensorStrength;
66 commonProps.maxEnrollmentsPerUser = kMaxEnrollmentsPerUser;
Haining Chen48618552021-03-14 17:30:09 -070067 commonProps.componentInfo = {std::move(hw_component_info), std::move(sw_component_info)};
Ilya Matyukhin09166982020-10-12 13:41:03 -070068
69 SensorProps props;
70 props.commonProps = std::move(commonProps);
71 props.sensorType = kSensorType;
72 props.halControlsPreview = kHalControlsPreview;
Kevin Chynbad76852020-11-11 13:23:35 -080073 props.enrollPreviewWidth = 1080;
74 props.enrollPreviewHeight = 1920;
75 props.enrollTranslationX = 100.f;
76 props.enrollTranslationY = 50.f;
77 props.enrollPreviewScale = 1.f;
Ilya Matyukhin09166982020-10-12 13:41:03 -070078
79 *return_val = {std::move(props)};
80 return ndk::ScopedAStatus::ok();
81}
82
Jeff Pu1e93ca62024-01-24 10:51:31 -050083ndk::ScopedAStatus Face::createSession(int32_t sensorId, int32_t userId,
Ilya Matyukhin09166982020-10-12 13:41:03 -070084 const std::shared_ptr<ISessionCallback>& cb,
85 std::shared_ptr<ISession>* return_val) {
Jeff Pu1e93ca62024-01-24 10:51:31 -050086 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 Matyukhin09166982020-10-12 13:41:03 -070092 return ndk::ScopedAStatus::ok();
93}
94
Jeff Pu1e93ca62024-01-24 10:51:31 -050095binder_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
119binder_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
144void 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
152void 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 Matyukhin09166982020-10-12 13:41:03 -0700184} // namespace aidl::android::hardware::biometrics::face