AutofillIntents.kt

2.0 KB · raw

1package com.peachpasswords.autofill23import android.app.PendingIntent4import android.content.Context5import android.content.Intent6import android.content.IntentSender7import android.os.Build89/**10 * PendingIntents the autofill surfaces hand to the framework: a no-op11 * attribution target the inline chip requires, and the authentication12 * IntentSender that opens the branded [AutofillEntryPickerActivity].13 */14object AutofillIntents {15    const val EXTRA_IDENTITY_ID = "peach.autofill.identityId"16    const val EXTRA_PASSWORD_ID = "peach.autofill.passwordId"17    const val EXTRA_OTP_ID = "peach.autofill.otpId"18    const val EXTRA_ORIGIN = "peach.autofill.origin"19    const val EXTRA_IS_WEB_ORIGIN = "peach.autofill.isWebOrigin"2021    private const val REQ_CHIP = 0xC0DE22    private const val REQ_PICKER = 0xBEEF2324    /** Required attribution for an inline suggestion; tapping it is a no-op. */25    fun noopChipIntent(context: Context): PendingIntent {26        val intent = Intent(context, AutofillEntryPickerActivity::class.java)27        return PendingIntent.getActivity(context, REQ_CHIP, intent, immutableFlags())28    }2930    /** Authentication target for the "Search Peach…" dataset. */31    fun pickerIntentSender(context: Context, parsed: ParsedStructure): IntentSender {32        val intent = Intent(context, AutofillEntryPickerActivity::class.java).apply {33            putExtra(EXTRA_IDENTITY_ID, parsed.identityId)34            putExtra(EXTRA_PASSWORD_ID, parsed.passwordId)35            putExtra(EXTRA_OTP_ID, parsed.otpId)36            putExtra(EXTRA_ORIGIN, parsed.origin)37            putExtra(EXTRA_IS_WEB_ORIGIN, parsed.webDomain != null)38        }39        return PendingIntent.getActivity(context, REQ_PICKER, intent, mutableFlags()).intentSender40    }4142    private fun immutableFlags(): Int =43        PendingIntent.FLAG_UPDATE_CURRENT or44            if (Build.VERSION.SDK_INT >= 23) PendingIntent.FLAG_IMMUTABLE else 04546    private fun mutableFlags(): Int =47        PendingIntent.FLAG_UPDATE_CURRENT or48            if (Build.VERSION.SDK_INT >= 31) PendingIntent.FLAG_MUTABLE else 049}