Files
device_lenovo_zippo/fod/FingerprintInscreen.cpp
2021-03-15 07:03:44 -06:00

153 lines
3.8 KiB
C++

/*
* Copyright (C) 2019 The LineageOS 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 "FingerprintInscreenService"
#include "FingerprintInscreen.h"
#include <unistd.h>
#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include <fstream>
#include <cmath>
#define CMD_FINGERPRINT_EVENT 10
#define HBM_ENABLE_PATH "/sys/class/backlight/panel0-hbm/brightness"
namespace vendor {
namespace lineage {
namespace biometrics {
namespace fingerprint {
namespace inscreen {
namespace V1_0 {
namespace implementation {
/*
* Write value to path and close file.
*/
template <typename T>
static void set(const std::string& path, const T& value) {
std::ofstream file(path);
file << value;
LOG(INFO) << "wrote path: " << path << ", value: " << value << "\n";
}
template <typename T>
static T get(const std::string& path, const T& def) {
std::ifstream file(path);
T result;
file >> result;
return file.fail() ? def : result;
}
FingerprintInscreen::FingerprintInscreen() {
this->mVendorFpService = IGoodixFPExtendService::getService();
}
Return<void> FingerprintInscreen::onStartEnroll() {
this->mVendorFpService->goodixExtendCommand(CMD_FINGERPRINT_EVENT, 1);
return Void();
}
Return<void> FingerprintInscreen::onFinishEnroll() {
set(HBM_ENABLE_PATH, 0);
return Void();
}
Return<void> FingerprintInscreen::onPress() {
this->mVendorFpService->goodixExtendCommand(CMD_FINGERPRINT_EVENT, 1);
set(HBM_ENABLE_PATH, 1);
return Void();
}
Return<void> FingerprintInscreen::onRelease() {
this->mVendorFpService->goodixExtendCommand(CMD_FINGERPRINT_EVENT, 0);
set(HBM_ENABLE_PATH, 0);
return Void();
}
Return<void> FingerprintInscreen::onShowFODView() {
return Void();
}
Return<void> FingerprintInscreen::onHideFODView() {
return Void();
}
Return<bool> FingerprintInscreen::handleAcquired(int32_t acquiredInfo, int32_t vendorCode) {
LOG(ERROR) << "acquiredInfo: " << acquiredInfo << ", vendorCode: " << vendorCode << "\n";
return false;
}
Return<bool> FingerprintInscreen::handleError(int32_t error, int32_t vendorCode) {
LOG(ERROR) << "error: " << error << ", vendorCode: " << vendorCode << "\n";
return false;
}
Return<void> FingerprintInscreen::setLongPressEnabled(bool) {
return Void();
}
Return<int32_t> FingerprintInscreen::getDimAmount(int32_t brightness) {
float alpha;
int realBrightness = brightness * 2047 / 255;
if (realBrightness > 500) {
alpha = 1.0 - pow(realBrightness / 2047.0 * 430.0 / 600.0, 0.455);
} else {
alpha = 1.0 - pow(realBrightness / 1680.0, 0.455);
}
return 255 * alpha;
}
Return<bool> FingerprintInscreen::shouldBoostBrightness() {
return false;
}
Return<void> FingerprintInscreen::setCallback(const sp<IFingerprintInscreenCallback>& callback) {
{
std::lock_guard<std::mutex> _lock(mCallbackLock);
mCallback = callback;
}
return Void();
}
Return<int32_t> FingerprintInscreen::getPositionX() {
return 450;
}
Return<int32_t> FingerprintInscreen::getPositionY() {
return 1916;
}
Return<int32_t> FingerprintInscreen::getSize() {
return 178;
}
} // namespace implementation
} // namespace V1_0
} // namespace inscreen
} // namespace fingerprint
} // namespace biometrics
} // namespace lineage
} // namespace vendor