@@ -14,8 +14,10 @@ import android.content.pm.ShortcutInfo.Builder
1414import android.content.pm.ShortcutManager
1515import android.graphics.Color
1616import android.graphics.drawable.Icon
17+ import android.net.Uri
1718import android.os.Build
1819import android.os.Bundle
20+ import android.provider.Settings
1921import android.text.TextUtils
2022import android.view.KeyEvent
2123import android.view.Menu
@@ -43,6 +45,8 @@ import com.github.ajalt.timberkt.w
4345import com.google.android.material.dialog.MaterialAlertDialogBuilder
4446import com.google.android.material.snackbar.Snackbar
4547import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher
48+ import com.zeapo.pwdstore.autofill.oreo.BrowserAutofillSupportLevel
49+ import com.zeapo.pwdstore.autofill.oreo.getInstalledBrowsersWithAutofillSupportLevel
4650import com.zeapo.pwdstore.crypto.PgpActivity
4751import com.zeapo.pwdstore.crypto.PgpActivity.Companion.getLongName
4852import 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 {
0 commit comments