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 #include "BiometricsFace.h"
18 
19 namespace android::hardware::biometrics::face::implementation {
20 using android::hardware::biometrics::face::V1_0::FaceError;
21 using android::hardware::biometrics::face::V1_0::OptionalUint64;
22 
23 // Arbitrary value.
24 constexpr uint64_t kDeviceId = 123;
25 // Arbitrary value.
26 constexpr uint64_t kAuthenticatorId = 987;
27 // Not locked out.
28 constexpr uint64_t kLockoutDuration = 0;
29 
BiometricsFace()30 BiometricsFace::BiometricsFace() : mRandom(std::mt19937::default_seed) {}
31 
32 // Methods from IBiometricsFace follow.
setCallback(const sp<IBiometricsFaceClientCallback> & clientCallback,setCallback_cb _hidl_cb)33 Return<void> BiometricsFace::setCallback(const sp<IBiometricsFaceClientCallback>& clientCallback,
34                                          setCallback_cb _hidl_cb) {
35     mClientCallback = clientCallback;
36     _hidl_cb({Status::OK, kDeviceId});
37     return Void();
38 }
39 
setActiveUser(int32_t userId,const hidl_string & storePath)40 Return<Status> BiometricsFace::setActiveUser(int32_t userId, const hidl_string& storePath) {
41     if (userId < 0 || storePath.empty() || std::string(storePath).find("/data") != 0) {
42         return Status::ILLEGAL_ARGUMENT;
43     }
44     mUserId = userId;
45     mClientCallback->onLockoutChanged(kLockoutDuration);
46     return Status::OK;
47 }
48 
generateChallenge(uint32_t,generateChallenge_cb _hidl_cb)49 Return<void> BiometricsFace::generateChallenge(uint32_t /* challengeTimeoutSec */,
50                                                generateChallenge_cb _hidl_cb) {
51     std::uniform_int_distribution<uint64_t> dist;
52     _hidl_cb({Status::OK, dist(mRandom)});
53     return Void();
54 }
55 
enroll(const hidl_vec<uint8_t> &,uint32_t,const hidl_vec<Feature> &)56 Return<Status> BiometricsFace::enroll(const hidl_vec<uint8_t>& /* hat */, uint32_t /* timeoutSec */,
57                                       const hidl_vec<Feature>& /* disabledFeatures */) {
58     // hat can never be valid in this implementation.
59     mClientCallback->onError(kDeviceId, mUserId, FaceError::UNABLE_TO_PROCESS, 0 /* vendorCode */);
60     return Status::OK;
61 }
62 
revokeChallenge()63 Return<Status> BiometricsFace::revokeChallenge() {
64     return Status::OK;
65 }
66 
setFeature(Feature,bool,const hidl_vec<uint8_t> &,uint32_t)67 Return<Status> BiometricsFace::setFeature(Feature /* feature */, bool /* enabled */,
68                                           const hidl_vec<uint8_t>& /* hat */,
69                                           uint32_t /* faceId */) {
70     // hat can never be valid in this implementation.
71     return Status::ILLEGAL_ARGUMENT;
72 }
73 
getFeature(Feature,uint32_t,getFeature_cb _hidl_cb)74 Return<void> BiometricsFace::getFeature(Feature /* feature */, uint32_t /* faceId */,
75                                         getFeature_cb _hidl_cb) {
76     // hat can never be valid in this implementation.
77     _hidl_cb({Status::ILLEGAL_ARGUMENT, false});
78     return Void();
79 }
80 
getAuthenticatorId(getAuthenticatorId_cb _hidl_cb)81 Return<void> BiometricsFace::getAuthenticatorId(getAuthenticatorId_cb _hidl_cb) {
82     _hidl_cb({Status::OK, kAuthenticatorId});
83     return Void();
84 }
85 
cancel()86 Return<Status> BiometricsFace::cancel() {
87     mClientCallback->onError(kDeviceId, mUserId, FaceError::CANCELED, 0 /* vendorCode */);
88     return Status::OK;
89 }
90 
enumerate()91 Return<Status> BiometricsFace::enumerate() {
92     mClientCallback->onEnumerate(kDeviceId, {}, mUserId);
93     return Status::OK;
94 }
95 
remove(uint32_t)96 Return<Status> BiometricsFace::remove(uint32_t /* faceId */) {
97     return Status::OK;
98 }
99 
authenticate(uint64_t)100 Return<Status> BiometricsFace::authenticate(uint64_t /* operationId */) {
101     mClientCallback->onError(kDeviceId, mUserId, FaceError::HW_UNAVAILABLE, 0 /* vendorCode */);
102     return Status::OK;
103 }
104 
userActivity()105 Return<Status> BiometricsFace::userActivity() {
106     return Status::OK;
107 }
108 
resetLockout(const hidl_vec<uint8_t> &)109 Return<Status> BiometricsFace::resetLockout(const hidl_vec<uint8_t>& /* hat */) {
110     return Status::OK;
111 }
112 
113 }  // namespace android::hardware::biometrics::face::implementation
114