diff --git a/CHANGELOG b/CHANGELOG index 02b22f218..7aab2f09c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +KeePassDX(2.8.1) + * Capture exceptions in coroutines + KeePassDX(2.8) * Fix TOTP period (> 60s) * Fix searching in recycle bin diff --git a/app/build.gradle b/app/build.gradle index ece83fba9..4b04752ee 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId "com.kunzisoft.keepass" minSdkVersion 14 targetSdkVersion 29 - versionCode = 36 - versionName = "2.8" + versionCode = 37 + versionName = "2.8.1" multiDexEnabled true testApplicationId = "com.kunzisoft.keepass.tests" diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/PasswordActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/PasswordActivity.kt index 515e3ac08..162a89254 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/PasswordActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/PasswordActivity.kt @@ -227,7 +227,7 @@ open class PasswordActivity : SpecialModeActivity() { if (resultMessage != null && resultMessage.isNotEmpty()) { resultError = "$resultError $resultMessage" } - Log.e(TAG, resultError, resultException) + Log.e(TAG, resultError) Snackbar.make(activity_password_coordinator_layout, resultError, Snackbar.LENGTH_LONG).asError().show() diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt index 1faba33e3..b817e9f59 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt @@ -380,10 +380,8 @@ class Database { loaded = true } catch (e: LoadDatabaseException) { - Log.e("KPD", "Database::loadData", e) throw e } catch (e: Exception) { - Log.e("KPD", "Database::loadData", e) throw FileNotFoundDatabaseException() } finally { keyFileInputStream?.close() diff --git a/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseOpenNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseOpenNotificationService.kt index 810c913da..7dc6569a5 100644 --- a/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseOpenNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseOpenNotificationService.kt @@ -23,6 +23,7 @@ import android.app.PendingIntent import android.content.Context import android.content.Intent import android.os.Build +import android.os.IBinder import com.kunzisoft.keepass.R import com.kunzisoft.keepass.activities.GroupActivity import com.kunzisoft.keepass.database.element.Database @@ -47,11 +48,16 @@ class DatabaseOpenNotificationService: LockNotificationService() { super.actionOnLock() } - override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - super.onStartCommand(intent, flags, startId) + private fun checkIntent(intent: Intent?) { + val notificationBuilder = buildNewNotification().apply { + setSmallIcon(R.drawable.notification_ic_database_open) + setContentTitle(getString(R.string.database_opened)) + setAutoCancel(false) + } when(intent?.action) { ACTION_CLOSE_DATABASE -> { + startForeground(notificationId, notificationBuilder.build()) stopNotificationAndSendLock() } else -> { @@ -68,11 +74,8 @@ class DatabaseOpenNotificationService: LockNotificationService() { val database = Database.getInstance() if (database.loaded) { - startForeground(notificationId, buildNewNotification().apply { - setSmallIcon(R.drawable.notification_ic_database_open) - setContentTitle(getString(R.string.database_opened)) + startForeground(notificationId, notificationBuilder.apply { setContentText(database.name + " (" + database.version + ")") - setAutoCancel(false) setContentIntent(pendingDatabaseIntent) // Unfortunately swipe is disabled in lollipop+ setDeleteIntent(pendingDeleteIntent) @@ -80,11 +83,21 @@ class DatabaseOpenNotificationService: LockNotificationService() { pendingDeleteIntent) }.build()) } else { + startForeground(notificationId, notificationBuilder.build()) stopSelf() } } } + } + override fun onBind(intent: Intent): IBinder? { + checkIntent(intent) + return super.onBind(intent) + } + + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + super.onStartCommand(intent, flags, startId) + checkIntent(intent) return START_STICKY } diff --git a/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseTaskNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseTaskNotificationService.kt index 1ab1f9cee..9949d4a58 100644 --- a/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseTaskNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseTaskNotificationService.kt @@ -90,22 +90,13 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat } } - override fun onBind(intent: Intent): IBinder? { - return mActionTaskBinder - } - - override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - super.onStartCommand(intent, flags, startId) - - if (intent == null) return START_REDELIVER_INTENT - - val intentAction = intent.action - + private fun buildNotification(intent: Intent?) { var saveAction = true - if (intent.hasExtra(SAVE_DATABASE_KEY)) { + if (intent != null && intent.hasExtra(SAVE_DATABASE_KEY)) { saveAction = intent.getBooleanExtra(SAVE_DATABASE_KEY, saveAction) } + val intentAction = intent?.action val titleId: Int = when (intentAction) { ACTION_DATABASE_CREATE_TASK -> R.string.creating_database ACTION_DATABASE_LOAD_TASK -> R.string.loading_database @@ -127,6 +118,31 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat else R.string.do_not_kill_app + // Assign elements for updates + mTitleId = titleId + mMessageId = messageId + mWarningId = warningId + // Create the notification + startForeground(notificationId, buildNewNotification() + .setSmallIcon(R.drawable.notification_ic_database_load) + .setContentTitle(getString(intent?.getIntExtra(DATABASE_TASK_TITLE_KEY, titleId) ?: titleId)) + .setAutoCancel(false) + .setContentIntent(null).build()) + } + + override fun onBind(intent: Intent): IBinder? { + buildNotification(intent) + return mActionTaskBinder + } + + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + super.onStartCommand(intent, flags, startId) + + buildNotification(intent) + + if (intent == null) return START_REDELIVER_INTENT + + val intentAction = intent.action val actionRunnable: ActionRunnable? = when (intentAction) { ACTION_DATABASE_CREATE_TASK -> buildDatabaseCreateActionTask(intent) ACTION_DATABASE_LOAD_TASK -> buildDatabaseLoadActionTask(intent) @@ -157,26 +173,19 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat } actionRunnable?.let { actionRunnableNotNull -> - // Assign elements for updates - mTitleId = titleId - mMessageId = messageId - mWarningId = warningId - - // Create the notification - newNotification(intent.getIntExtra(DATABASE_TASK_TITLE_KEY, titleId)) // Build and launch the action mainScope.launch { executeAction(this@DatabaseTaskNotificationService, { sendBroadcast(Intent(DATABASE_START_TASK_ACTION).apply { - putExtra(DATABASE_TASK_TITLE_KEY, titleId) - putExtra(DATABASE_TASK_MESSAGE_KEY, messageId) - putExtra(DATABASE_TASK_WARNING_KEY, warningId) + putExtra(DATABASE_TASK_TITLE_KEY, mTitleId) + putExtra(DATABASE_TASK_MESSAGE_KEY, mMessageId) + putExtra(DATABASE_TASK_WARNING_KEY, mWarningId) }) mActionTaskListeners.forEach { actionTaskListener -> - actionTaskListener.onStartAction(titleId, messageId, warningId) + actionTaskListener.onStartAction(mTitleId, mMessageId, mWarningId) } }, @@ -208,8 +217,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat onPostExecute: (result: ActionRunnable.Result) -> Unit) { mAllowFinishAction.set(false) - // Stop the opening notification - DatabaseOpenNotificationService.stop(this) TimeoutHelper.temporarilyDisableTimeout() onPreExecute.invoke() withContext(Dispatchers.IO) { @@ -228,27 +235,20 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat result } withContext(Dispatchers.Main) { - onPostExecute.invoke(asyncResult.await()) - TimeoutHelper.releaseTemporarilyDisableTimeout() - // Start the opening notification - if (TimeoutHelper.checkTimeAndLockIfTimeout(this@DatabaseTaskNotificationService)) { - DatabaseOpenNotificationService.start(this@DatabaseTaskNotificationService) + try { + onPostExecute.invoke(asyncResult.await()) + } finally { + TimeoutHelper.releaseTemporarilyDisableTimeout() + // Start the opening notification + if (TimeoutHelper.checkTimeAndLockIfTimeout(this@DatabaseTaskNotificationService)) { + DatabaseOpenNotificationService.start(this@DatabaseTaskNotificationService) + } } } } } } - private fun newNotification(title: Int) { - - val builder = buildNewNotification() - .setSmallIcon(R.drawable.notification_ic_database_load) - .setContentTitle(getString(title)) - .setAutoCancel(false) - .setContentIntent(null) - startForeground(notificationId, builder.build()) - } - override fun updateMessage(resId: Int) { mMessageId = resId mActionTaskListeners.forEach { actionTaskListener -> diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/ActionRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/tasks/ActionRunnable.kt index aeb07cd84..3554c69e8 100644 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/ActionRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/ActionRunnable.kt @@ -20,6 +20,7 @@ package com.kunzisoft.keepass.tasks import android.os.Bundle +import android.util.Log import com.kunzisoft.keepass.database.exception.DatabaseException /** @@ -48,18 +49,26 @@ abstract class ActionRunnable: Runnable { result.isSuccess = false result.exception = null result.message = message + showLog() } protected fun setError(exception: Exception) { result.isSuccess = false result.exception = null result.message = exception.message + showLog() } protected fun setError(exception: DatabaseException) { result.isSuccess = false result.exception = exception result.message = exception.message + showLog() + } + + private fun showLog() { + val message = if (result.message != null) ", message=${result.message}" else "" + Log.e(TAG, "success=${result.isSuccess}$message", result.exception) } /** @@ -69,4 +78,8 @@ abstract class ActionRunnable: Runnable { var message: String? = null, var exception: DatabaseException? = null, var data: Bundle? = null) + + companion object { + private const val TAG = "ActionRunnable" + } } diff --git a/fastlane/metadata/android/en-US/changelogs/36.txt b/fastlane/metadata/android/en-US/changelogs/36.txt index f119964b3..484ec6a4e 100644 --- a/fastlane/metadata/android/en-US/changelogs/36.txt +++ b/fastlane/metadata/android/en-US/changelogs/36.txt @@ -1,7 +1,2 @@ - * Fix TOTP period (> 60s) - * Fix searching in recycle bin - * Settings to back to the previous keyboard during database credentials and after form filling - * Improving action tasks - * Improve recognition to reset app timeout - * Fix minor issues + * Capture exceptions in coroutines diff --git a/fastlane/metadata/android/fr-FR/changelogs/36.txt b/fastlane/metadata/android/fr-FR/changelogs/36.txt index 2fe8c2a72..543f4c19b 100644 --- a/fastlane/metadata/android/fr-FR/changelogs/36.txt +++ b/fastlane/metadata/android/fr-FR/changelogs/36.txt @@ -1,6 +1 @@ - * Correction de la période pour le TOTP (> 60s) - * Correction de la recherche dans la corbeille - * Paramètres pour revenir automatiquement au clavier précédent durant l'identification de la base et après le remplissage de formulaire - * Amélioration des tâches d'action - * Amélioration de la reconnaissance pour le temps écoulé - * Correction de problèmes mineurs + * Capture des exceptions dans les coroutines