Skip to content

Commit faad679

Browse files
committed
Add dev setting for logging out of Google account
1 parent 412ca7f commit faad679

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

autofill/autofill-internal/src/main/java/com/duckduckgo/autofill/internal/AutofillInternalSettingsActivity.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.app.Activity
2121
import android.content.Context
2222
import android.content.Intent
2323
import android.os.Bundle
24+
import android.webkit.CookieManager
2425
import android.widget.Toast
2526
import androidx.activity.result.contract.ActivityResultContracts
2627
import androidx.core.content.IntentCompat
@@ -317,6 +318,10 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() {
317318
importCsvLauncher.launch(intent)
318319
}
319320

321+
binding.importPasswordsGoogleLogoutButton.setClickListener {
322+
clearGoogleCookies()
323+
}
324+
320325
binding.importPasswordsResetImportedFlagButton.setClickListener {
321326
lifecycleScope.launch(dispatchers.io()) {
322327
autofillStore.hasDismissedMainAppSettingsPromo = false
@@ -651,6 +656,21 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() {
651656
return LoginCredentials(username = username, password = password, domain = domain)
652657
}
653658

659+
private fun clearGoogleCookies() {
660+
val cookieManager = CookieManager.getInstance()
661+
val domain = ".google.com"
662+
663+
cookieManager.getCookie(domain)?.let { cookies ->
664+
cookies.split(";").forEach { cookie ->
665+
val cookieName = cookie.substringBefore("=").trim()
666+
cookieManager.setCookie(domain, "$cookieName=; Max-Age=0; Path=/")
667+
}
668+
}
669+
cookieManager.flush()
670+
671+
Toast.makeText(this, R.string.autofillDevSettingsGoogleLogoutSuccess, Toast.LENGTH_SHORT).show()
672+
}
673+
654674
companion object {
655675
fun intent(context: Context): Intent {
656676
return Intent(context, AutofillInternalSettingsActivity::class.java)

autofill/autofill-internal/src/main/res/layout/activity_autofill_internal_settings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@
124124
android:layout_height="wrap_content"
125125
app:primaryText="@string/autofillDevSettingsImportPasswordsImportPasswordsCsvTitle" />
126126

127+
<com.duckduckgo.common.ui.view.listitem.TwoLineListItem
128+
android:id="@+id/importPasswordsGoogleLogoutButton"
129+
android:layout_width="match_parent"
130+
android:layout_height="wrap_content"
131+
app:primaryText="@string/autofillDevSettingsImportPasswordsGoogleLogoutTitle"
132+
app:secondaryText="@string/autofillDevSettingsImportPasswordsGoogleInstruction" />
133+
127134
<com.duckduckgo.common.ui.view.listitem.TwoLineListItem
128135
android:id="@+id/importPasswordsResetImportedFlagButton"
129136
android:layout_width="match_parent"

autofill/autofill-internal/src/main/res/values/donottranslate.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
<string name="autofillDevSettingsImportPasswordsExportPasswordsOurAppTitle">Launch Google Passwords (normal tab)</string>
4444
<string name="autofillDevSettingsImportPasswordsExportPasswordsImportFlowTitle">Launch Google Passwords (import flow)</string>
4545
<string name="autofillDevSettingsImportPasswordsImportPasswordsCsvTitle">Import CSV</string>
46+
<string name="autofillDevSettingsImportPasswordsGoogleLogoutTitle">Google Account Logout</string>
47+
<string name="autofillDevSettingsImportPasswordsGoogleInstruction">Tap to clear all Google cookies</string>
48+
<string name="autofillDevSettingsGoogleLogoutSuccess">Google cookies cleared</string>
4649
<string name="autofillDevSettingsImportGooglePasswordsSuccessMessage" instruction="Placeholder is the number of passwords we were able to import">%1$d passwords imported from Google</string>
4750
<string name="autofillDevSettingsResetGooglePasswordsImportFlagTitle">Clear Previous Google Imports interactions</string>
4851
<string name="autofillDevSettingsResetGooglePasswordsImportFlagInstruction">Tap to forget whether we\'ve previously imported, what we chose when previously prompted etc…</string>

0 commit comments

Comments
 (0)