Kill the task if PinActivity is cancelled
This commit is contained in:
parent
03c66315cb
commit
299bcc2bc7
|
@ -318,11 +318,12 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector {
|
||||||
if (requestCode == PinActivity.PIN_REQUEST_CODE) {
|
if (requestCode == PinActivity.PIN_REQUEST_CODE) {
|
||||||
when (resultCode) {
|
when (resultCode) {
|
||||||
Activity.RESULT_OK -> {
|
Activity.RESULT_OK -> {
|
||||||
|
Timber.v("Pin ok, unlock app")
|
||||||
pinLocker.unlock()
|
pinLocker.unlock()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
pinLocker.block()
|
// Remove the task, to be sure that PIN code will be requested when resumed
|
||||||
moveTaskToBack(true)
|
finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,16 +47,12 @@ class PinLocker @Inject constructor(
|
||||||
// App is locked, can be unlock
|
// App is locked, can be unlock
|
||||||
LOCKED,
|
LOCKED,
|
||||||
|
|
||||||
// App is blocked and can't be unlocked as long as the app is in foreground
|
// App is unlocked, the app can be used
|
||||||
BLOCKED,
|
|
||||||
|
|
||||||
// is unlocked, the app can be used
|
|
||||||
UNLOCKED
|
UNLOCKED
|
||||||
}
|
}
|
||||||
|
|
||||||
private val liveState = MutableLiveData<State>()
|
private val liveState = MutableLiveData<State>()
|
||||||
|
|
||||||
private var isBlocked = false
|
|
||||||
private var shouldBeLocked = true
|
private var shouldBeLocked = true
|
||||||
private var entersBackgroundTs = 0L
|
private var entersBackgroundTs = 0L
|
||||||
|
|
||||||
|
@ -66,13 +62,13 @@ class PinLocker @Inject constructor(
|
||||||
|
|
||||||
private fun computeState() {
|
private fun computeState() {
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
val state = if (isBlocked) {
|
val state = if (shouldBeLocked && pinCodeStore.hasEncodedPin()) {
|
||||||
State.BLOCKED
|
|
||||||
} else if (shouldBeLocked && pinCodeStore.hasEncodedPin()) {
|
|
||||||
State.LOCKED
|
State.LOCKED
|
||||||
} else {
|
} else {
|
||||||
State.UNLOCKED
|
State.UNLOCKED
|
||||||
}
|
}
|
||||||
|
.also { Timber.v("New state: $it") }
|
||||||
|
|
||||||
if (liveState.value != state) {
|
if (liveState.value != state) {
|
||||||
liveState.postValue(state)
|
liveState.postValue(state)
|
||||||
}
|
}
|
||||||
|
@ -85,23 +81,17 @@ class PinLocker @Inject constructor(
|
||||||
computeState()
|
computeState()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun block() {
|
|
||||||
Timber.v("Block app")
|
|
||||||
isBlocked = true
|
|
||||||
computeState()
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||||
fun entersForeground() {
|
fun entersForeground() {
|
||||||
val timeElapsedSinceBackground = SystemClock.elapsedRealtime() - entersBackgroundTs
|
val timeElapsedSinceBackground = SystemClock.elapsedRealtime() - entersBackgroundTs
|
||||||
shouldBeLocked = shouldBeLocked || timeElapsedSinceBackground >= getGracePeriod()
|
shouldBeLocked = shouldBeLocked || timeElapsedSinceBackground >= getGracePeriod()
|
||||||
Timber.v("App enters foreground after $timeElapsedSinceBackground ms spent in background")
|
Timber.v("App enters foreground after $timeElapsedSinceBackground ms spent in background shouldBeLocked: $shouldBeLocked")
|
||||||
computeState()
|
computeState()
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||||
fun entersBackground() {
|
fun entersBackground() {
|
||||||
isBlocked = false
|
Timber.v("App enters background")
|
||||||
entersBackgroundTs = SystemClock.elapsedRealtime()
|
entersBackgroundTs = SystemClock.elapsedRealtime()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +99,7 @@ class PinLocker @Inject constructor(
|
||||||
return if (vectorPreferences.useGracePeriod()) {
|
return if (vectorPreferences.useGracePeriod()) {
|
||||||
PERIOD_OF_GRACE_IN_MS
|
PERIOD_OF_GRACE_IN_MS
|
||||||
} else {
|
} else {
|
||||||
0L
|
0L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue