eqs: FOD implementation using moto panel hal

uses a timeout to disable fod hbm after 200ms, which should be
enough for the FPS to recognize/register/fail.
This commit is contained in:
SGCMarkus
2022-10-27 23:38:42 +02:00
parent 87fe9ec70b
commit 09191372b3
4 changed files with 52 additions and 72 deletions

View File

@@ -18,16 +18,7 @@ cc_binary {
"android.hardware.biometrics.fingerprint@2.2",
"android.hardware.biometrics.fingerprint@2.3",
"com.motorola.hardware.biometric.fingerprint@1.0",
],
}
cc_library_static {
name: "libudfps_extension.eqs",
srcs: ["UdfpsExtension.cpp"],
include_dirs: [
"frameworks/native/services/surfaceflinger/CompositionEngine/include"
],
header_libs: [
"generated_kernel_headers",
"com.motorola.hardware.display.panel@1.0",
"com.motorola.hardware.display.panel@1.1",
],
}

View File

@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "android.hardware.biometrics.fingerprint@2.3-service.eqs"
#define LOG_TAG "fingerprint@2.3-service.eqs"
#include "BiometricsFingerprint.h"
#include <chrono>
#include <android-base/logging.h>
#include <fstream>
#include <cmath>
@@ -29,8 +30,6 @@
#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 {
@@ -38,52 +37,36 @@ namespace fingerprint {
namespace V2_3 {
namespace implementation {
static bool readBool(int fd) {
char c;
int rc;
void BiometricsFingerprint::disableHighBrightFod() {
std::lock_guard<std::mutex> lock(mSetHbmFodMutex);
rc = lseek(fd, 0, SEEK_SET);
if (rc) {
LOG(ERROR) << "failed to seek fd, err: " << rc;
return false;
}
if(!hbmFodEnabled) return;
// this is no mistake, setColor sets the PanelMode, while setMode sets the panel color
displayPanelService->setColor((PanelColor) PanelMode::PANEL_MODE_NORMAL);
mMotoFingerprint->sendFodEvent(NOTIFY_FINGER_UP, {},
[](IMotFodEventResult, const hidl_vec<signed char>&) {});
rc = read(fd, &c, sizeof(char));
if (rc != 1) {
LOG(ERROR) << "failed to read bool from fd, err: " << rc;
return false;
}
hbmFodEnabled = false;
}
return c != '0';
void BiometricsFingerprint::enableHighBrightFod() {
std::lock_guard<std::mutex> lock(mSetHbmFodMutex);
if(hbmFodEnabled) return;
// this is no mistake, setColor sets the PanelMode, while setMode sets the panel color
displayPanelService->setColor((PanelColor) PanelMode::PANEL_MODE_HIGH_BRIGHT_FOD);
mMotoFingerprint->sendFodEvent(NOTIFY_FINGER_DOWN, {},
[](IMotFodEventResult, const hidl_vec<signed char>&) {});
hbmFodEnabled = true;
}
BiometricsFingerprint::BiometricsFingerprint() {
biometrics_2_1_service = IBiometricsFingerprint_2_1::getService();
mMotoFingerprint = IMotoFingerPrint::getService();
displayPanelService = IDisplayPanel::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();
hbmFodEnabled = false;
}
Return<uint64_t> BiometricsFingerprint::setNotify(const sp<IBiometricsFingerprintClientCallback>& clientCallback) {
@@ -107,7 +90,9 @@ Return<uint64_t> BiometricsFingerprint::getAuthenticatorId() {
}
Return<RequestStatus> BiometricsFingerprint::cancel() {
return biometrics_2_1_service->cancel();
auto ret = biometrics_2_1_service->cancel();
BiometricsFingerprint::onFingerUp();
return ret;
}
Return<RequestStatus> BiometricsFingerprint::enumerate() {
@@ -123,7 +108,9 @@ Return<RequestStatus> BiometricsFingerprint::setActiveGroup(uint32_t gid, const
}
Return<RequestStatus> BiometricsFingerprint::authenticate(uint64_t operationId, uint32_t gid) {
return biometrics_2_1_service->authenticate(operationId, gid);
auto ret = biometrics_2_1_service->authenticate(operationId, gid);
BiometricsFingerprint::onFingerUp();
return ret;
}
Return<bool> BiometricsFingerprint::isUdfps(uint32_t) {
@@ -131,10 +118,19 @@ Return<bool> BiometricsFingerprint::isUdfps(uint32_t) {
}
Return<void> BiometricsFingerprint::onFingerDown(uint32_t, uint32_t, float, float) {
BiometricsFingerprint::enableHighBrightFod();
std::thread([this]() {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
BiometricsFingerprint::onFingerUp();
}).detach();
return Void();
}
Return<void> BiometricsFingerprint::onFingerUp() {
BiometricsFingerprint::disableHighBrightFod();
return Void();
}

View File

@@ -21,6 +21,7 @@
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
#include <com/motorola/hardware/biometric/fingerprint/1.0/IMotoFingerPrint.h>
#include <com/motorola/hardware/display/panel/1.1/IDisplayPanel.h>
namespace android {
namespace hardware {
@@ -43,6 +44,10 @@ using ::com::motorola::hardware::biometric::fingerprint::V1_0::IMotoFingerPrint;
using ::com::motorola::hardware::biometric::fingerprint::V1_0::IMotFodEventType;
using ::com::motorola::hardware::biometric::fingerprint::V1_0::IMotFodEventResult;
using ::com::motorola::hardware::display::panel::V1_1::IDisplayPanel;
using ::com::motorola::hardware::display::panel::V1_0::PanelColor;
using ::com::motorola::hardware::display::panel::V1_0::PanelMode;
struct BiometricsFingerprint : public IBiometricsFingerprint {
BiometricsFingerprint();
// Methods from ::V2_1::IBiometricsFingerprint follow.
@@ -63,8 +68,15 @@ struct BiometricsFingerprint : public IBiometricsFingerprint {
Return<void> onFingerUp() override;
private:
void disableHighBrightFod();
void enableHighBrightFod();
bool hbmFodEnabled;
std::mutex mSetHbmFodMutex;
sp<IBiometricsFingerprint_2_1> biometrics_2_1_service;
sp<IMotoFingerPrint> mMotoFingerprint;
sp<IDisplayPanel> displayPanelService;
};
} // namespace implementation

View File

@@ -1,19 +0,0 @@
/*
* Copyright (C) 2022 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <compositionengine/UdfpsExtension.h>
#include <display/drm/sde_drm.h>
uint32_t getUdfpsZOrder(uint32_t z, bool touched) {
if (touched) {
z |= FOD_PRESSED_LAYER_ZORDER;
}
return z;
}
uint64_t getUdfpsUsageBits(uint64_t usageBits, bool) {
return usageBits;
}