From ec8e4e97677bf32bf0516b1905d0fa24ea738860 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 6 Oct 2022 18:47:09 +0600 Subject: [PATCH 1/2] 722-Fix_mail_app_crash_after_authentication_complete issue: https://gitlab.e.foundation/e/os/backlog/-/issues/722 Race-condition is observed in e-os-mail app after authentication completed. To resolve this, we need to check if the mail app is opening after the authentication, if yes, then we don't need to send broadcast to mail app that new account is added. --- .../at/bitfire/davdroid/MailAccountSyncHelper.kt | 16 +++++++++++++++- .../davdroid/ui/setup/AccountDetailsFragment.kt | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt b/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt index 66406e36e..5f3b65958 100644 --- a/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt +++ b/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt @@ -27,7 +27,11 @@ object MailAccountSyncHelper { private const val MAIL_RECEIVER_CLASS = "com.fsck.k9.account.AccountSyncReceiver" private const val ACTION_PREFIX = "foundation.e.accountmanager.account." - fun onAccountLoggedIn(applicationContext : Context?) { + fun onAccountLoggedIn(applicationContext : Context?, packageToBeOpened: String?) { + if (isOpeningMailAppActivity(packageToBeOpened)) { + return + } + val intent = getIntent() intent.action = ACTION_PREFIX + "create" applicationContext?.sendBroadcast(intent) @@ -51,4 +55,14 @@ object MailAccountSyncHelper { intent.component = ComponentName(MAIL_PACKAGE, MAIL_RECEIVER_CLASS) return intent } + + // if mail app's activity is needed to open after the auth, no need to send broadCast. + // because, sending broadcast will fail. The cause is, mail app will be opened in a new task + private fun isOpeningMailAppActivity(packageToBeOpened: String?): Boolean { + if (packageToBeOpened == null || packageToBeOpened != MAIL_PACKAGE) { + return false + } + + return true + } } \ No newline at end of file diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.kt b/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.kt index f76d27a60..26a940f49 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.kt +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.kt @@ -188,7 +188,7 @@ class AccountDetailsFragment : Fragment() { val packageToBeOpened = requireActivity().intent.getStringExtra(LoginActivity.OPEN_APP_PACKAGE_AFTER_AUTH) val activityToBeOpened = requireActivity().intent.getStringExtra(LoginActivity.OPEN_APP_ACTIVITY_AFTER_AUTH) openApp(packageToBeOpened, activityToBeOpened) - MailAccountSyncHelper.onAccountLoggedIn(context?.applicationContext) + MailAccountSyncHelper.onAccountLoggedIn(context?.applicationContext, packageToBeOpened) } private fun openApp(packageToBeOpened: String?, activityToBeOpened: String?) { -- GitLab From 6d14a13bc85280f2116b13179d7a5a32bbd600d1 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Thu, 6 Oct 2022 13:06:48 +0000 Subject: [PATCH 2/2] Apply 1 suggestion(s) to 1 file(s) --- app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt b/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt index 5f3b65958..cd83ad58d 100644 --- a/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt +++ b/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt @@ -27,7 +27,7 @@ object MailAccountSyncHelper { private const val MAIL_RECEIVER_CLASS = "com.fsck.k9.account.AccountSyncReceiver" private const val ACTION_PREFIX = "foundation.e.accountmanager.account." - fun onAccountLoggedIn(applicationContext : Context?, packageToBeOpened: String?) { + fun onAccountLoggedIn(applicationContext: Context?, packageToBeOpened: String?) { if (isOpeningMailAppActivity(packageToBeOpened)) { return } -- GitLab