sm8250-common: Import FOD HAL from device/oneplus/sm8150-common
This commit is contained in:
203
fod/FingerprintInscreen.cpp
Normal file
203
fod/FingerprintInscreen.cpp
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* 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 <android-base/logging.h>
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
#include <fstream>
|
||||
|
||||
#define FINGERPRINT_ERROR_CANCELED 5
|
||||
#define FINGERPRINT_ACQUIRED_VENDOR 6
|
||||
#define FINGERPRINT_ERROR_VENDOR 8
|
||||
|
||||
#define OP_ENABLE_FP_LONGPRESS 3
|
||||
#define OP_DISABLE_FP_LONGPRESS 4
|
||||
#define OP_RESUME_FP_ENROLL 8
|
||||
#define OP_FINISH_FP_ENROLL 10
|
||||
|
||||
#define OP_DISPLAY_AOD_MODE 8
|
||||
#define OP_DISPLAY_NOTIFY_PRESS 9
|
||||
#define OP_DISPLAY_SET_DIM 10
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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->mFodCircleVisible = false;
|
||||
this->mIsEnrolling = false;
|
||||
this->mVendorFpService = IVendorFingerprintExtensions::getService();
|
||||
this->mVendorDisplayService = IOneplusDisplay::getService();
|
||||
}
|
||||
|
||||
Return<void> FingerprintInscreen::onStartEnroll() {
|
||||
this->mIsEnrolling = true;
|
||||
this->mVendorFpService->updateStatus(OP_DISABLE_FP_LONGPRESS);
|
||||
this->mVendorFpService->updateStatus(OP_RESUME_FP_ENROLL);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> FingerprintInscreen::onFinishEnroll() {
|
||||
this->mIsEnrolling = false;
|
||||
this->mVendorFpService->updateStatus(OP_FINISH_FP_ENROLL);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> FingerprintInscreen::onPress() {
|
||||
if (mIsEnrolling) {
|
||||
this->mVendorDisplayService->setMode(OP_DISPLAY_SET_DIM, 1);
|
||||
}
|
||||
this->mVendorDisplayService->setMode(OP_DISPLAY_NOTIFY_PRESS, 1);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> FingerprintInscreen::onRelease() {
|
||||
this->mVendorDisplayService->setMode(OP_DISPLAY_SET_DIM, 0);
|
||||
this->mVendorDisplayService->setMode(OP_DISPLAY_NOTIFY_PRESS, 0);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> FingerprintInscreen::onShowFODView() {
|
||||
this->mFodCircleVisible = true;
|
||||
this->mVendorDisplayService->setMode(OP_DISPLAY_AOD_MODE, 0);
|
||||
this->mVendorDisplayService->setMode(OP_DISPLAY_SET_DIM, 0);
|
||||
this->mVendorDisplayService->setMode(OP_DISPLAY_NOTIFY_PRESS, 0);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> FingerprintInscreen::onHideFODView() {
|
||||
this->mFodCircleVisible = false;
|
||||
this->mVendorDisplayService->setMode(OP_DISPLAY_AOD_MODE, 0);
|
||||
this->mVendorDisplayService->setMode(OP_DISPLAY_SET_DIM, 0);
|
||||
this->mVendorDisplayService->setMode(OP_DISPLAY_NOTIFY_PRESS, 0);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<bool> FingerprintInscreen::handleAcquired(int32_t acquiredInfo, int32_t vendorCode) {
|
||||
std::lock_guard<std::mutex> _lock(mCallbackLock);
|
||||
if (mCallback == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (acquiredInfo == FINGERPRINT_ACQUIRED_VENDOR) {
|
||||
if (mFodCircleVisible && vendorCode == 0) {
|
||||
Return<void> ret = mCallback->onFingerDown();
|
||||
if (!ret.isOk()) {
|
||||
LOG(ERROR) << "FingerDown() error: " << ret.description();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mFodCircleVisible && vendorCode == 1) {
|
||||
Return<void> ret = mCallback->onFingerUp();
|
||||
if (!ret.isOk()) {
|
||||
LOG(ERROR) << "FingerUp() error: " << ret.description();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Return<bool> FingerprintInscreen::handleError(int32_t error, int32_t vendorCode) {
|
||||
switch (error) {
|
||||
case FINGERPRINT_ERROR_CANCELED:
|
||||
if (vendorCode == 0) {
|
||||
this->mIsEnrolling = false;
|
||||
}
|
||||
return false;
|
||||
case FINGERPRINT_ERROR_VENDOR:
|
||||
// Ignore vendorCode 6
|
||||
return vendorCode == 6;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Return<void> FingerprintInscreen::setLongPressEnabled(bool enabled) {
|
||||
this->mVendorFpService->updateStatus(
|
||||
enabled ? OP_ENABLE_FP_LONGPRESS : OP_DISABLE_FP_LONGPRESS);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<int32_t> FingerprintInscreen::getDimAmount(int32_t) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 FOD_POS_X;
|
||||
}
|
||||
|
||||
Return<int32_t> FingerprintInscreen::getPositionY() {
|
||||
return FOD_POS_Y;
|
||||
}
|
||||
|
||||
Return<int32_t> FingerprintInscreen::getSize() {
|
||||
return FOD_SIZE;
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace inscreen
|
||||
} // namespace fingerprint
|
||||
} // namespace biometrics
|
||||
} // namespace lineage
|
||||
} // namespace vendor
|
||||
Reference in New Issue
Block a user