From 887b0f3119a56892fc82ebf40b62520d9e8a607b Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 19 Jun 2021 12:12:26 +0200 Subject: [PATCH 1/3] Revert #1018 and change runOnUIThread by lifecyclescope(main) --- .../keepass/activities/PasswordActivity.kt | 5 ----- .../biometric/AdvancedUnlockFragment.kt | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) 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 b35b9d712..566238563 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/PasswordActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/PasswordActivity.kt @@ -462,11 +462,6 @@ open class PasswordActivity : SpecialModeActivity(), AdvancedUnlockFragment.Buil override fun onPause() { mProgressDatabaseTaskProvider?.unregisterProgressTask() - // To prevent biometric prompt to appearing outside of the app - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - advancedUnlockFragment?.disconnect(hideViews = false, closePrompt = true) - } - // Reinit locking activity UI variable LockingActivity.LOCKING_ACTIVITY_UI_VISIBLE_DURING_LOCK = null mAllowAutoOpenBiometricPrompt = true diff --git a/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockFragment.kt b/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockFragment.kt index 1c089e5f8..37d51e615 100644 --- a/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockFragment.kt +++ b/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockFragment.kt @@ -30,6 +30,7 @@ import android.view.* import androidx.annotation.RequiresApi import androidx.biometric.BiometricManager import androidx.biometric.BiometricPrompt +import androidx.lifecycle.lifecycleScope import com.getkeepsafe.taptargetview.TapTargetView import com.kunzisoft.keepass.R import com.kunzisoft.keepass.activities.stylish.StylishFragment @@ -38,6 +39,8 @@ import com.kunzisoft.keepass.database.exception.IODatabaseException import com.kunzisoft.keepass.education.PasswordActivityEducation import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.view.AdvancedUnlockInfoView +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedUnlockCallback { @@ -309,7 +312,7 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU @RequiresApi(Build.VERSION_CODES.M) private fun openAdvancedUnlockPrompt(cryptoPrompt: AdvancedUnlockCryptoPrompt) { - activity?.runOnUiThread { + lifecycleScope.launch(Dispatchers.Main) { if (allowOpenBiometricPrompt) { if (cryptoPrompt.isDeviceCredentialOperation) keepConnection = true @@ -450,7 +453,7 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU } override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { - activity?.runOnUiThread { + lifecycleScope.launch(Dispatchers.Main) { Log.e(TAG, "Biometric authentication error. Code : $errorCode Error : $errString") setAdvancedUnlockedMessageView(errString.toString()) } @@ -458,7 +461,7 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU @RequiresApi(Build.VERSION_CODES.M) override fun onAuthenticationFailed() { - activity?.runOnUiThread { + lifecycleScope.launch(Dispatchers.Main) { Log.e(TAG, "Biometric authentication failed, biometric not recognized") setAdvancedUnlockedMessageView(R.string.advanced_unlock_not_recognized) } @@ -466,7 +469,7 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU @RequiresApi(Build.VERSION_CODES.M) override fun onAuthenticationSucceeded() { - activity?.runOnUiThread { + lifecycleScope.launch(Dispatchers.Main) { when (biometricMode) { Mode.BIOMETRIC_UNAVAILABLE -> { } @@ -524,7 +527,7 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU } private fun showViews(show: Boolean) { - activity?.runOnUiThread { + lifecycleScope.launch(Dispatchers.Main) { mAdvancedUnlockInfoView?.visibility = if (show) View.VISIBLE else { @@ -535,20 +538,20 @@ class AdvancedUnlockFragment: StylishFragment(), AdvancedUnlockManager.AdvancedU @RequiresApi(Build.VERSION_CODES.M) private fun setAdvancedUnlockedTitleView(textId: Int) { - activity?.runOnUiThread { + lifecycleScope.launch(Dispatchers.Main) { mAdvancedUnlockInfoView?.setTitle(textId) } } @RequiresApi(Build.VERSION_CODES.M) private fun setAdvancedUnlockedMessageView(textId: Int) { - activity?.runOnUiThread { + lifecycleScope.launch(Dispatchers.Main) { mAdvancedUnlockInfoView?.setMessage(textId) } } private fun setAdvancedUnlockedMessageView(text: CharSequence) { - activity?.runOnUiThread { + lifecycleScope.launch(Dispatchers.Main) { mAdvancedUnlockInfoView?.message = text } } From de6312d3174979ee826dbb5fc094fa5413d92db5 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 19 Jun 2021 19:42:26 +0200 Subject: [PATCH 2/3] Fix binding service #1028 --- .../action/ProgressDatabaseTaskProvider.kt | 6 ----- .../DatabaseTaskNotificationService.kt | 27 +++++-------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/ProgressDatabaseTaskProvider.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/ProgressDatabaseTaskProvider.kt index e64e3a20c..00a22a779 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/action/ProgressDatabaseTaskProvider.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/ProgressDatabaseTaskProvider.kt @@ -23,7 +23,6 @@ import android.content.* import android.content.Context.BIND_ABOVE_CLIENT import android.content.Context.BIND_NOT_FOREGROUND import android.net.Uri -import android.os.Build import android.os.Bundle import android.os.IBinder import android.util.Log @@ -286,11 +285,6 @@ class ProgressDatabaseTaskProvider(private val activity: FragmentActivity) { readOnly: Boolean, cipherEntity: CipherDatabaseEntity?, fixDuplicateUuid: Boolean) { - try { - activity.stopService(intentDatabaseTask) - } catch (e: Exception) { - Log.e(TAG, "Unable to stop the service", e) - } start(Bundle().apply { putParcelable(DatabaseTaskNotificationService.DATABASE_URI_KEY, databaseUri) putParcelable(DatabaseTaskNotificationService.MAIN_CREDENTIAL_KEY, mainCredential) diff --git a/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt index ec29c28c5..1b552bf13 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt @@ -19,9 +19,7 @@ */ package com.kunzisoft.keepass.services -import android.app.ActivityManager import android.app.PendingIntent -import android.content.Context import android.content.Intent import android.net.Uri import android.os.* @@ -50,7 +48,6 @@ import com.kunzisoft.keepass.utils.* import com.kunzisoft.keepass.viewmodels.FileDatabaseInfo import kotlinx.coroutines.* import java.util.* -import java.util.concurrent.atomic.AtomicBoolean import kotlin.collections.ArrayList open class DatabaseTaskNotificationService : LockNotificationService(), ProgressTaskUpdater { @@ -63,7 +60,6 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress private var mActionTaskBinder = ActionTaskBinder() private var mActionTaskListeners = LinkedList() - private var mAllowFinishAction = AtomicBoolean() private var mActionRunning = false private var mDatabaseInfoListeners = LinkedList() @@ -86,19 +82,17 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress fun getService(): DatabaseTaskNotificationService = this@DatabaseTaskNotificationService fun addActionTaskListener(actionTaskListener: ActionTaskListener) { - mAllowFinishAction.set(true) - mActionTaskListeners.add(actionTaskListener) + if (!mActionTaskListeners.contains(actionTaskListener)) + mActionTaskListeners.add(actionTaskListener) } fun removeActionTaskListener(actionTaskListener: ActionTaskListener) { mActionTaskListeners.remove(actionTaskListener) - if (mActionTaskListeners.size == 0) { - mAllowFinishAction.set(false) - } } fun addDatabaseFileInfoListener(databaseInfoListener: DatabaseInfoListener) { - mDatabaseInfoListeners.add(databaseInfoListener) + if (!mDatabaseInfoListeners.contains(databaseInfoListener)) + mDatabaseInfoListeners.add(databaseInfoListener) } fun removeDatabaseFileInfoListener(databaseInfoListener: DatabaseInfoListener) { @@ -236,6 +230,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress mainScope.launch { executeAction(this@DatabaseTaskNotificationService, { + TimeoutHelper.temporarilyDisableTimeout() + mActionRunning = true sendBroadcast(Intent(DATABASE_START_TASK_ACTION).apply { @@ -427,23 +423,12 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress onPreExecute: () -> Unit, onExecute: (ProgressTaskUpdater?) -> ActionRunnable?, onPostExecute: (result: ActionRunnable.Result) -> Unit) { - mAllowFinishAction.set(false) - - TimeoutHelper.temporarilyDisableTimeout() onPreExecute.invoke() withContext(Dispatchers.IO) { onExecute.invoke(progressTaskUpdater)?.apply { val asyncResult: Deferred = async { - val startTime = System.currentTimeMillis() - var timeIsUp = false // Run the actionRunnable run() - // Wait onBind or 4 seconds max - while (!mAllowFinishAction.get() && !timeIsUp) { - delay(100) - if (startTime + 4000 < System.currentTimeMillis()) - timeIsUp = true - } result } withContext(Dispatchers.Main) { From bb2f641073f080e50c5e0c37e59a3b5c3bcc9dcf Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 19 Jun 2021 20:50:28 +0200 Subject: [PATCH 3/3] Update to 2.10.5 --- CHANGELOG | 4 ++++ app/build.gradle | 4 ++-- fastlane/metadata/android/en-US/changelogs/83.txt | 2 ++ fastlane/metadata/android/fr-FR/changelogs/83.txt | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/83.txt create mode 100644 fastlane/metadata/android/fr-FR/changelogs/83.txt diff --git a/CHANGELOG b/CHANGELOG index 9c1522249..d9b5b1ba1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +KeePassDX(2.10.5) + * Increase the saving speed of database #1028 + * Fix advanced unlocking by device credential #1029 + KeePassDX(2.10.4) * Hot fix to increase the opening speed of database #1028 diff --git a/app/build.gradle b/app/build.gradle index 4816537a6..62933eb17 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId "com.kunzisoft.keepass" minSdkVersion 15 targetSdkVersion 30 - versionCode = 82 - versionName = "2.10.4" + versionCode = 83 + versionName = "2.10.5" multiDexEnabled true testApplicationId = "com.kunzisoft.keepass.tests" diff --git a/fastlane/metadata/android/en-US/changelogs/83.txt b/fastlane/metadata/android/en-US/changelogs/83.txt new file mode 100644 index 000000000..6cabcb0be --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/83.txt @@ -0,0 +1,2 @@ + * Increase the saving speed of database #1028 + * Fix advanced unlocking by device credential #1029 \ No newline at end of file diff --git a/fastlane/metadata/android/fr-FR/changelogs/83.txt b/fastlane/metadata/android/fr-FR/changelogs/83.txt new file mode 100644 index 000000000..67e718451 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/83.txt @@ -0,0 +1,2 @@ + * Augmentation de la rapidité de sauvegarde de la base de données #1028 + * Correction du déverouillage avancé #1029 \ No newline at end of file