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 #pragma once
18 
19 #include <random>
20 
21 #include <aidl/android/hardware/biometrics/face/BnSession.h>
22 #include <aidl/android/hardware/biometrics/face/ISessionCallback.h>
23 
24 namespace aidl::android::hardware::biometrics::face {
25 
26 namespace common = aidl::android::hardware::biometrics::common;
27 namespace keymaster = aidl::android::hardware::keymaster;
28 
29 using aidl::android::hardware::common::NativeHandle;
30 
31 class Session : public BnSession {
32   public:
33     explicit Session(std::shared_ptr<ISessionCallback> cb);
34 
35     ndk::ScopedAStatus generateChallenge() override;
36 
37     ndk::ScopedAStatus revokeChallenge(int64_t challenge) override;
38 
39     ndk::ScopedAStatus getEnrollmentConfig(EnrollmentType enrollmentType,
40                                            std::vector<EnrollmentStageConfig>* return_val) override;
41 
42     ndk::ScopedAStatus enroll(const keymaster::HardwareAuthToken& hat,
43                               EnrollmentType enrollmentType, const std::vector<Feature>& features,
44                               const std::optional<NativeHandle>& previewSurface,
45                               std::shared_ptr<common::ICancellationSignal>* return_val) override;
46 
47     ndk::ScopedAStatus authenticate(
48             int64_t keystoreOperationId,
49             std::shared_ptr<common::ICancellationSignal>* returnVal) override;
50 
51     ndk::ScopedAStatus detectInteraction(
52             std::shared_ptr<common::ICancellationSignal>* returnVal) override;
53 
54     ndk::ScopedAStatus enumerateEnrollments() override;
55 
56     ndk::ScopedAStatus removeEnrollments(const std::vector<int32_t>& enrollmentIds) override;
57 
58     ndk::ScopedAStatus getFeatures() override;
59 
60     ndk::ScopedAStatus setFeature(const keymaster::HardwareAuthToken& hat, Feature feature,
61                                   bool enabled) override;
62 
63     ndk::ScopedAStatus getAuthenticatorId() override;
64 
65     ndk::ScopedAStatus invalidateAuthenticatorId() override;
66 
67     ndk::ScopedAStatus resetLockout(const keymaster::HardwareAuthToken& hat) override;
68 
69     ndk::ScopedAStatus close() override;
70 
71   private:
72     std::shared_ptr<ISessionCallback> cb_;
73     std::mt19937 mRandom;
74 };
75 
76 }  // namespace aidl::android::hardware::biometrics::face
77