1 /*
2  * Copyright 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 <android/hardware/biometrics/face/1.0/IBiometricsFace.h>
20 #include <hidl/MQDescriptor.h>
21 #include <hidl/Status.h>
22 #include <random>
23 
24 namespace android::hardware::biometrics::face::implementation {
25 
26 using ::android::sp;
27 using ::android::hardware::hidl_array;
28 using ::android::hardware::hidl_memory;
29 using ::android::hardware::hidl_string;
30 using ::android::hardware::hidl_vec;
31 using ::android::hardware::Return;
32 using ::android::hardware::Void;
33 using ::android::hardware::biometrics::face::V1_0::Feature;
34 using ::android::hardware::biometrics::face::V1_0::IBiometricsFaceClientCallback;
35 using ::android::hardware::biometrics::face::V1_0::Status;
36 
37 class BiometricsFace : public V1_0::IBiometricsFace {
38   public:
39     BiometricsFace();
40 
41     // Methods from ::android::hardware::biometrics::face::V1_0::IBiometricsFace follow.
42     Return<void> setCallback(const sp<IBiometricsFaceClientCallback>& clientCallback,
43                              setCallback_cb _hidl_cb) override;
44 
45     Return<Status> setActiveUser(int32_t userId, const hidl_string& storePath) override;
46 
47     Return<void> generateChallenge(uint32_t challengeTimeoutSec,
48                                    generateChallenge_cb _hidl_cb) override;
49 
50     Return<Status> enroll(const hidl_vec<uint8_t>& hat, uint32_t timeoutSec,
51                           const hidl_vec<Feature>& disabledFeatures) override;
52 
53     Return<Status> revokeChallenge() override;
54 
55     Return<Status> setFeature(Feature feature, bool enabled, const hidl_vec<uint8_t>& hat,
56                               uint32_t faceId) override;
57 
58     Return<void> getFeature(Feature feature, uint32_t faceId, getFeature_cb _hidl_cb) override;
59 
60     Return<void> getAuthenticatorId(getAuthenticatorId_cb _hidl_cb) override;
61 
62     Return<Status> cancel() override;
63 
64     Return<Status> enumerate() override;
65 
66     Return<Status> remove(uint32_t faceId) override;
67 
68     Return<Status> authenticate(uint64_t operationId) override;
69 
70     Return<Status> userActivity() override;
71 
72     Return<Status> resetLockout(const hidl_vec<uint8_t>& hat) override;
73 
74   private:
75     std::mt19937 mRandom;
76     int32_t mUserId;
77     sp<IBiometricsFaceClientCallback> mClientCallback;
78 };
79 
80 }  // namespace android::hardware::biometrics::face::implementation
81