Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[devicelock] Fix asynchronous unlocking. Contributes to JB#45370
Move Failure handling from enterSecurityCode to unlockFinished.

Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
  • Loading branch information
Tomin1 committed May 3, 2019
1 parent b65e698 commit 1fa86b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/nemo-devicelock/host/hostauthenticationinput.h
Expand Up @@ -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,
Expand Down
45 changes: 27 additions & 18 deletions src/nemo-devicelock/host/hostdevicelock.cpp
Expand Up @@ -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;
Expand All @@ -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:
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit 1fa86b1

Please sign in to comment.