Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit e6ea5f6

Browse files
committed
PasswordStore: onboard users to Oreo autofill
Signed-off-by: Harsh Shandilya <[email protected]>
1 parent b0774fe commit e6ea5f6

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import android.content.pm.ShortcutInfo.Builder
1414
import android.content.pm.ShortcutManager
1515
import android.graphics.Color
1616
import android.graphics.drawable.Icon
17+
import android.net.Uri
1718
import android.os.Build
1819
import android.os.Bundle
20+
import android.provider.Settings
1921
import android.text.TextUtils
2022
import android.view.KeyEvent
2123
import android.view.Menu
@@ -43,6 +45,8 @@ import com.github.ajalt.timberkt.w
4345
import com.google.android.material.dialog.MaterialAlertDialogBuilder
4446
import com.google.android.material.snackbar.Snackbar
4547
import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher
48+
import com.zeapo.pwdstore.autofill.oreo.BrowserAutofillSupportLevel
49+
import com.zeapo.pwdstore.autofill.oreo.getInstalledBrowsersWithAutofillSupportLevel
4650
import com.zeapo.pwdstore.crypto.PgpActivity
4751
import com.zeapo.pwdstore.crypto.PgpActivity.Companion.getLongName
4852
import com.zeapo.pwdstore.git.BaseGitActivity
@@ -122,6 +126,43 @@ class PasswordStore : AppCompatActivity() {
122126
super.onCreate(savedInstance)
123127
setContentView(R.layout.activity_pwdstore)
124128

129+
// If user is eligible for Oreo autofill, prompt them to switch.
130+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
131+
!settings.getBoolean("seen_autofill_onboarding", false)) {
132+
MaterialAlertDialogBuilder(this).run {
133+
@SuppressLint("InflateParams")
134+
val layout =
135+
layoutInflater.inflate(R.layout.oreo_autofill_instructions, null)
136+
layout.findViewById<AppCompatTextView>(R.id.intro_text).visibility = View.GONE
137+
val supportedBrowsersTextView =
138+
layout.findViewById<AppCompatTextView>(R.id.supportedBrowsers)
139+
supportedBrowsersTextView.text =
140+
getInstalledBrowsersWithAutofillSupportLevel(context).joinToString(
141+
separator = "\n"
142+
) {
143+
val appLabel = it.first
144+
val supportDescription = when (it.second) {
145+
BrowserAutofillSupportLevel.None -> getString(R.string.oreo_autofill_no_support)
146+
BrowserAutofillSupportLevel.FlakyFill -> getString(R.string.oreo_autofill_flaky_fill_support)
147+
BrowserAutofillSupportLevel.PasswordFill -> getString(R.string.oreo_autofill_password_fill_support)
148+
BrowserAutofillSupportLevel.GeneralFill -> getString(R.string.oreo_autofill_general_fill_support)
149+
BrowserAutofillSupportLevel.GeneralFillAndSave -> getString(R.string.oreo_autofill_general_fill_and_save_support)
150+
}
151+
"$appLabel: $supportDescription"
152+
}
153+
setView(layout)
154+
setTitle(getString(R.string.autofill_onboarding_dialog_title))
155+
setMessage(getString(R.string.autofill_onboarding_dialog_message))
156+
setPositiveButton(R.string.dialog_ok) { _, _ ->
157+
settings.edit { putBoolean("seen_autofill_onboarding", true) }
158+
startActivity(Intent(Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE).apply {
159+
data = Uri.parse("package:${BuildConfig.APPLICATION_ID}")
160+
})
161+
}
162+
show()
163+
}
164+
}
165+
125166
model.currentDir.observe(this) { dir ->
126167
val basePath = getRepositoryDirectory(applicationContext).absoluteFile
127168
supportActionBar!!.apply {

app/src/main/res/layout/oreo_autofill_instructions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
android:paddingTop="20dp">
1515

1616
<androidx.appcompat.widget.AppCompatTextView
17+
android:id="@+id/intro_text"
1718
android:layout_width="wrap_content"
1819
android:layout_height="wrap_content"
1920
android:text="@string/oreo_autofill_enable_dialog_description"

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,6 @@
362362
<string name="git_operation_wrong_passphrase">Wrong passphrase</string>
363363
<string name="bottom_sheet_create_new_folder">Create new folder</string>
364364
<string name="bottom_sheet_create_new_password">Create new password</string>
365+
<string name="autofill_onboarding_dialog_title">New, revamped Autofill!</string>
366+
<string name="autofill_onboarding_dialog_message">In this release, Autofill support has been massively improved with advanced features like anti-phishing protection and enhanced reliability. If you have been holding out on using it because of the shortcomings on the previous version, you\'ll likely love the new iteration. Give it a shot!</string>
365367
</resources>

0 commit comments

Comments
 (0)