Skip to content

Commit

Permalink
Fix race condition
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Nov 2, 2023
1 parent 760fdcd commit 7078217
Showing 1 changed file with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,36 +61,38 @@ class PassCodeManager(private val preferences: AppPreferences, private val clock
}

fun onActivityResumed(activity: Activity): Boolean {
var askedForPin = false
val timestamp = preferences.lockTimestamp
setSecureFlag(activity)

if (!isExemptActivity(activity)) {
val passcodeRequested = passCodeShouldBeRequested(timestamp)
val credentialsRequested = deviceCredentialsShouldBeRequested(timestamp, activity)
val shouldHideView = passcodeRequested || credentialsRequested
toggleActivityVisibility(shouldHideView, activity)
askedForPin = shouldHideView

if (passcodeRequested) {
requestPasscode(activity)
} else if (credentialsRequested) {
requestCredentials(activity)
synchronized(this) {
var askedForPin = false
val timestamp = preferences.lockTimestamp
setSecureFlag(activity)

if (!isExemptActivity(activity)) {
val passcodeRequested = passCodeShouldBeRequested(timestamp)
val credentialsRequested = deviceCredentialsShouldBeRequested(timestamp, activity)
val shouldHideView = passcodeRequested || credentialsRequested
toggleActivityVisibility(shouldHideView, activity)
askedForPin = shouldHideView

if (passcodeRequested) {
requestPasscode(activity)
} else if (credentialsRequested) {
requestCredentials(activity)
}
if (askedForPin) {
preferences.lockTimestamp = 0
}
}
if (askedForPin) {
preferences.lockTimestamp = 0

if (!askedForPin && preferences.lockTimestamp != 0L) {
updateLockTimestamp()
}
}

if (!askedForPin && preferences.lockTimestamp != 0L) {
updateLockTimestamp()
}
if (!isExemptActivity(activity)) {
addVisibleActivity(activity) // keep it AFTER passCodeShouldBeRequested was checked
}

if (!isExemptActivity(activity)) {
addVisibleActivity(activity) // keep it AFTER passCodeShouldBeRequested was checked
return askedForPin
}

return askedForPin
}

/**
Expand Down

0 comments on commit 7078217

Please sign in to comment.