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" |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 18 | |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 19 | #include <fingerprint.sysprop.h> |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 20 | #include "Session.h" |
| 21 | |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 22 | #include <android-base/logging.h> |
| 23 | |
| 24 | using namespace ::android::fingerprint::virt; |
| 25 | |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 26 | namespace aidl::android::hardware::biometrics::fingerprint { |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 27 | namespace { |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 28 | constexpr size_t MAX_WORKER_QUEUE_SIZE = 5; |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 29 | constexpr int SENSOR_ID = 5; |
Kevin Chyn | 0ec2e0c | 2021-03-26 18:07:24 -0700 | [diff] [blame] | 30 | constexpr common::SensorStrength SENSOR_STRENGTH = common::SensorStrength::STRONG; |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 31 | constexpr int MAX_ENROLLMENTS_PER_USER = 5; |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 32 | constexpr bool SUPPORTS_NAVIGATION_GESTURES = true; |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 33 | constexpr char HW_COMPONENT_ID[] = "fingerprintSensor"; |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 34 | constexpr char HW_VERSION[] = "vendor/model/revision"; |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 35 | constexpr char FW_VERSION[] = "1.01"; |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 36 | constexpr char SERIAL_NUMBER[] = "00000001"; |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 37 | constexpr char SW_COMPONENT_ID[] = "matchingAlgorithm"; |
| 38 | constexpr char SW_VERSION[] = "vendor/version/revision"; |
Kevin Chyn | 7d3fdf5 | 2020-09-15 13:01:40 -0700 | [diff] [blame] | 39 | |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 40 | } // namespace |
Kevin Chyn | c306b76 | 2020-09-17 12:40:09 -0700 | [diff] [blame] | 41 | |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 42 | Fingerprint::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 Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 61 | |
| 62 | ndk::ScopedAStatus Fingerprint::getSensorProps(std::vector<SensorProps>* out) { |
Haining Chen | 4861855 | 2021-03-14 17:30:09 -0700 | [diff] [blame] | 63 | 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 Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 67 | |
Jeff Pu | 343ca94 | 2022-09-14 15:56:30 -0400 | [diff] [blame^] | 68 | auto sensorId = FingerprintHalProperties::sensor_id().value_or(SENSOR_ID); |
| 69 | auto sensorStrength = |
| 70 | FingerprintHalProperties::sensor_strength().value_or((int)SENSOR_STRENGTH); |
| 71 | auto maxEnrollments = |
| 72 | FingerprintHalProperties::max_enrollments().value_or(MAX_ENROLLMENTS_PER_USER); |
| 73 | auto navigationGuesture = FingerprintHalProperties::navigation_guesture().value_or(false); |
| 74 | auto detectInteraction = FingerprintHalProperties::detect_interaction().value_or(false); |
| 75 | auto displayTouch = FingerprintHalProperties::display_touch().value_or(true); |
| 76 | auto controlIllumination = FingerprintHalProperties::control_illumination().value_or(false); |
| 77 | |
| 78 | common::CommonProps commonProps = {sensorId, (common::SensorStrength)sensorStrength, |
| 79 | maxEnrollments, componentInfo}; |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 80 | |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 81 | SensorLocation sensorLocation = mEngine->getSensorLocation(); |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 82 | |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 83 | LOG(INFO) << "sensor type:" << (int)mSensorType << " location:" << sensorLocation.toString(); |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 84 | |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 85 | *out = {{commonProps, |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 86 | mSensorType, |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 87 | {sensorLocation}, |
Jeff Pu | 343ca94 | 2022-09-14 15:56:30 -0400 | [diff] [blame^] | 88 | navigationGuesture, |
| 89 | detectInteraction, |
| 90 | displayTouch, |
| 91 | controlIllumination}}; |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 92 | return ndk::ScopedAStatus::ok(); |
| 93 | } |
| 94 | |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 95 | ndk::ScopedAStatus Fingerprint::createSession(int32_t sensorId, int32_t userId, |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 96 | const std::shared_ptr<ISessionCallback>& cb, |
Ilya Matyukhin | 124e70a | 2021-02-12 13:00:15 -0800 | [diff] [blame] | 97 | std::shared_ptr<ISession>* out) { |
Ilya Matyukhin | c605e0b | 2021-02-25 16:04:34 -0800 | [diff] [blame] | 98 | CHECK(mSession == nullptr || mSession->isClosed()) << "Open session already exists!"; |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 99 | |
Ilya Matyukhin | c605e0b | 2021-02-25 16:04:34 -0800 | [diff] [blame] | 100 | mSession = SharedRefBase::make<Session>(sensorId, userId, cb, mEngine.get(), &mWorker); |
| 101 | *out = mSession; |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 102 | |
| 103 | LOG(INFO) << "createSession: sensorId:" << sensorId << " userId:" << userId; |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 104 | return ndk::ScopedAStatus::ok(); |
| 105 | } |
Ilya Matyukhin | 71005c5 | 2021-02-17 12:44:14 -0800 | [diff] [blame] | 106 | |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 107 | } // namespace aidl::android::hardware::biometrics::fingerprint |