summaryrefslogtreecommitdiff
path: root/biometrics/face/1.0/default/BiometricsFace.cpp
blob: 97dc4690befe8fc82cceff866fc3ce03e2e56dc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "BiometricsFace.h"

namespace android::hardware::biometrics::face::implementation {
using android::hardware::biometrics::face::V1_0::FaceError;
using android::hardware::biometrics::face::V1_0::OptionalUint64;

// Arbitrary value.
constexpr uint64_t kDeviceId = 123;
// Arbitrary value.
constexpr uint64_t kAuthenticatorId = 987;
// Not locked out.
constexpr uint64_t kLockoutDuration = 0;

BiometricsFace::BiometricsFace() : mRandom(std::mt19937::default_seed) {}

// Methods from IBiometricsFace follow.
Return<void> BiometricsFace::setCallback(const sp<IBiometricsFaceClientCallback>& clientCallback,
                                         setCallback_cb _hidl_cb) {
    mClientCallback = clientCallback;
    _hidl_cb({Status::OK, kDeviceId});
    return Void();
}

Return<Status> BiometricsFace::setActiveUser(int32_t userId, const hidl_string& storePath) {
    if (userId < 0 || storePath.empty() || std::string(storePath).find("/data") != 0) {
        return Status::ILLEGAL_ARGUMENT;
    }
    mUserId = userId;
    mClientCallback->onLockoutChanged(kLockoutDuration);
    return Status::OK;
}

Return<void> BiometricsFace::generateChallenge(uint32_t /* challengeTimeoutSec */,
                                               generateChallenge_cb _hidl_cb) {
    std::uniform_int_distribution<uint64_t> dist;
    _hidl_cb({Status::OK, dist(mRandom)});
    return Void();
}

Return<Status> BiometricsFace::enroll(const hidl_vec<uint8_t>& /* hat */, uint32_t /* timeoutSec */,
                                      const hidl_vec<Feature>& /* disabledFeatures */) {
    // hat can never be valid in this implementation.
    mClientCallback->onError(kDeviceId, mUserId, FaceError::UNABLE_TO_PROCESS, 0 /* vendorCode */);
    return Status::OK;
}

Return<Status> BiometricsFace::revokeChallenge() {
    return Status::OK;
}

Return<Status> BiometricsFace::setFeature(Feature /* feature */, bool /* enabled */,
                                          const hidl_vec<uint8_t>& /* hat */,
                                          uint32_t /* faceId */) {
    // hat can never be valid in this implementation.
    return Status::ILLEGAL_ARGUMENT;
}

Return<void> BiometricsFace::getFeature(Feature /* feature */, uint32_t /* faceId */,
                                        getFeature_cb _hidl_cb) {
    // hat can never be valid in this implementation.
    _hidl_cb({Status::ILLEGAL_ARGUMENT, false});
    return Void();
}

Return<void> BiometricsFace::getAuthenticatorId(getAuthenticatorId_cb _hidl_cb) {
    _hidl_cb({Status::OK, kAuthenticatorId});
    return Void();
}

Return<Status> BiometricsFace::cancel() {
    mClientCallback->onError(kDeviceId, mUserId, FaceError::CANCELED, 0 /* vendorCode */);
    return Status::OK;
}

Return<Status> BiometricsFace::enumerate() {
    mClientCallback->onEnumerate(kDeviceId, {}, mUserId);
    return Status::OK;
}

Return<Status> BiometricsFace::remove(uint32_t /* faceId */) {
    return Status::OK;
}

Return<Status> BiometricsFace::authenticate(uint64_t /* operationId */) {
    mClientCallback->onError(kDeviceId, mUserId, FaceError::HW_UNAVAILABLE, 0 /* vendorCode */);
    return Status::OK;
}

Return<Status> BiometricsFace::userActivity() {
    return Status::OK;
}

Return<Status> BiometricsFace::resetLockout(const hidl_vec<uint8_t>& /* hat */) {
    return Status::OK;
}

}  // namespace android::hardware::biometrics::face::implementation