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 
19 #include "Session.h"
20 
21 namespace aidl::android::hardware::biometrics::fingerprint {
22 namespace {
23 constexpr size_t MAX_WORKER_QUEUE_SIZE = 5;
24 constexpr int SENSOR_ID = 1;
25 constexpr common::SensorStrength SENSOR_STRENGTH = common::SensorStrength::STRONG;
26 constexpr int MAX_ENROLLMENTS_PER_USER = 5;
27 constexpr FingerprintSensorType SENSOR_TYPE = FingerprintSensorType::REAR;
28 constexpr bool SUPPORTS_NAVIGATION_GESTURES = true;
29 constexpr char HW_COMPONENT_ID[] = "fingerprintSensor";
30 constexpr char HW_VERSION[] = "vendor/model/revision";
31 constexpr char FW_VERSION[] = "1.01";
32 constexpr char SERIAL_NUMBER[] = "00000001";
33 constexpr char SW_COMPONENT_ID[] = "matchingAlgorithm";
34 constexpr char SW_VERSION[] = "vendor/version/revision";
35 
36 }  // namespace
37 
Fingerprint()38 Fingerprint::Fingerprint()
39     : mEngine(std::make_unique<FakeFingerprintEngine>()), mWorker(MAX_WORKER_QUEUE_SIZE) {}
40 
getSensorProps(std::vector<SensorProps> * out)41 ndk::ScopedAStatus Fingerprint::getSensorProps(std::vector<SensorProps>* out) {
42     std::vector<common::ComponentInfo> componentInfo = {
43             {HW_COMPONENT_ID, HW_VERSION, FW_VERSION, SERIAL_NUMBER, "" /* softwareVersion */},
44             {SW_COMPONENT_ID, "" /* hardwareVersion */, "" /* firmwareVersion */,
45              "" /* serialNumber */, SW_VERSION}};
46 
47     common::CommonProps commonProps = {SENSOR_ID, SENSOR_STRENGTH, MAX_ENROLLMENTS_PER_USER,
48                                        componentInfo};
49 
50     SensorLocation sensorLocation = {0 /* displayId */, 0 /* sensorLocationX */,
51                                      0 /* sensorLocationY */, 0 /* sensorRadius */};
52 
53     *out = {{commonProps,
54              SENSOR_TYPE,
55              {sensorLocation},
56              SUPPORTS_NAVIGATION_GESTURES,
57              false /* supportsDetectInteraction */}};
58     return ndk::ScopedAStatus::ok();
59 }
60 
createSession(int32_t sensorId,int32_t userId,const std::shared_ptr<ISessionCallback> & cb,std::shared_ptr<ISession> * out)61 ndk::ScopedAStatus Fingerprint::createSession(int32_t sensorId, int32_t userId,
62                                               const std::shared_ptr<ISessionCallback>& cb,
63                                               std::shared_ptr<ISession>* out) {
64     CHECK(mSession == nullptr || mSession->isClosed()) << "Open session already exists!";
65 
66     mSession = SharedRefBase::make<Session>(sensorId, userId, cb, mEngine.get(), &mWorker);
67     *out = mSession;
68     return ndk::ScopedAStatus::ok();
69 }
70 
71 }  // namespace aidl::android::hardware::biometrics::fingerprint
72