1package com.peachpasswords.autofill23import android.content.Context4import android.content.Intent5import android.net.Uri6import android.provider.Settings7import android.view.autofill.AutofillManager8910111213141516171819202122object AutofillEnablement {2324 private const val PREFS = "peach_autofill"25 private const val ASKED_KEY = "asked_enable"2627 fun isSupported(context: Context): Boolean =28 context.getSystemService(AutofillManager::class.java)?.isAutofillSupported == true2930 fun isEnabled(context: Context): Boolean =31 context.getSystemService(AutofillManager::class.java)?.hasEnabledAutofillServices() == true3233 fun shouldOffer(context: Context): Boolean =34 isSupported(context) && !isEnabled(context) && !asked(context)3536 private fun asked(context: Context) =37 context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getBoolean(ASKED_KEY, false)3839 fun markAsked(context: Context) {40 context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)41 .edit().putBoolean(ASKED_KEY, true).apply()42 }4344 4546474849 fun requestIntent(context: Context): Intent =50 Intent(Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE)51 .setData(Uri.parse("package:${context.packageName}"))5253 fun fallbackIntent(): Intent = Intent(Settings.ACTION_SETTINGS)54}