From edfba51e7c65c4a4c261d3d6e8ccc269e614d9da Mon Sep 17 00:00:00 2001 From: davinci9196 Date: Mon, 25 Nov 2024 15:39:31 +0800 Subject: [PATCH 1/2] Fixed the issue that the issue of clicking the account and password management settings page to upload files did not respond. --- .../manager/PasswordManagerActivity.kt | 48 ++++--------------- 1 file changed, 8 insertions(+), 40 deletions(-) diff --git a/play-services-core/src/main/kotlin/com/google/android/gms/credential/manager/PasswordManagerActivity.kt b/play-services-core/src/main/kotlin/com/google/android/gms/credential/manager/PasswordManagerActivity.kt index 89a1ae2504..2b45d61c21 100644 --- a/play-services-core/src/main/kotlin/com/google/android/gms/credential/manager/PasswordManagerActivity.kt +++ b/play-services-core/src/main/kotlin/com/google/android/gms/credential/manager/PasswordManagerActivity.kt @@ -1,15 +1,10 @@ package com.google.android.gms.credential.manager -import android.accounts.AccountManager +import android.content.Intent +import android.net.Uri import android.os.Bundle import android.util.Log -import android.view.View -import android.webkit.WebView -import android.widget.ProgressBar -import android.widget.RelativeLayout import androidx.appcompat.app.AppCompatActivity -import org.microg.gms.accountsettings.ui.WebViewHelper -import org.microg.gms.auth.AuthConstants const val PASSWORD_MANAGER_CLASS_NAME = "com.google.android.gms.credential.manager.PasswordManagerActivity" @@ -21,43 +16,16 @@ private const val PSW_MANAGER_PATH = "https://passwords.google.com/" class PasswordManagerActivity : AppCompatActivity() { - private lateinit var webView: WebView - - private val accountName: String? - get() = runCatching { intent?.getStringExtra(EXTRA_KEY_ACCOUNT_NAME) }.getOrNull() - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Log.d(TAG, "onCreate: start") - - val accounts = AccountManager.get(this).getAccountsByType(AuthConstants.DEFAULT_ACCOUNT_TYPE) - val realAccountName = accounts.find { it.name.equals(accountName) }?.name - - Log.d(TAG, "realAccountName: $realAccountName") - - val layout = RelativeLayout(this) - layout.addView(ProgressBar(this).apply { - layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT).apply { - addRule(RelativeLayout.CENTER_HORIZONTAL) - addRule(RelativeLayout.CENTER_VERTICAL) - } - isIndeterminate = true - }) - webView = WebView(this).apply { - layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT) - visibility = View.INVISIBLE - } - layout.addView(webView) - setContentView(layout) - WebViewHelper(this, webView).openWebView(PSW_MANAGER_PATH, realAccountName) - } - - override fun onBackPressed() { - if (this::webView.isInitialized && webView.canGoBack()) { - webView.goBack() - } else { - super.onBackPressed() + val targetIntent = Intent(Intent.ACTION_VIEW, Uri.parse(PSW_MANAGER_PATH)) + val resolveInfoList = packageManager.queryIntentActivities(targetIntent, 0) + Log.d(TAG, "resolveInfoList: $resolveInfoList") + if (resolveInfoList.isNotEmpty()) { + startActivity(targetIntent) } + finish() } } \ No newline at end of file From 0ad7649bfda6c2606bd3308d717fcd20e4cb58d7 Mon Sep 17 00:00:00 2001 From: davinci9196 Date: Mon, 25 Nov 2024 16:02:00 +0800 Subject: [PATCH 2/2] Allow account to log in directly --- .../manager/PasswordManagerActivity.kt | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/play-services-core/src/main/kotlin/com/google/android/gms/credential/manager/PasswordManagerActivity.kt b/play-services-core/src/main/kotlin/com/google/android/gms/credential/manager/PasswordManagerActivity.kt index 2b45d61c21..b405093a45 100644 --- a/play-services-core/src/main/kotlin/com/google/android/gms/credential/manager/PasswordManagerActivity.kt +++ b/play-services-core/src/main/kotlin/com/google/android/gms/credential/manager/PasswordManagerActivity.kt @@ -1,10 +1,17 @@ package com.google.android.gms.credential.manager +import android.accounts.AccountManager import android.content.Intent import android.net.Uri import android.os.Bundle import android.util.Log import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.lifecycleScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import org.microg.gms.auth.AuthConstants +import java.net.URLEncoder +import java.util.concurrent.TimeUnit const val PASSWORD_MANAGER_CLASS_NAME = "com.google.android.gms.credential.manager.PasswordManagerActivity" @@ -16,16 +23,33 @@ private const val PSW_MANAGER_PATH = "https://passwords.google.com/" class PasswordManagerActivity : AppCompatActivity() { + private val accountName: String? + get() = runCatching { intent?.getStringExtra(EXTRA_KEY_ACCOUNT_NAME) }.getOrNull() + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Log.d(TAG, "onCreate: start") - val targetIntent = Intent(Intent.ACTION_VIEW, Uri.parse(PSW_MANAGER_PATH)) - val resolveInfoList = packageManager.queryIntentActivities(targetIntent, 0) - Log.d(TAG, "resolveInfoList: $resolveInfoList") - if (resolveInfoList.isNotEmpty()) { - startActivity(targetIntent) + + val accounts = AccountManager.get(this).getAccountsByType(AuthConstants.DEFAULT_ACCOUNT_TYPE) + val account = accounts.find { it.name.equals(accountName) } + + Log.d(TAG, "realAccountName: ${account?.name}") + + lifecycleScope.launchWhenCreated { + val service = "weblogin:continue=" + URLEncoder.encode(PSW_MANAGER_PATH, "utf-8") + val auth = withContext(Dispatchers.IO) { + val bundle = AccountManager.get(this@PasswordManagerActivity).getAuthToken(account, service, null, null, null, null) + .getResult(10, TimeUnit.SECONDS) + bundle.getString(AccountManager.KEY_AUTHTOKEN) + } + val targetIntent = Intent(Intent.ACTION_VIEW, Uri.parse(auth)) + val resolveInfoList = packageManager.queryIntentActivities(targetIntent, 0) + Log.d(TAG, "resolveInfoList: $resolveInfoList") + if (resolveInfoList.isNotEmpty()) { + startActivity(targetIntent) + } + finish() } - finish() } } \ No newline at end of file