Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth: New abnormal account processing #2660

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.microg.gms.auth.signin
import android.accounts.Account
import android.app.Dialog
import android.content.DialogInterface
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.KeyEvent
Expand All @@ -19,6 +20,8 @@ import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
import androidx.collection.ArraySet
import androidx.collection.arraySetOf
import androidx.lifecycle.lifecycleScope
import com.google.android.gms.R
import com.google.android.gms.auth.api.identity.BeginSignInRequest
Expand Down Expand Up @@ -55,6 +58,7 @@ class AssistedSignInFragment(
private var container: FrameLayout? = null
private var loginJob: Job? = null
private var isSigningIn = false
private val authStatusList = arraySetOf<Pair<Account, Boolean?>>()

private var lastChooseAccount: Account? = null
private var lastChooseAccountPermitted = false
Expand All @@ -79,39 +83,32 @@ class AssistedSignInFragment(
}
}

private fun filterAccountsLogin(multiMethod: (List<Account>) -> Unit, loginMethod: (Account, Boolean) -> Unit) {
lifecycleScope.launch {
val allowAutoLoginAccounts = mutableListOf<Account>()
runCatching {
accounts.forEach { account ->
val authStatus = checkAccountAuthStatus(requireContext(), clientPackageName, options.scopes, 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())
return@launch
private suspend fun filterAccountsLogin(multiMethod: (ArraySet<Pair<Account, Boolean?>>) -> Unit, loginMethod: (Account, Boolean) -> Unit) {
accounts.forEach { account ->
val authStatus = try {
checkAccountAuthStatus(requireContext(), clientPackageName, options.scopes, account)
} catch (e: Exception) {
Log.d(TAG, "checkAccountAuthStatus: account:${account.name} auth error ", e)
null
}
val filterByAuthorizedAccounts = beginSignInRequest.googleIdTokenRequestOptions.filterByAuthorizedAccounts()
if (!filterByAuthorizedAccounts) {
multiMethod(allowAutoLoginAccounts)
return@launch
}
if (allowAutoLoginAccounts.size == 1) {
loginMethod(allowAutoLoginAccounts.first(), true)
return@launch
}
multiMethod(allowAutoLoginAccounts)
authStatusList.add(Pair(account, authStatus))
}
Log.d(TAG, "filterAccountsLogin: authStatusList: $authStatusList")
val checkAccounts = authStatusList.filter { it.second != null }
if (checkAccounts.size == 1) {
loginMethod(checkAccounts.first().first, checkAccounts.first().second!!)
return
}
val filterByAuthorizedAccounts = beginSignInRequest.googleIdTokenRequestOptions.filterByAuthorizedAccounts()
val authorizedAccounts = authStatusList.filter { it.second == true }
if (filterByAuthorizedAccounts && authorizedAccounts.isNotEmpty()) {
loginMethod(checkAccounts.first().first, true)
return
}
multiMethod(authStatusList)
}

private fun prepareMultiSignIn(allowAutoLoginAccounts: List<Account>) {
private fun prepareMultiSignIn(authorizedAccounts: ArraySet<Pair<Account, Boolean?>>) {
lifecycleScope.launch {
notifyCancelBtn(true)
container?.removeAllViews()
Expand All @@ -120,9 +117,10 @@ class AssistedSignInFragment(
chooseView.findViewById<TextView>(R.id.sign_multi_description).text =
String.format(getString(R.string.credentials_assisted_choose_account_subtitle), clientAppLabel)
val accountViews = chooseView.findViewById<LinearLayout>(R.id.sign_multi_account_container)
accounts.forEachIndexed { index, account ->
val accountView =
LayoutInflater.from(requireContext()).inflate(R.layout.assisted_signin_multi_layout, null)
val progress = chooseView.findViewById<ProgressBar>(R.id.sign_multi_progress)
authorizedAccounts.forEachIndexed { index, pair ->
val account = pair.first
val accountView = LayoutInflater.from(requireContext()).inflate(R.layout.assisted_signin_multi_layout, null)
accountView.findViewById<TextView>(R.id.account_email).text = account.name
withContext(Dispatchers.IO) {
PeopleManager.getDisplayName(requireContext(), account.name)
Expand All @@ -131,15 +129,23 @@ class AssistedSignInFragment(
PeopleManager.getOwnerAvatarBitmap(requireContext(), account.name, false)
?: PeopleManager.getOwnerAvatarBitmap(requireContext(), account.name, true)
}.let { accountView.findViewById<ImageView>(R.id.account_photo).setImageBitmap(it) }
accountView.findViewById<TextView>(R.id.account_description).text =
getString(R.string.credentials_assisted_signin_button_text_long)
if (pair.second != null) {
accountView.findViewById<TextView>(R.id.account_description).text =
getString(R.string.credentials_assisted_signin_button_text_long)
accountView.setOnClickListener {
progress.visibility = View.VISIBLE
prepareSignInLoading(account, pair.second!!)
}
} else {
accountView.findViewById<TextView>(R.id.account_description).apply {
text = getString(R.string.credentials_assisted_choose_account_error_tips)
setTextColor(Color.RED)
}
accountView.setOnClickListener(null)
}
if (index == accounts.size - 1) {
accountView.findViewById<View>(R.id.multi_account_line).visibility = View.GONE
}
accountView.setOnClickListener {
chooseView.findViewById<ProgressBar>(R.id.sign_multi_progress).visibility = View.VISIBLE
prepareSignInLoading(account, permitted = allowAutoLoginAccounts.any { it == account })
}
accountViews.addView(accountView)
}
container?.addView(chooseView)
Expand Down Expand Up @@ -173,7 +179,7 @@ class AssistedSignInFragment(

private fun prepareChooseLogin(account: Account, showConsent: Boolean = false, permitted: Boolean = false) {
lifecycleScope.launch {
notifyCancelBtn(true)
notifyCancelBtn(visible = true, backToMulti = authStatusList.size > 1)
container?.removeAllViews()
val reloadView =
LayoutInflater.from(requireContext()).inflate(R.layout.assisted_signin_back_consent_layout, null)
Expand Down Expand Up @@ -235,9 +241,6 @@ class AssistedSignInFragment(
super.onViewCreated(view, savedInstanceState)
Log.d(TAG, "onViewCreated")
cancelBtn = view.findViewById(R.id.cancel)
cancelBtn?.setOnClickListener {
dismiss()
}
container = view.findViewById(R.id.google_sign_in_container)
}

Expand All @@ -250,9 +253,16 @@ class AssistedSignInFragment(
super.onDismiss(dialog)
}

private fun notifyCancelBtn(visible: Boolean) {
private fun notifyCancelBtn(visible: Boolean, backToMulti:Boolean = false) {
cancelBtn?.visibility = if (visible) View.VISIBLE else View.GONE
cancelBtn?.isClickable = visible
cancelBtn?.setOnClickListener {
if (backToMulti) {
prepareMultiSignIn(authStatusList)
return@setOnClickListener
}
dismiss()
}
}

private fun startLogin(account: Account, permitted: Boolean = false) {
Expand Down
1 change: 1 addition & 0 deletions play-services-core/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ microG GmsCore 内置一套自由的 SafetyNet 实现,但是官方服务器要
<string name="credentials_assisted_signin_description">您可以在您的 Google 账号中管理“使用 Google 账号登录”功能。</string>
<string name="credentials_assisted_choose_account_label">选择账号</string>
<string name="credentials_assisted_choose_account_subtitle">以继续使用 %1$s</string>
<string name="credentials_assisted_choose_account_error_tips">账号异常</string>
<string name="credentials_assisted_signin_button_text_long">使用 Google 账号登录</string>
<string name="auth_package_override_request_title">允许 <b><xliff:g example="F-Droid">%1$s</xliff:g></b> 访问<xliff:g example="[email protected]">%2$s</xliff:g>?</string>
<string name="auth_package_override_request_message">&lt;b&gt;&lt;xliff:g example=\"F-Droid\"&gt;%1$s&lt;/xliff:g&gt;&lt;/b&gt; 想以 &lt;xliff:g example=\"F-Droid Inc.\"&gt;%3$s&lt;/xliff:g&gt;&lt;/b&gt; 的 &lt;b&gt;&lt;xliff:g example=\"F-Droid\"&gt;%2$s&lt;/xliff:g&gt; 访问你的账户。这可能授予访问你账户的权限。</string>
Expand Down
1 change: 1 addition & 0 deletions play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ Please set up a password, PIN, or pattern lock screen."</string>
<string name="credentials_assisted_signin_description">You can manage Sign in with Google in your Google Accounts.</string>
<string name="credentials_assisted_choose_account_label">Choose account</string>
<string name="credentials_assisted_choose_account_subtitle">to continue to %1$s</string>
<string name="credentials_assisted_choose_account_error_tips">Account abnormality</string>
<string name="credentials_assisted_signin_button_text_long">Sign in with Google</string>

<string name="limited_services_dialog_information">You are using the microG Limited Services. Unlike the usual microG Services, this flavor only works with apps using microG libraries, not those on Google Play. This means that most applications will ignore these services.</string>
Expand Down
Loading