package com.peachpasswords.autofill import android.app.PendingIntent import android.content.Context import android.content.Intent import android.content.IntentSender import android.os.Build /** * PendingIntents the autofill surfaces hand to the framework: a no-op * attribution target the inline chip requires, and the authentication * IntentSender that opens the branded [AutofillEntryPickerActivity]. */ object AutofillIntents { const val EXTRA_IDENTITY_ID = "peach.autofill.identityId" const val EXTRA_PASSWORD_ID = "peach.autofill.passwordId" const val EXTRA_OTP_ID = "peach.autofill.otpId" const val EXTRA_ORIGIN = "peach.autofill.origin" const val EXTRA_IS_WEB_ORIGIN = "peach.autofill.isWebOrigin" private const val REQ_CHIP = 0xC0DE private const val REQ_PICKER = 0xBEEF /** Required attribution for an inline suggestion; tapping it is a no-op. */ fun noopChipIntent(context: Context): PendingIntent { val intent = Intent(context, AutofillEntryPickerActivity::class.java) return PendingIntent.getActivity(context, REQ_CHIP, intent, immutableFlags()) } /** Authentication target for the "Search Peach…" dataset. */ fun pickerIntentSender(context: Context, parsed: ParsedStructure): IntentSender { val intent = Intent(context, AutofillEntryPickerActivity::class.java).apply { putExtra(EXTRA_IDENTITY_ID, parsed.identityId) putExtra(EXTRA_PASSWORD_ID, parsed.passwordId) putExtra(EXTRA_OTP_ID, parsed.otpId) putExtra(EXTRA_ORIGIN, parsed.origin) putExtra(EXTRA_IS_WEB_ORIGIN, parsed.webDomain != null) } return PendingIntent.getActivity(context, REQ_PICKER, intent, mutableFlags()).intentSender } private fun immutableFlags(): Int = PendingIntent.FLAG_UPDATE_CURRENT or if (Build.VERSION.SDK_INT >= 23) PendingIntent.FLAG_IMMUTABLE else 0 private fun mutableFlags(): Int = PendingIntent.FLAG_UPDATE_CURRENT or if (Build.VERSION.SDK_INT >= 31) PendingIntent.FLAG_MUTABLE else 0 }