2019-07-01 19:32:47 -04:00
|
|
|
/*
|
|
|
|
* 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 <fstream>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#define COMMAND_NIT 10
|
2020-02-16 20:18:38 -05:00
|
|
|
#define PARAM_NIT_FOD 1
|
2019-07-01 19:32:47 -04:00
|
|
|
#define PARAM_NIT_NONE 0
|
|
|
|
|
|
|
|
#define FOD_HBM_PATH "/sys/devices/platform/soc/soc:qcom,dsi-display/fod_hbm"
|
|
|
|
#define FOD_HBM_ON 1
|
|
|
|
#define FOD_HBM_OFF 0
|
|
|
|
|
|
|
|
#define FOD_STATUS_PATH "/sys/devices/virtual/touch/tp_dev/fod_status"
|
|
|
|
#define FOD_STATUS_ON 1
|
|
|
|
#define FOD_STATUS_OFF 0
|
|
|
|
|
|
|
|
#define FOD_SENSOR_X 445
|
|
|
|
#define FOD_SENSOR_Y 1931
|
|
|
|
#define FOD_SENSOR_SIZE 190
|
|
|
|
|
2019-11-20 07:24:58 -05:00
|
|
|
#define BRIGHTNESS_PATH "/sys/class/backlight/panel0-backlight/brightness"
|
|
|
|
|
2019-07-01 19:32:47 -04:00
|
|
|
namespace {
|
|
|
|
|
2019-11-20 07:24:58 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-07-01 19:32:47 -04:00
|
|
|
template <typename T>
|
|
|
|
static void set(const std::string& path, const T& value) {
|
|
|
|
std::ofstream file(path);
|
|
|
|
file << value;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace vendor {
|
|
|
|
namespace lineage {
|
|
|
|
namespace biometrics {
|
|
|
|
namespace fingerprint {
|
|
|
|
namespace inscreen {
|
|
|
|
namespace V1_0 {
|
|
|
|
namespace implementation {
|
|
|
|
|
|
|
|
FingerprintInscreen::FingerprintInscreen() {
|
|
|
|
xiaomiFingerprintService = IXiaomiFingerprint::getService();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<int32_t> FingerprintInscreen::getPositionX() {
|
|
|
|
return FOD_SENSOR_X;
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<int32_t> FingerprintInscreen::getPositionY() {
|
|
|
|
return FOD_SENSOR_Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<int32_t> FingerprintInscreen::getSize() {
|
|
|
|
return FOD_SENSOR_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> FingerprintInscreen::onStartEnroll() {
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> FingerprintInscreen::onFinishEnroll() {
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> FingerprintInscreen::onPress() {
|
|
|
|
set(FOD_HBM_PATH, FOD_HBM_ON);
|
|
|
|
xiaomiFingerprintService->extCmd(COMMAND_NIT, PARAM_NIT_FOD);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> FingerprintInscreen::onRelease() {
|
|
|
|
set(FOD_HBM_PATH, FOD_HBM_OFF);
|
|
|
|
xiaomiFingerprintService->extCmd(COMMAND_NIT, PARAM_NIT_NONE);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> FingerprintInscreen::onShowFODView() {
|
|
|
|
set(FOD_STATUS_PATH, FOD_STATUS_ON);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> FingerprintInscreen::onHideFODView() {
|
|
|
|
set(FOD_STATUS_PATH, FOD_STATUS_OFF);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<bool> FingerprintInscreen::handleAcquired(int32_t acquiredInfo, int32_t vendorCode) {
|
2020-05-28 18:40:01 -04:00
|
|
|
LOG(ERROR) << "acquiredInfo: " << acquiredInfo << ", vendorCode: " << vendorCode;
|
2019-07-01 19:32:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<bool> FingerprintInscreen::handleError(int32_t error, int32_t vendorCode) {
|
2020-05-28 18:40:01 -04:00
|
|
|
LOG(ERROR) << "error: " << error << ", vendorCode: " << vendorCode;
|
2019-07-01 19:32:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> FingerprintInscreen::setLongPressEnabled(bool) {
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2019-12-30 19:06:45 -05:00
|
|
|
Return<int32_t> FingerprintInscreen::getDimAmount(int32_t /* brightness */) {
|
2019-11-20 07:24:58 -05:00
|
|
|
int realBrightness = get(BRIGHTNESS_PATH, 0);
|
2019-07-01 19:32:47 -04:00
|
|
|
float alpha;
|
|
|
|
|
2019-11-20 07:24:58 -05:00
|
|
|
if (realBrightness > 500) {
|
|
|
|
alpha = 1.0 - pow(realBrightness / 2047.0 * 430.0 / 600.0, 0.455);
|
2019-07-01 19:32:47 -04:00
|
|
|
} else {
|
2019-11-20 07:24:58 -05:00
|
|
|
alpha = 1.0 - pow(realBrightness / 1680.0, 0.455);
|
2019-07-01 19:32:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 255 * alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<bool> FingerprintInscreen::shouldBoostBrightness() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-30 19:06:45 -05:00
|
|
|
Return<void> FingerprintInscreen::setCallback(const sp<IFingerprintInscreenCallback>& /* callback */) {
|
2019-07-01 19:32:47 -04:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace implementation
|
|
|
|
} // namespace V1_0
|
|
|
|
} // namespace inscreen
|
|
|
|
} // namespace fingerprint
|
|
|
|
} // namespace biometrics
|
|
|
|
} // namespace lineage
|
|
|
|
} // namespace vendor
|