2019-07-01 19:32:47 -04:00
|
|
|
/*
|
2020-02-10 19:50:36 -05:00
|
|
|
* Copyright (C) 2019-2020 The LineageOS Project
|
2019-07-01 19:32:47 -04:00
|
|
|
*
|
|
|
|
* 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>
|
2020-05-28 18:03:15 -04:00
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <sys/stat.h>
|
2019-07-01 19:32:47 -04:00
|
|
|
|
2019-07-02 09:05:43 -04:00
|
|
|
#define FINGERPRINT_ACQUIRED_VENDOR 6
|
|
|
|
|
2019-07-01 19:32:47 -04:00
|
|
|
#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
|
|
|
|
|
2020-02-10 19:50:36 -05:00
|
|
|
#define TOUCH_FOD_ENABLE 10
|
2019-07-01 19:32:47 -04:00
|
|
|
|
2020-05-28 18:03:15 -04:00
|
|
|
#define FOD_UI_PATH "/sys/devices/platform/soc/soc:qcom,dsi-display/fod_ui"
|
|
|
|
|
2019-07-01 19:32:47 -04:00
|
|
|
#define FOD_SENSOR_X 445
|
|
|
|
#define FOD_SENSOR_Y 1931
|
|
|
|
#define FOD_SENSOR_SIZE 190
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-05-28 18:03:15 -04:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2019-07-01 19:32:47 -04:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace vendor {
|
|
|
|
namespace lineage {
|
|
|
|
namespace biometrics {
|
|
|
|
namespace fingerprint {
|
|
|
|
namespace inscreen {
|
|
|
|
namespace V1_0 {
|
|
|
|
namespace implementation {
|
|
|
|
|
|
|
|
FingerprintInscreen::FingerprintInscreen() {
|
2020-02-10 19:50:36 -05:00
|
|
|
touchFeatureService = ITouchFeature::getService();
|
2019-07-01 19:32:47 -04:00
|
|
|
xiaomiFingerprintService = IXiaomiFingerprint::getService();
|
2020-05-28 18:03:15 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
xiaomiFingerprintService->extCmd(COMMAND_NIT,
|
|
|
|
readBool(fd) ? PARAM_NIT_FOD : PARAM_NIT_NONE);
|
|
|
|
}
|
|
|
|
}).detach();
|
2019-07-01 19:32:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> FingerprintInscreen::onRelease() {
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> FingerprintInscreen::onShowFODView() {
|
2020-02-10 19:50:36 -05:00
|
|
|
touchFeatureService->setTouchMode(TOUCH_FOD_ENABLE, 1);
|
2019-07-01 19:32:47 -04:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> FingerprintInscreen::onHideFODView() {
|
2020-02-10 19:50:36 -05:00
|
|
|
touchFeatureService->resetTouchMode(TOUCH_FOD_ENABLE);
|
2019-07-01 19:32:47 -04:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<bool> FingerprintInscreen::handleAcquired(int32_t acquiredInfo, int32_t vendorCode) {
|
2019-07-02 09:05:43 -04:00
|
|
|
std::lock_guard<std::mutex> _lock(mCallbackLock);
|
|
|
|
if (mCallback == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (acquiredInfo == FINGERPRINT_ACQUIRED_VENDOR) {
|
|
|
|
if (vendorCode == 0) {
|
|
|
|
Return<void> ret = mCallback->onFingerDown();
|
|
|
|
if (!ret.isOk()) {
|
|
|
|
LOG(ERROR) << "FingerDown() error: " << ret.description();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vendorCode == 1) {
|
|
|
|
Return<void> ret = mCallback->onFingerUp();
|
|
|
|
if (!ret.isOk()) {
|
|
|
|
LOG(ERROR) << "FingerUp() error: " << ret.description();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 */) {
|
2020-05-23 06:35:10 -04:00
|
|
|
return 0;
|
2019-07-01 19:32:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Return<bool> FingerprintInscreen::shouldBoostBrightness() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-02 09:05:43 -04:00
|
|
|
Return<void> FingerprintInscreen::setCallback(const sp<IFingerprintInscreenCallback>& callback) {
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> _lock(mCallbackLock);
|
|
|
|
mCallback = 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
|