Kevin Chyn | 22a5720 | 2020-12-02 17:39:53 -0800 | [diff] [blame^] | 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 | #define LOG_TAG "android.hardware.biometrics.fingerprint@2.2-service" |
| 17 | #define LOG_VERBOSE "android.hardware.biometrics.fingerprint@2.2-service" |
| 18 | |
| 19 | #include <hardware/hw_auth_token.h> |
| 20 | |
| 21 | #include <android/log.h> |
| 22 | #include <hardware/hardware.h> |
| 23 | #include <hardware/fingerprint.h> |
| 24 | #include "BiometricsFingerprint.h" |
| 25 | |
| 26 | #include <inttypes.h> |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <unistd.h> |
| 30 | |
| 31 | namespace android { |
| 32 | namespace hardware { |
| 33 | namespace biometrics { |
| 34 | namespace fingerprint { |
| 35 | namespace V2_2 { |
| 36 | namespace implementation { |
| 37 | |
| 38 | using RequestStatus = android::hardware::biometrics::fingerprint::V2_1::RequestStatus; |
| 39 | using FingerprintError = android::hardware::biometrics::fingerprint::V2_1::FingerprintError; |
| 40 | |
| 41 | constexpr uint64_t kDeviceId = 1; |
| 42 | |
| 43 | BiometricsFingerprint::BiometricsFingerprint() { |
| 44 | |
| 45 | } |
| 46 | |
| 47 | BiometricsFingerprint::~BiometricsFingerprint() { |
| 48 | |
| 49 | } |
| 50 | |
| 51 | Return<uint64_t> BiometricsFingerprint::setNotify( |
| 52 | const sp<IBiometricsFingerprintClientCallback>& clientCallback) { |
| 53 | mClientCallback = clientCallback; |
| 54 | return kDeviceId; |
| 55 | } |
| 56 | |
| 57 | Return<uint64_t> BiometricsFingerprint::preEnroll() { |
| 58 | // On a real implementation, this must be generated and stored in the TEE or its equivalent. |
| 59 | return rand(); |
| 60 | } |
| 61 | |
| 62 | Return<RequestStatus> BiometricsFingerprint::enroll(const hidl_array<uint8_t, 69>& /* hat */, |
| 63 | uint32_t /* gid */, uint32_t /* timeoutSec */) { |
| 64 | // On a real implementation, the HAT must be checked in the TEE or its equivalent. |
| 65 | mClientCallback->onError(kDeviceId, FingerprintError::ERROR_UNABLE_TO_PROCESS, |
| 66 | 0 /* vendorCode */); |
| 67 | return RequestStatus::SYS_OK; |
| 68 | } |
| 69 | |
| 70 | Return<RequestStatus> BiometricsFingerprint::postEnroll() { |
| 71 | return RequestStatus::SYS_OK; |
| 72 | } |
| 73 | |
| 74 | Return<uint64_t> BiometricsFingerprint::getAuthenticatorId() { |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | Return<RequestStatus> BiometricsFingerprint::cancel() { |
| 79 | mClientCallback->onError(kDeviceId, FingerprintError::ERROR_CANCELED, 0 /* vendorCode */); |
| 80 | return RequestStatus::SYS_OK; |
| 81 | } |
| 82 | |
| 83 | Return<RequestStatus> BiometricsFingerprint::enumerate() { |
| 84 | mClientCallback->onEnumerate(kDeviceId, 0 /* fingerId */, 0 /* groupId */, |
| 85 | 0 /* remaining */); |
| 86 | return RequestStatus::SYS_OK; |
| 87 | } |
| 88 | |
| 89 | Return<RequestStatus> BiometricsFingerprint::remove(uint32_t gid, uint32_t fid) { |
| 90 | mClientCallback->onRemoved(kDeviceId, fid, gid, 0 /* remaining */); |
| 91 | return RequestStatus::SYS_OK; |
| 92 | } |
| 93 | |
| 94 | Return<RequestStatus> BiometricsFingerprint::setActiveGroup(uint32_t /* gid */, |
| 95 | const hidl_string& storePath) { |
| 96 | // Return invalid for paths that the HAL is unable to write to. |
| 97 | std::string path = storePath.c_str(); |
| 98 | if (path.compare("") == 0 || path.compare("/") == 0) { |
| 99 | return RequestStatus::SYS_EINVAL; |
| 100 | } |
| 101 | return RequestStatus::SYS_OK; |
| 102 | } |
| 103 | |
| 104 | Return<RequestStatus> BiometricsFingerprint::authenticate(uint64_t /* operationId */, |
| 105 | uint32_t /* gid */) { |
| 106 | return RequestStatus::SYS_OK; |
| 107 | } |
| 108 | |
| 109 | } // namespace implementation |
| 110 | } // namespace V2_2 |
| 111 | } // namespace fingerprint |
| 112 | } // namespace biometrics |
| 113 | } // namespace hardware |
| 114 | } // namespace android |