blob: 922781ce65ee037d81cbd1f32f60d6e38c3d26f0 [file] [log] [blame]
Ilya Matyukhina9a3c852020-08-18 03:09:41 -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
17#include "Fingerprint.h"
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080018
Joe Bolingerde94aa02021-12-09 17:00:32 -080019#include <fingerprint.sysprop.h>
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070020#include "Session.h"
21
Joe Bolingerde94aa02021-12-09 17:00:32 -080022#include <android-base/logging.h>
23
24using namespace ::android::fingerprint::virt;
25
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070026namespace aidl::android::hardware::biometrics::fingerprint {
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080027namespace {
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080028constexpr size_t MAX_WORKER_QUEUE_SIZE = 5;
Jeff Pu63f33c72022-07-28 16:06:23 -040029constexpr int SENSOR_ID = 5;
Kevin Chyn0ec2e0c2021-03-26 18:07:24 -070030constexpr common::SensorStrength SENSOR_STRENGTH = common::SensorStrength::STRONG;
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080031constexpr int MAX_ENROLLMENTS_PER_USER = 5;
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080032constexpr bool SUPPORTS_NAVIGATION_GESTURES = true;
Haining Chen48618552021-03-14 17:30:09 -070033constexpr char HW_COMPONENT_ID[] = "fingerprintSensor";
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080034constexpr char HW_VERSION[] = "vendor/model/revision";
Haining Chen48618552021-03-14 17:30:09 -070035constexpr char FW_VERSION[] = "1.01";
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080036constexpr char SERIAL_NUMBER[] = "00000001";
Haining Chen48618552021-03-14 17:30:09 -070037constexpr char SW_COMPONENT_ID[] = "matchingAlgorithm";
38constexpr char SW_VERSION[] = "vendor/version/revision";
Kevin Chyn7d3fdf52020-09-15 13:01:40 -070039
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080040} // namespace
Kevin Chync306b762020-09-17 12:40:09 -070041
Jeff Pu63f33c72022-07-28 16:06:23 -040042Fingerprint::Fingerprint() : mWorker(MAX_WORKER_QUEUE_SIZE) {
43 std::string sensorTypeProp = FingerprintHalProperties::type().value_or("");
44 if (sensorTypeProp == "" || sensorTypeProp == "default" || sensorTypeProp == "rear") {
45 mSensorType = FingerprintSensorType::REAR;
46 mEngine = std::make_unique<FakeFingerprintEngineRear>();
47 } else if (sensorTypeProp == "udfps") {
48 mSensorType = FingerprintSensorType::UNDER_DISPLAY_OPTICAL;
49 mEngine = std::make_unique<FakeFingerprintEngineUdfps>();
50 } else if (sensorTypeProp == "side") {
51 mSensorType = FingerprintSensorType::POWER_BUTTON;
52 mEngine = std::make_unique<FakeFingerprintEngineSide>();
53 } else {
54 mSensorType = FingerprintSensorType::UNKNOWN;
55 mEngine = std::make_unique<FakeFingerprintEngineRear>();
56 UNIMPLEMENTED(FATAL) << "unrecognized or unimplemented fingerprint behavior: "
57 << sensorTypeProp;
58 }
59 LOG(INFO) << "sensorTypeProp:" << sensorTypeProp;
60}
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080061
62ndk::ScopedAStatus Fingerprint::getSensorProps(std::vector<SensorProps>* out) {
Haining Chen48618552021-03-14 17:30:09 -070063 std::vector<common::ComponentInfo> componentInfo = {
64 {HW_COMPONENT_ID, HW_VERSION, FW_VERSION, SERIAL_NUMBER, "" /* softwareVersion */},
65 {SW_COMPONENT_ID, "" /* hardwareVersion */, "" /* firmwareVersion */,
66 "" /* serialNumber */, SW_VERSION}};
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080067
68 common::CommonProps commonProps = {SENSOR_ID, SENSOR_STRENGTH, MAX_ENROLLMENTS_PER_USER,
Haining Chen48618552021-03-14 17:30:09 -070069 componentInfo};
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080070
Jeff Pu63f33c72022-07-28 16:06:23 -040071 SensorLocation sensorLocation = mEngine->getSensorLocation();
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080072
Jeff Pu63f33c72022-07-28 16:06:23 -040073 LOG(INFO) << "sensor type:" << (int)mSensorType << " location:" << sensorLocation.toString();
Joe Bolingerde94aa02021-12-09 17:00:32 -080074
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080075 *out = {{commonProps,
Jeff Pu63f33c72022-07-28 16:06:23 -040076 mSensorType,
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080077 {sensorLocation},
78 SUPPORTS_NAVIGATION_GESTURES,
79 false /* supportsDetectInteraction */}};
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070080 return ndk::ScopedAStatus::ok();
81}
82
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080083ndk::ScopedAStatus Fingerprint::createSession(int32_t sensorId, int32_t userId,
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070084 const std::shared_ptr<ISessionCallback>& cb,
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080085 std::shared_ptr<ISession>* out) {
Ilya Matyukhinc605e0b2021-02-25 16:04:34 -080086 CHECK(mSession == nullptr || mSession->isClosed()) << "Open session already exists!";
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080087
Ilya Matyukhinc605e0b2021-02-25 16:04:34 -080088 mSession = SharedRefBase::make<Session>(sensorId, userId, cb, mEngine.get(), &mWorker);
89 *out = mSession;
Jeff Pu63f33c72022-07-28 16:06:23 -040090
91 LOG(INFO) << "createSession: sensorId:" << sensorId << " userId:" << userId;
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070092 return ndk::ScopedAStatus::ok();
93}
Ilya Matyukhin71005c52021-02-17 12:44:14 -080094
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070095} // namespace aidl::android::hardware::biometrics::fingerprint