mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Try to fix notification lock
This commit is contained in:
@@ -76,7 +76,7 @@ class ProgressDatabaseTaskProvider(private val activity: FragmentActivity) {
|
||||
var onActionFinish: ((actionTask: String,
|
||||
result: ActionRunnable.Result) -> Unit)? = null
|
||||
|
||||
private var intentDatabaseTask = Intent(activity, DatabaseTaskNotificationService::class.java)
|
||||
private var intentDatabaseTask = Intent(activity.applicationContext, DatabaseTaskNotificationService::class.java)
|
||||
|
||||
private var databaseTaskBroadcastReceiver: BroadcastReceiver? = null
|
||||
private var mBinder: DatabaseTaskNotificationService.ActionTaskBinder? = null
|
||||
@@ -219,12 +219,8 @@ class ProgressDatabaseTaskProvider(private val activity: FragmentActivity) {
|
||||
if (bundle != null)
|
||||
intentDatabaseTask.putExtras(bundle)
|
||||
intentDatabaseTask.action = actionTask
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
activity.startForegroundService(intentDatabaseTask)
|
||||
} else {
|
||||
activity.startService(intentDatabaseTask)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
----
|
||||
|
||||
@@ -178,12 +178,23 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
actionRunnable
|
||||
},
|
||||
{ result ->
|
||||
try {
|
||||
mActionTaskListeners.forEach { actionTaskListener ->
|
||||
actionTaskListener.onStopAction(intentAction!!, result)
|
||||
}
|
||||
|
||||
} finally {
|
||||
removeIntentData(intent)
|
||||
buildMessage(intent)
|
||||
TimeoutHelper.releaseTemporarilyDisableTimeout()
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(this@DatabaseTaskNotificationService)) {
|
||||
if (!mDatabase.loaded) {
|
||||
stopSelf()
|
||||
} else {
|
||||
// Restart the service to open lock notification
|
||||
startService(Intent(applicationContext,
|
||||
DatabaseTaskNotificationService::class.java))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sendBroadcast(Intent(DATABASE_STOP_TASK_ACTION))
|
||||
|
||||
@@ -191,11 +202,17 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
}
|
||||
)
|
||||
}
|
||||
// Relaunch action if failed
|
||||
return START_REDELIVER_INTENT
|
||||
}
|
||||
|
||||
return START_STICKY
|
||||
return when (intentAction) {
|
||||
ACTION_DATABASE_LOAD_TASK, null -> {
|
||||
START_STICKY
|
||||
}
|
||||
else -> {
|
||||
// Relaunch action if failed
|
||||
START_REDELIVER_INTENT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildMessage(intent: Intent?) {
|
||||
@@ -341,17 +358,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
result
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
try {
|
||||
onPostExecute.invoke(asyncResult.await())
|
||||
} finally {
|
||||
TimeoutHelper.releaseTemporarilyDisableTimeout()
|
||||
// Start the opening notification
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(this@DatabaseTaskNotificationService)) {
|
||||
if (!mDatabase.loaded) {
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user