From dd4c1d5034a7da2e85ab82013b39b6dda89ef07d Mon Sep 17 00:00:00 2001 From: Brayden Zee Date: Mon, 7 Apr 2025 05:14:05 -0400 Subject: [PATCH] fingerprint: allow fprint to suspend and cancel verify for us (#722) * fingerprint: allow fprint to suspend and cancel verify for us * fingerprint: fix formatting --- src/auth/Fingerprint.cpp | 30 ++++++++---------------------- src/auth/Fingerprint.hpp | 12 +++++------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/auth/Fingerprint.cpp b/src/auth/Fingerprint.cpp index d0ba1b7..9bcc36b 100644 --- a/src/auth/Fingerprint.cpp +++ b/src/auth/Fingerprint.cpp @@ -65,20 +65,13 @@ void CFingerprint::init() { // When entering sleep, the wake signal will trigger startVerify(). if (m_sDBUSState.sleeping) return; - inhibitSleep(); startVerify(); }); m_sDBUSState.login->uponSignal("PrepareForSleep").onInterface(LOGIN_MANAGER).call([this](bool start) { Debug::log(LOG, "fprint: PrepareForSleep (start: {})", start); - if (start) { - m_sDBUSState.sleeping = true; - stopVerify(); - m_sDBUSState.inhibitLock.reset(); - } else { - m_sDBUSState.sleeping = false; - inhibitSleep(); + m_sDBUSState.sleeping = start; + if (!m_sDBUSState.sleeping && !m_sDBUSState.verifying) startVerify(); - } }); } @@ -111,18 +104,6 @@ std::shared_ptr CFingerprint::getConnection() { return m_sDBUSState.connection; } -void CFingerprint::inhibitSleep() { - m_sDBUSState.login->callMethodAsync("Inhibit") - .onInterface(LOGIN_MANAGER) - .withArguments("sleep", "hyprlock", "Fingerprint verifcation must be stopped before sleep", "delay") - .uponReplyInvoke([this](std::optional e, sdbus::UnixFd fd) { - if (e) - Debug::log(WARN, "fprint: could not inhibit sleep: {}", e->what()); - else - m_sDBUSState.inhibitLock = fd; - }); -} - bool CFingerprint::createDeviceProxy() { auto proxy = sdbus::createProxy(*m_sDBUSState.connection, FPRINT, sdbus::ObjectPath{"/net/reactivated/Fprint/Manager"}); @@ -163,8 +144,11 @@ void CFingerprint::handleVerifyStatus(const std::string& result, bool done) { auto matchResult = s_mapStringToTestType[result]; bool authenticated = false; bool retry = false; - if (m_sDBUSState.sleeping && matchResult != MATCH_DISCONNECTED) + if (m_sDBUSState.sleeping) { + stopVerify(); + Debug::log(LOG, "fprint: device suspended"); return; + } switch (matchResult) { case MATCH_INVALID: Debug::log(WARN, "fprint: unknown status: {}", result); break; case MATCH_NO_MATCH: @@ -229,6 +213,7 @@ void CFingerprint::claimDevice() { } void CFingerprint::startVerify(bool isRetry) { + m_sDBUSState.verifying = true; if (!m_sDBUSState.device) { if (!createDeviceProxy()) return; @@ -256,6 +241,7 @@ void CFingerprint::startVerify(bool isRetry) { } bool CFingerprint::stopVerify() { + m_sDBUSState.verifying = false; if (!m_sDBUSState.device) return false; try { diff --git a/src/auth/Fingerprint.hpp b/src/auth/Fingerprint.hpp index fc4acf8..404a5ca 100644 --- a/src/auth/Fingerprint.hpp +++ b/src/auth/Fingerprint.hpp @@ -29,12 +29,12 @@ class CFingerprint : public IAuthImplementation { std::shared_ptr connection; std::unique_ptr login; std::unique_ptr device; - sdbus::UnixFd inhibitLock; - bool abort = false; - bool done = false; - int retries = 0; - bool sleeping = false; + bool abort = false; + bool done = false; + int retries = 0; + bool sleeping = false; + bool verifying = false; } m_sDBUSState; std::string m_sFingerprintReady; @@ -45,8 +45,6 @@ class CFingerprint : public IAuthImplementation { void handleVerifyStatus(const std::string& result, const bool done); - void inhibitSleep(); - bool createDeviceProxy(); void claimDevice(); void startVerify(bool isRetry = false);