Skip to content

Commit

Permalink
Allow accessing Google Password Manager via web view (#2415)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaVinci9196 authored Aug 4, 2024
1 parent ad08391 commit 8d7b1b0
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@

public class CallerInfo extends AutoSafeParcelable {
@Field(1)
public String s1;
public String source;
@Field(2)
public String s2;
public String medium;
@Field(3)
public String s3;
public String campaign;
@Field(4)
public String s4;
public String content;

@NonNull
@Override
public String toString() {
return "CallerInfo(" + s1 + "," + s2 + "," + s3 + "," + s4 + ")";
return "CallerInfo(" + source + "," + medium + "," + campaign + "," + content + ")";
}

public static final Creator<CallerInfo> CREATOR = new AutoCreator<>(CallerInfo.class);
Expand Down
7 changes: 7 additions & 0 deletions play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,13 @@
android:excludeFromRecents="true"
android:theme="@style/Theme.App.Translucent"/>

<activity
android:name="com.google.android.gms.credential.manager.PasswordManagerActivity"
android:exported="true"
android:process=":ui"
android:excludeFromRecents="true"
android:theme="@style/Theme.Translucent"/>

<service android:name="org.microg.gms.clearcut.ClearcutLoggerService">
<intent-filter>
<action android:name="com.google.android.gms.clearcut.service.START" />
Expand Down
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()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

package org.microg.gms.credential

import android.app.PendingIntent
import android.content.Context
import android.os.Bundle
import android.content.Intent
import android.os.Parcel
import android.util.Base64
import android.util.Log
Expand All @@ -20,11 +21,14 @@ import com.google.android.gms.common.api.internal.IStatusCallback
import com.google.android.gms.common.internal.ConnectionInfo
import com.google.android.gms.common.internal.GetServiceRequest
import com.google.android.gms.common.internal.IGmsCallbacks
import com.google.android.gms.credential.manager.EXTRA_KEY_ACCOUNT_NAME
import com.google.android.gms.credential.manager.PASSWORD_MANAGER_CLASS_NAME
import com.google.android.gms.credential.manager.common.IPendingIntentCallback
import com.google.android.gms.credential.manager.common.ISettingsCallback
import com.google.android.gms.credential.manager.firstparty.internal.ICredentialManagerService
import com.google.android.gms.credential.manager.invocationparams.CredentialManagerInvocationParams
import org.microg.gms.BaseService
import org.microg.gms.common.Constants
import org.microg.gms.common.GmsService
import org.microg.gms.common.GooglePackagePermission
import org.microg.gms.common.PackageUtils
Expand Down Expand Up @@ -53,13 +57,20 @@ class CredentialManagerService : BaseService(TAG, GmsService.CREDENTIAL_MANAGER)

private class CredentialManagerServiceImpl(private val context: Context, override val lifecycle: Lifecycle) : ICredentialManagerService.Stub(), LifecycleOwner {

override fun getCredentialManagerIntent(callback: IPendingIntentCallback?, params: CredentialManagerInvocationParams?) {
Log.d(TAG, "Not yet implemented: getCredentialManagerIntent $params")
override fun getCredentialManagerIntent(callback: IPendingIntentCallback?, params: CredentialManagerInvocationParams) {
Log.d(TAG, "Method getCredentialManagerIntent $params called")
lifecycleScope.launchWhenStarted {
try {
runCatching {
val intent = Intent().apply {
setClassName(Constants.GMS_PACKAGE_NAME, PASSWORD_MANAGER_CLASS_NAME)
putExtra(EXTRA_KEY_ACCOUNT_NAME, params.account.name)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
callback?.onPendingIntent(Status.SUCCESS, pendingIntent)
}.onFailure {
Log.d(TAG, "getCredentialManagerIntent error", it)
callback?.onPendingIntent(Status.INTERNAL_ERROR, null)
} catch (e: Exception) {
Log.w(TAG, e)
}
}
}
Expand Down

0 comments on commit 8d7b1b0

Please sign in to comment.