android_device_motorola_bangkk/fingerprint/BiometricsFingerprint.cpp
SagarMakhar 1b9b756685 dubai: Add sendFodEvent hooks to fingerprint wrapper
Co-authored-by: sb6596 <shubhamprince111@gmail.com>
Co-authored-by: AdarshGrewal <adarshgrewal@gmail.com>
Change-Id: I75d2f8c05533003ad3c2c3393e33c1ff6a7d34fc
2022-09-29 19:56:25 -06:00

146 lines
4.2 KiB
C++

/*
* Copyright (C) 2017 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.
*/
#define LOG_TAG "android.hardware.biometrics.fingerprint@2.3-service.dubai"
#include "BiometricsFingerprint.h"
#include <android-base/logging.h>
#include <fstream>
#include <cmath>
#include <thread>
#include <fcntl.h>
#include <poll.h>
#include <sys/stat.h>
#define NOTIFY_FINGER_UP IMotFodEventType::FINGER_UP
#define NOTIFY_FINGER_DOWN IMotFodEventType::FINGER_DOWN
#define FOD_UI_PATH "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_ui"
namespace android {
namespace hardware {
namespace biometrics {
namespace fingerprint {
namespace V2_3 {
namespace implementation {
static bool readBool(int fd) {
char c;
int rc;
rc = lseek(fd, 0, SEEK_SET);
if (rc) {
LOG(ERROR) << "failed to seek fd, err: " << rc;
return false;
}
rc = read(fd, &c, sizeof(char));
if (rc != 1) {
LOG(ERROR) << "failed to read bool from fd, err: " << rc;
return false;
}
return c != '0';
}
BiometricsFingerprint::BiometricsFingerprint() {
biometrics_2_1_service = IBiometricsFingerprint_2_1::getService();
mMotoFingerprint = IMotoFingerPrint::getService();
std::thread([this]() {
int fd = open(FOD_UI_PATH, O_RDONLY);
if (fd < 0) {
LOG(ERROR) << "failed to open fd, err: " << fd;
return;
}
struct pollfd fodUiPoll = {
.fd = fd,
.events = POLLERR | POLLPRI,
.revents = 0,
};
while (true) {
int rc = poll(&fodUiPoll, 1, -1);
if (rc < 0) {
LOG(ERROR) << "failed to poll fd, err: " << rc;
continue;
}
mMotoFingerprint->sendFodEvent(readBool(fd) ? NOTIFY_FINGER_DOWN : NOTIFY_FINGER_UP , {},
[](IMotFodEventResult, const hidl_vec<signed char>&) {});
}
}).detach();
}
Return<uint64_t> BiometricsFingerprint::setNotify(const sp<IBiometricsFingerprintClientCallback>& clientCallback) {
return biometrics_2_1_service->setNotify(clientCallback);
}
Return<uint64_t> BiometricsFingerprint::preEnroll() {
return biometrics_2_1_service->preEnroll();
}
Return<RequestStatus> BiometricsFingerprint::enroll(const hidl_array<uint8_t, 69>& hat, uint32_t gid, uint32_t timeoutSec) {
return biometrics_2_1_service->enroll(hat, gid, timeoutSec);
}
Return<RequestStatus> BiometricsFingerprint::postEnroll() {
return biometrics_2_1_service->postEnroll();
}
Return<uint64_t> BiometricsFingerprint::getAuthenticatorId() {
return biometrics_2_1_service->getAuthenticatorId();
}
Return<RequestStatus> BiometricsFingerprint::cancel() {
return biometrics_2_1_service->cancel();
}
Return<RequestStatus> BiometricsFingerprint::enumerate() {
return biometrics_2_1_service->enumerate();
}
Return<RequestStatus> BiometricsFingerprint::remove(uint32_t gid, uint32_t fid) {
return biometrics_2_1_service->remove(gid, fid);
}
Return<RequestStatus> BiometricsFingerprint::setActiveGroup(uint32_t gid, const hidl_string& storePath) {
return biometrics_2_1_service->setActiveGroup(gid, storePath);
}
Return<RequestStatus> BiometricsFingerprint::authenticate(uint64_t operationId, uint32_t gid) {
return biometrics_2_1_service->authenticate(operationId, gid);
}
Return<bool> BiometricsFingerprint::isUdfps(uint32_t) {
return true;
}
Return<void> BiometricsFingerprint::onFingerDown(uint32_t, uint32_t, float, float) {
return Void();
}
Return<void> BiometricsFingerprint::onFingerUp() {
return Void();
}
} // namespace implementation
} // namespace V2_3
} // namespace fingerprint
} // namespace biometrics
} // namespace hardware
} // namespace android