From 1fa86b1151418961b4b0309f27ba85f6e3c8395e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Lepp=C3=A4nen?= Date: Thu, 25 Apr 2019 18:10:43 +0300 Subject: [PATCH] [devicelock] Fix asynchronous unlocking. Contributes to JB#45370 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move Failure handling from enterSecurityCode to unlockFinished. Signed-off-by: Tomi Leppänen --- .../host/hostauthenticationinput.h | 2 +- src/nemo-devicelock/host/hostdevicelock.cpp | 45 +++++++++++-------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/nemo-devicelock/host/hostauthenticationinput.h b/src/nemo-devicelock/host/hostauthenticationinput.h index 1201b9f..d9b1a38 100644 --- a/src/nemo-devicelock/host/hostauthenticationinput.h +++ b/src/nemo-devicelock/host/hostauthenticationinput.h @@ -146,7 +146,7 @@ class HostAuthenticationInput : public HostObject virtual void confirmAuthentication(Authenticator::Method method) = 0; virtual void abortAuthentication(AuthenticationInput::Error error); -\ + // Signals void feedback( AuthenticationInput::Feedback feedback, diff --git a/src/nemo-devicelock/host/hostdevicelock.cpp b/src/nemo-devicelock/host/hostdevicelock.cpp index 7ecc81d..c7fd561 100644 --- a/src/nemo-devicelock/host/hostdevicelock.cpp +++ b/src/nemo-devicelock/host/hostdevicelock.cpp @@ -149,10 +149,6 @@ void HostDeviceLock::enterSecurityCode(const QString &code) break; case Authenticating: { switch (const int result = unlockWithCode(code)) { - case Evaluating: - case Success: - unlockFinished(result, Authenticator::SecurityCode); - break; case SecurityCodeExpired: m_state = EnteringNewSecurityCode; m_currentCode = code; @@ -164,21 +160,10 @@ void HostDeviceLock::enterSecurityCode(const QString &code) case LockedOut: lockedOut(); break; - default: { - const int maximum = maximumAttempts(); - - if (maximum > 0) { - feedback(AuthenticationInput::IncorrectSecurityCode, qMax(0, maximum - result)); - - if (result >= maximum) { - lockedOut(); - } - } else { - feedback(AuthenticationInput::IncorrectSecurityCode, -1); - } + default: + unlockFinished(result, Authenticator::SecurityCode); break; } - } break; } case EnteringNewSecurityCode: @@ -255,7 +240,9 @@ void HostDeviceLock::unlockFinished(int result, Authenticator::Method method) abortAuthentication(AuthenticationInput::SoftwareError); } break; - default: + case SecurityCodeExpired: + case SecurityCodeInHistory: + case LockedOut: if (m_state == Canceled) { m_state = Idle; @@ -266,6 +253,28 @@ void HostDeviceLock::unlockFinished(int result, Authenticator::Method method) abortAuthentication(AuthenticationInput::SoftwareError); } break; + default: { + int attemptsRemaining = -1; + const int maximum = maximumAttempts(); + + if (maximum > 0) { + if (result >= maximum) { + feedback(AuthenticationInput::IncorrectSecurityCode, 0); + lockedOut(); + break; + } else { + attemptsRemaining = maximum - result; + } + } + + if (m_state == Unlocking) { + m_state = Authenticating; + authenticationResumed(AuthenticationInput::IncorrectSecurityCode, {{ QStringLiteral("attemptsRemaining"), attemptsRemaining }}); + } else { + feedback(AuthenticationInput::IncorrectSecurityCode, attemptsRemaining); + } + break; + } } }