From 3d9adcb194d68966b54d57d2892391e400e657d4 Mon Sep 17 00:00:00 2001 From: DaVinci9196 <150454414+DaVinci9196@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:08:48 +0800 Subject: [PATCH] Auth: Catch exceptions in AssistedSignInFragment (#2446) Fixes #2424 --- .../gms/auth/signin/AssistedSignInFragment.kt | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AssistedSignInFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AssistedSignInFragment.kt index deb274b41c..d3e03a0849 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AssistedSignInFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AssistedSignInFragment.kt @@ -82,11 +82,17 @@ class AssistedSignInFragment( private fun filterAccountsLogin(multiMethod: (List) -> Unit, loginMethod: (Account, Boolean) -> Unit) { lifecycleScope.launch { val allowAutoLoginAccounts = mutableListOf() - accounts.forEach { account -> - val authStatus = checkAppAuthStatus(requireContext(), clientPackageName, options, account) - if (authStatus) { - allowAutoLoginAccounts.add(account) + runCatching { + accounts.forEach { account -> + val authStatus = checkAppAuthStatus(requireContext(), clientPackageName, options, account) + if (authStatus) { + allowAutoLoginAccounts.add(account) + } } + }.onFailure { + Log.d(TAG, "filterAccountsLogin: error", it) + errorBlock(Status(CommonStatusCodes.INTERNAL_ERROR, "auth error")) + return@launch } if (accounts.size == 1) { loginMethod(accounts.first(), allowAutoLoginAccounts.isNotEmpty()) @@ -255,15 +261,20 @@ class AssistedSignInFragment( lastChooseAccountPermitted = permitted isSigningIn = true delay(3000) - val googleSignInAccount = withContext(Dispatchers.IO) { - performSignIn(requireContext(), clientPackageName, options, account, permitted) - } - if (googleSignInAccount == null) { - isSigningIn = false - prepareChooseLogin(account, showConsent = true, permitted = true) - return@launch + runCatching { + val googleSignInAccount = withContext(Dispatchers.IO) { + performSignIn(requireContext(), clientPackageName, options, account, permitted) + } + if (googleSignInAccount == null) { + isSigningIn = false + prepareChooseLogin(account, showConsent = true, permitted = true) + return@launch + } + loginBlock(googleSignInAccount) + }.onFailure { + Log.d(TAG, "startLogin: error", it) + errorBlock(Status(CommonStatusCodes.INTERNAL_ERROR, "signIn error")) } - loginBlock(googleSignInAccount) } }