mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
fix: Orientatino change in old device
This commit is contained in:
@@ -10,7 +10,11 @@ data class DeviceUnlockCryptoPrompt(
|
|||||||
@StringRes var descriptionId: Int? = null,
|
@StringRes var descriptionId: Int? = null,
|
||||||
var isDeviceCredentialOperation: Boolean,
|
var isDeviceCredentialOperation: Boolean,
|
||||||
var isBiometricOperation: Boolean
|
var isBiometricOperation: Boolean
|
||||||
)
|
) {
|
||||||
|
fun isOldCredentialOperation(): Boolean {
|
||||||
|
return !isBiometricOperation && isDeviceCredentialOperation
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum class DeviceUnlockCryptoPromptType {
|
enum class DeviceUnlockCryptoPromptType {
|
||||||
CREDENTIAL_ENCRYPTION, CREDENTIAL_DECRYPTION
|
CREDENTIAL_ENCRYPTION, CREDENTIAL_DECRYPTION
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import androidx.annotation.StringRes
|
|||||||
import androidx.media.app.NotificationCompat
|
import androidx.media.app.NotificationCompat
|
||||||
import com.kunzisoft.keepass.R
|
import com.kunzisoft.keepass.R
|
||||||
import com.kunzisoft.keepass.activities.GroupActivity
|
import com.kunzisoft.keepass.activities.GroupActivity
|
||||||
import com.kunzisoft.keepass.app.AppLifecycleObserver
|
|
||||||
import com.kunzisoft.keepass.app.database.CipherDatabaseAction
|
import com.kunzisoft.keepass.app.database.CipherDatabaseAction
|
||||||
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
|
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
|
||||||
import com.kunzisoft.keepass.database.ContextualDatabase
|
import com.kunzisoft.keepass.database.ContextualDatabase
|
||||||
@@ -626,16 +625,6 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
intent?.removeExtra(NEW_ELEMENT_KEY)
|
intent?.removeExtra(NEW_ELEMENT_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate() {
|
|
||||||
super.onCreate()
|
|
||||||
AppLifecycleObserver.lockBackgroundEvent = true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
super.onDestroy()
|
|
||||||
AppLifecycleObserver.lockBackgroundEvent = false
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute action with a coroutine
|
* Execute action with a coroutine
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package com.kunzisoft.keepass.services
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
|
import com.kunzisoft.keepass.app.AppLifecycleObserver
|
||||||
import com.kunzisoft.keepass.timeout.TimeoutHelper
|
import com.kunzisoft.keepass.timeout.TimeoutHelper
|
||||||
import com.kunzisoft.keepass.utils.LockReceiver
|
import com.kunzisoft.keepass.utils.LockReceiver
|
||||||
import com.kunzisoft.keepass.utils.registerLockReceiver
|
import com.kunzisoft.keepass.utils.registerLockReceiver
|
||||||
@@ -35,6 +36,7 @@ abstract class LockNotificationService : NotificationService() {
|
|||||||
protected open fun actionOnLock() {
|
protected open fun actionOnLock() {
|
||||||
// Stop the service in all cases
|
// Stop the service in all cases
|
||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
|
AppLifecycleObserver.lockBackgroundEvent = false
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,19 +161,28 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
|||||||
checkUnlockAvailability(databaseUri)
|
checkUnlockAvailability(databaseUri)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun disconnect() {
|
private fun showPendingIfNecessary() {
|
||||||
|
// Reassign prompt state to open again if necessary
|
||||||
|
if (cryptoPrompt?.isOldCredentialOperation() != true
|
||||||
|
&& uiState.value.cryptoPromptState == DeviceUnlockPromptMode.IDLE_SHOW) {
|
||||||
|
cryptoPromptShowPending = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun disconnectDatabase() {
|
||||||
this.databaseUri = null
|
this.databaseUri = null
|
||||||
cipherDatabaseListener?.let {
|
cipherDatabaseListener?.let {
|
||||||
cipherDatabaseAction.unregisterDatabaseListener(it)
|
cipherDatabaseAction.unregisterDatabaseListener(it)
|
||||||
}
|
}
|
||||||
// Reassign prompt state to open again if necessary
|
|
||||||
if (uiState.value.cryptoPromptState == DeviceUnlockPromptMode.IDLE_SHOW) {
|
|
||||||
cryptoPromptShowPending = true
|
|
||||||
}
|
|
||||||
clear()
|
clear()
|
||||||
changeMode(DeviceUnlockMode.BIOMETRIC_UNAVAILABLE)
|
changeMode(DeviceUnlockMode.BIOMETRIC_UNAVAILABLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun disconnect() {
|
||||||
|
showPendingIfNecessary()
|
||||||
|
disconnectDatabase()
|
||||||
|
}
|
||||||
|
|
||||||
fun databaseFileLoaded(databaseUri: Uri?) {
|
fun databaseFileLoaded(databaseUri: Uri?) {
|
||||||
// To get device credential unlock result, only if same database uri
|
// To get device credential unlock result, only if same database uri
|
||||||
if (databaseUri != null
|
if (databaseUri != null
|
||||||
@@ -182,7 +191,7 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
|||||||
connect(databaseUri)
|
connect(databaseUri)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
disconnect()
|
disconnectDatabase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,11 +328,14 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
|||||||
autoOpen: Boolean = false
|
autoOpen: Boolean = false
|
||||||
) {
|
) {
|
||||||
this@DeviceUnlockViewModel.cryptoPrompt = cryptoPrompt
|
this@DeviceUnlockViewModel.cryptoPrompt = cryptoPrompt
|
||||||
if (autoOpen && PreferencesUtil.isAdvancedUnlockPromptAutoOpenEnable(getApplication()))
|
if (cryptoPromptShowPending
|
||||||
|
|| (autoOpen && PreferencesUtil.isAdvancedUnlockPromptAutoOpenEnable(getApplication())))
|
||||||
showPrompt()
|
showPrompt()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showPrompt() {
|
fun showPrompt() {
|
||||||
|
AppLifecycleObserver.lockBackgroundEvent = true
|
||||||
|
isAutoOpenBiometricPromptAllowed = false
|
||||||
cryptoPromptShowPending = false
|
cryptoPromptShowPending = false
|
||||||
_uiState.update { currentState ->
|
_uiState.update { currentState ->
|
||||||
currentState.copy(
|
currentState.copy(
|
||||||
@@ -333,7 +345,6 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun promptShown() {
|
fun promptShown() {
|
||||||
isAutoOpenBiometricPromptAllowed = false
|
|
||||||
_uiState.update { currentState ->
|
_uiState.update { currentState ->
|
||||||
currentState.copy(
|
currentState.copy(
|
||||||
cryptoPromptState = DeviceUnlockPromptMode.IDLE_SHOW
|
cryptoPromptState = DeviceUnlockPromptMode.IDLE_SHOW
|
||||||
@@ -378,7 +389,6 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
|||||||
onPromptRequested(
|
onPromptRequested(
|
||||||
cryptoPrompt,
|
cryptoPrompt,
|
||||||
autoOpen = isAutoOpenBiometricPromptAllowed
|
autoOpen = isAutoOpenBiometricPromptAllowed
|
||||||
|| cryptoPromptShowPending
|
|
||||||
)
|
)
|
||||||
} ?: setException(Exception("AdvancedUnlockManager not initialized"))
|
} ?: setException(Exception("AdvancedUnlockManager not initialized"))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -420,7 +430,7 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun clear(checkOperation: Boolean = false) {
|
fun clear(checkOperation: Boolean = false) {
|
||||||
if (!checkOperation || cryptoPrompt?.isDeviceCredentialOperation != true) {
|
if (!checkOperation || cryptoPrompt?.isOldCredentialOperation() != true) {
|
||||||
cryptoPrompt = null
|
cryptoPrompt = null
|
||||||
deviceUnlockManager = null
|
deviceUnlockManager = null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user