mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Better service implementation
This commit is contained in:
@@ -45,20 +45,16 @@ class CipherDatabaseAction(context: Context) {
|
||||
private var mBinder: AdvancedUnlockNotificationService.AdvancedUnlockBinder? = null
|
||||
private var mServiceConnection: ServiceConnection? = null
|
||||
|
||||
fun initialize() {
|
||||
applicationContext.startService(mIntentAdvancedUnlockService)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun attachService(serviceAttached: () -> Unit) {
|
||||
private fun attachService(performedAction: () -> Unit) {
|
||||
// Check if a service is currently running else do nothing
|
||||
if (mBinder != null) {
|
||||
serviceAttached.invoke()
|
||||
performedAction.invoke()
|
||||
} else if (mServiceConnection == null) {
|
||||
mServiceConnection = object : ServiceConnection {
|
||||
override fun onServiceConnected(name: ComponentName?, serviceBinder: IBinder?) {
|
||||
mBinder = (serviceBinder as AdvancedUnlockNotificationService.AdvancedUnlockBinder)
|
||||
serviceAttached.invoke()
|
||||
performedAction.invoke()
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {
|
||||
@@ -66,11 +62,11 @@ class CipherDatabaseAction(context: Context) {
|
||||
mServiceConnection = null
|
||||
}
|
||||
}
|
||||
// bind Service
|
||||
mServiceConnection?.let {
|
||||
applicationContext.bindService(mIntentAdvancedUnlockService,
|
||||
it,
|
||||
mServiceConnection!!,
|
||||
Context.BIND_ABOVE_CLIENT)
|
||||
if (mBinder == null) {
|
||||
applicationContext.startService(mIntentAdvancedUnlockService)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,6 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
// Add old listener to enable the button, only be call here because of onCheckedChange bug
|
||||
onCheckedPasswordChangeListener?.onCheckedChanged(compoundButton, checked)
|
||||
}
|
||||
cipherDatabaseAction.initialize()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,10 +183,10 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
}
|
||||
Mode.EXTRACT_CREDENTIAL -> {
|
||||
// retrieve the encrypted value from preferences
|
||||
cipherDatabaseAction.getCipherDatabase(databaseFileUri) {
|
||||
it?.encryptedValue?.let { value ->
|
||||
cipherDatabaseAction.getCipherDatabase(databaseFileUri) { cipherDatabase ->
|
||||
cipherDatabase?.encryptedValue?.let { value ->
|
||||
biometricUnlockDatabaseHelper?.decryptData(value)
|
||||
}
|
||||
} ?: deleteEncryptedDatabaseKey()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -294,7 +293,7 @@ class AdvancedUnlockedManager(var context: FragmentActivity,
|
||||
openBiometricPrompt(biometricPrompt, cryptoObject, promptInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
} ?: deleteEncryptedDatabaseKey()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,9 +61,9 @@ class AdvancedUnlockNotificationService : NotificationService() {
|
||||
// Unfortunately swipe is disabled in lollipop+
|
||||
setDeleteIntent(pendingDeleteIntent)
|
||||
}
|
||||
// Not necessarilly a foreground service
|
||||
// startForeground(notificationId, notificationBuilder.build())
|
||||
notificationManager?.notify(notificationId, notificationBuilder.build())
|
||||
// Not necessarily a foreground service
|
||||
startForeground(notificationId, notificationBuilder.build())
|
||||
//notificationManager?.notify(notificationId, notificationBuilder.build())
|
||||
|
||||
if (intent?.action == ACTION_REMOVE_KEYS) {
|
||||
stopSelf()
|
||||
|
||||
Reference in New Issue
Block a user