-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow accessing Google Password Manager via web view (#2415)
- Loading branch information
1 parent
ad08391
commit 8d7b1b0
Showing
4 changed files
with
92 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...core/src/main/kotlin/com/google/android/gms/credential/manager/PasswordManagerActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.google.android.gms.credential.manager | ||
|
||
import android.accounts.AccountManager | ||
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" | ||
|
||
const val EXTRA_KEY_ACCOUNT_NAME = "pwm.DataFieldNames.accountName" | ||
|
||
private const val TAG = "PasswordManagerActivity" | ||
|
||
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() | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters