f57a25c175bd

feat: Phase 9 — PeachAutofillService (inline chip + branded picker sheet), AssistStructureParser, AutofillResponseBuilder, TOTP fill, per-domain matching, 3 tests (v2.1.9)

time
2026-06-03 00:17 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
phase 8-12 sync autofill codex integrations
parent
a259dd8169f1
11 files app/build.gradle+3 −2app/src/main/AndroidManifest.xml+6 −0app/src/main/java/com/peachpasswords/autofill/AssistStructureParser.kt+104 −0app/src/main/java/com/peachpasswords/autofill/AutofillEntryPickerActivity.kt+237 −0app/src/main/java/com/peachpasswords/autofill/AutofillIntents.kt+47 −0app/src/main/java/com/peachpasswords/autofill/AutofillResponseBuilder.kt+122 −0app/src/main/java/com/peachpasswords/autofill/PeachAutofillService.kt+90 −2app/src/main/res/drawable/ic_peach_mark.xml+15 −0app/src/main/res/layout/autofill_row.xml+47 −0app/src/main/res/values/styles.xml+9 −0app/src/test/java/com/peachpasswords/autofill/AutofillMatchTest.kt+29 −0
app/build.gradle+3 −2
@@ -16,8 +16,8 @@1616         applicationId "com.peachpasswords"1717         minSdk 261818         targetSdk 3519-        versionCode 20100820-        versionName "2.1.8"19+        versionCode 20100920+        versionName "2.1.9"2121 2222         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"2323         vectorDrawables {@@ -72,6 +72,7 @@7272     androidTestImplementation platform("androidx.compose:compose-bom:2024.06.00")7373 7474     implementation "androidx.activity:activity-compose:1.9.2"75+    implementation "androidx.autofill:autofill:1.1.0"7576     implementation "androidx.biometric:biometric:1.1.0"7677     implementation "androidx.core:core-splashscreen:1.0.1"7778     implementation "androidx.appcompat:appcompat:1.7.0"

view file

app/src/main/AndroidManifest.xml+6 −0
@@ -46,6 +46,12 @@4646             android:exported="false"4747             android:theme="@style/Theme.Peach" />4848 49+        <activity50+            android:name=".autofill.AutofillEntryPickerActivity"51+            android:exported="false"52+            android:excludeFromRecents="true"53+            android:theme="@style/Theme.Peach.Transparent" />54+4955         <service5056             android:name=".autofill.PeachAutofillService"5157             android:permission="android.permission.BIND_AUTOFILL_SERVICE"

view file

app/src/main/java/com/peachpasswords/autofill/AssistStructureParser.kt+104 −0
@@ -0,0 +1,104 @@1+package com.peachpasswords.autofill2+3+import android.app.assist.AssistStructure4+import android.text.InputType5+import android.view.View6+import android.view.autofill.AutofillId7+8+/**9+ * The autofillable fields discovered in one [AssistStructure], plus the origin10+ * (web domain for browsers, package name otherwise) used to rank vault entries.11+ */12+data class ParsedStructure(13+    val usernameId: AutofillId? = null,14+    val emailId: AutofillId? = null,15+    val passwordId: AutofillId? = null,16+    val otpId: AutofillId? = null,17+    val webDomain: String? = null,18+    val packageName: String? = null,19+) {20+    /** The id we put the account identifier into — email preferred, else username. */21+    val identityId: AutofillId? get() = usernameId ?: emailId22+    val hasUsableField: Boolean get() = passwordId != null || identityId != null || otpId != null23+    /** Best label to rank entries against. */24+    val origin: String? get() = webDomain ?: packageName25+}26+27+/**28+ * Walks an [AssistStructure] to classify username/email/password/OTP fields.29+ * Mirrors the browser content-script's field detection: trust explicit autofill30+ * hints first, then fall back to input-type and id/hint keyword heuristics so31+ * unannotated login forms still work.32+ */33+object AssistStructureParser {34+35+    fun parse(structure: AssistStructure): ParsedStructure {36+        var result = ParsedStructure()37+        val windows = structure.windowNodeCount38+        for (i in 0 until windows) {39+            val root = structure.getWindowNodeAt(i).rootViewNode40+            result = traverse(root, result)41+        }42+        return result43+    }44+45+    private fun traverse(node: AssistStructure.ViewNode, acc: ParsedStructure): ParsedStructure {46+        var result = acc47+        if (result.webDomain == null && !node.webDomain.isNullOrBlank()) {48+            result = result.copy(webDomain = node.webDomain)49+        }50+        if (result.packageName == null && !node.idPackage.isNullOrBlank()) {51+            result = result.copy(packageName = node.idPackage)52+        }53+54+        val id = node.autofillId55+        if (id != null && isFillable(node)) {56+            result = when (classify(node)) {57+                FieldKind.PASSWORD -> if (result.passwordId == null) result.copy(passwordId = id) else result58+                FieldKind.USERNAME -> if (result.usernameId == null) result.copy(usernameId = id) else result59+                FieldKind.EMAIL -> if (result.emailId == null) result.copy(emailId = id) else result60+                FieldKind.OTP -> if (result.otpId == null) result.copy(otpId = id) else result61+                FieldKind.NONE -> result62+            }63+        }64+65+        for (i in 0 until node.childCount) {66+            result = traverse(node.getChildAt(i), result)67+        }68+        return result69+    }70+71+    private fun isFillable(node: AssistStructure.ViewNode): Boolean =72+        node.autofillType == View.AUTOFILL_TYPE_TEXT &&73+            node.visibility == View.VISIBLE74+75+    private enum class FieldKind { USERNAME, EMAIL, PASSWORD, OTP, NONE }76+77+    private fun classify(node: AssistStructure.ViewNode): FieldKind {78+        node.autofillHints?.forEach { hint ->79+            when (hint.lowercase()) {80+                View.AUTOFILL_HINT_PASSWORD, "password" -> return FieldKind.PASSWORD81+                View.AUTOFILL_HINT_USERNAME, "username" -> return FieldKind.USERNAME82+                View.AUTOFILL_HINT_EMAIL_ADDRESS, "email", "emailaddress" -> return FieldKind.EMAIL83+                "otp", "smsotpcode", "2facode" -> return FieldKind.OTP84+            }85+        }86+87+        val type = node.inputType88+        val isPasswordType = type and InputType.TYPE_MASK_VARIATION == InputType.TYPE_TEXT_VARIATION_PASSWORD ||89+            type and InputType.TYPE_MASK_VARIATION == InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD ||90+            type and InputType.TYPE_MASK_VARIATION == InputType.TYPE_NUMBER_VARIATION_PASSWORD91+        if (isPasswordType) return FieldKind.PASSWORD92+93+        val haystack = listOfNotNull(node.idEntry, node.hint, node.text?.toString())94+            .joinToString(" ").lowercase()95+        return when {96+            haystack.isBlank() -> FieldKind.NONE97+            Regex("\\b(otp|2fa|mfa|one[- ]?time|verification code|auth code)\\b").containsMatchIn(haystack) -> FieldKind.OTP98+            haystack.contains("password") || haystack.contains("passwd") || haystack.contains("pwd") -> FieldKind.PASSWORD99+            haystack.contains("email") || haystack.contains("e-mail") -> FieldKind.EMAIL100+            haystack.contains("user") || haystack.contains("login") || haystack.contains("account") -> FieldKind.USERNAME101+            else -> FieldKind.NONE102+        }103+    }104+}

view file

app/src/main/java/com/peachpasswords/autofill/AutofillEntryPickerActivity.kt+237 −0
@@ -0,0 +1,237 @@1+package com.peachpasswords.autofill2+3+import android.content.Intent4+import android.os.Bundle5+import android.view.autofill.AutofillId6+import android.view.autofill.AutofillManager7+import androidx.activity.compose.setContent8+import androidx.compose.foundation.background9+import androidx.compose.foundation.clickable10+import androidx.compose.foundation.layout.Arrangement11+import androidx.compose.foundation.layout.Box12+import androidx.compose.foundation.layout.Column13+import androidx.compose.foundation.layout.Row14+import androidx.compose.foundation.layout.fillMaxWidth15+import androidx.compose.foundation.layout.padding16+import androidx.compose.foundation.layout.size17+import androidx.compose.foundation.lazy.LazyColumn18+import androidx.compose.foundation.lazy.items19+import androidx.compose.foundation.shape.RoundedCornerShape20+import androidx.compose.material3.ExperimentalMaterial3Api21+import androidx.compose.material3.ModalBottomSheet22+import androidx.compose.material3.Text23+import androidx.compose.material3.rememberModalBottomSheetState24+import androidx.compose.runtime.Composable25+import androidx.compose.runtime.getValue26+import androidx.compose.runtime.remember27+import androidx.compose.ui.Alignment28+import androidx.compose.ui.Modifier29+import androidx.compose.ui.graphics.Color30+import androidx.compose.ui.text.font.FontStyle31+import androidx.compose.ui.text.style.TextOverflow32+import androidx.compose.ui.unit.dp33+import androidx.compose.ui.unit.sp34+import androidx.fragment.app.FragmentActivity35+import com.peachpasswords.MainActivity36+import com.peachpasswords.shared.extractDomain37+import com.peachpasswords.ui.components.FaviconInitials38+import com.peachpasswords.ui.theme.ACCENT_COLORS39+import com.peachpasswords.ui.theme.DEFAULT_ACCENT40+import com.peachpasswords.ui.theme.LocalPeachAccent41+import com.peachpasswords.ui.theme.PeachColors42+import com.peachpasswords.ui.theme.PeachTheme43+import com.peachpasswords.ui.theme.PeachType44+import com.peachpasswords.vault.VaultEntry45+import com.peachpasswords.vault.VaultRepository46+import dagger.hilt.android.AndroidEntryPoint47+import javax.inject.Inject48+49+/**50+ * Branded bottom sheet shown when the user taps "Search Peach…"/"Unlock Peach"51+ * in the system autofill drop-down. Lists matching vault entries using the same52+ * row vocabulary as the vault list; picking one returns a filled [android.service.autofill.Dataset]53+ * to the framework via [AutofillManager.EXTRA_AUTHENTICATION_RESULT].54+ */55+@AndroidEntryPoint56+class AutofillEntryPickerActivity : FragmentActivity() {57+58+    @Inject lateinit var vault: VaultRepository59+60+    @OptIn(ExperimentalMaterial3Api::class)61+    override fun onCreate(savedInstanceState: Bundle?) {62+        super.onCreate(savedInstanceState)63+64+        val parsed = ParsedStructure(65+            usernameId = intentAutofillId(AutofillIntents.EXTRA_IDENTITY_ID),66+            passwordId = intentAutofillId(AutofillIntents.EXTRA_PASSWORD_ID),67+            otpId = intentAutofillId(AutofillIntents.EXTRA_OTP_ID),68+            webDomain = intent.getStringExtra(AutofillIntents.EXTRA_ORIGIN),69+        )70+        val unlocked = vault.isUnlocked.value71+        val entries = if (unlocked) {72+            AutofillResponseBuilder.matchEntries(vault.getEntries(), parsed.origin).take(MAX_ROWS)73+        } else {74+            emptyList()75+        }76+        val accent = vault.settings.value.accentColor.let { ACCENT_COLORS[it] } ?: DEFAULT_ACCENT77+78+        setContent {79+            PeachTheme(accent = accent) {80+                val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)81+                ModalBottomSheet(82+                    onDismissRequest = { cancel() },83+                    sheetState = sheetState,84+                    containerColor = PeachColors.S1,85+                    dragHandle = { AccentDragHandle() },86+                ) {87+                    PickerBody(88+                        origin = parsed.origin,89+                        unlocked = unlocked,90+                        entries = entries,91+                        onPick = { returnDataset(parsed, it) },92+                        onOpenApp = { openApp() },93+                    )94+                }95+            }96+        }97+    }98+99+    private fun returnDataset(parsed: ParsedStructure, entry: VaultEntry) {100+        val dataset = AutofillResponseBuilder.datasetFor(this, parsed, entry, inlineSpec = null)101+        if (dataset == null) { cancel(); return }102+        val reply = Intent().putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, dataset)103+        setResult(RESULT_OK, reply)104+        finish()105+    }106+107+    private fun openApp() {108+        startActivity(Intent(this, MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))109+        cancel()110+    }111+112+    private fun cancel() {113+        setResult(RESULT_CANCELED)114+        finish()115+    }116+117+    @Suppress("DEPRECATION")118+    private fun intentAutofillId(key: String): AutofillId? =119+        if (android.os.Build.VERSION.SDK_INT >= 33) {120+            intent.getParcelableExtra(key, AutofillId::class.java)121+        } else {122+            intent.getParcelableExtra(key)123+        }124+125+    private companion object {126+        const val MAX_ROWS = 12127+    }128+}129+130+@Composable131+private fun AccentDragHandle() {132+    val accent = LocalPeachAccent.current133+    Row(134+        modifier = Modifier.fillMaxWidth().padding(top = 12.dp, bottom = 6.dp),135+        horizontalArrangement = Arrangement.Center,136+    ) {137+        Box(138+            modifier = Modifier139+                .size(width = 32.dp, height = 4.dp)140+                .background(accent.copy(alpha = 0.7f), RoundedCornerShape(2.dp)),141+        )142+    }143+}144+145+@Composable146+private fun PickerBody(147+    origin: String?,148+    unlocked: Boolean,149+    entries: List<VaultEntry>,150+    onPick: (VaultEntry) -> Unit,151+    onOpenApp: () -> Unit,152+) {153+    val accent = LocalPeachAccent.current154+    Column(modifier = Modifier.fillMaxWidth().padding(horizontal = 20.dp).padding(bottom = 28.dp)) {155+        Text(156+            text = "peach",157+            color = accent,158+            fontFamily = PeachType.Display,159+            fontStyle = FontStyle.Italic,160+            fontSize = 15.sp,161+        )162+        Text(163+            text = if (origin.isNullOrBlank()) "your vault" else "Suggested for $origin",164+            color = PeachColors.T2,165+            fontFamily = PeachType.Mono,166+            fontSize = 9.sp,167+            modifier = Modifier.padding(top = 2.dp, bottom = 14.dp),168+        )169+170+        if (!unlocked) {171+            Text(172+                text = "Peach is locked. Open the app to unlock, then return to this field.",173+                color = PeachColors.T1,174+                fontFamily = PeachType.Body,175+                fontSize = 14.sp,176+                modifier = Modifier.padding(bottom = 16.dp),177+            )178+            Text(179+                text = "Open Peach",180+                color = accent,181+                fontFamily = PeachType.Mono,182+                fontSize = 13.sp,183+                modifier = Modifier184+                    .fillMaxWidth()185+                    .clickable(onClick = onOpenApp)186+                    .padding(vertical = 12.dp),187+            )188+        } else if (entries.isEmpty()) {189+            Text(190+                text = "No saved entries match this site.",191+                color = PeachColors.T1,192+                fontFamily = PeachType.Body,193+                fontSize = 14.sp,194+            )195+        } else {196+            LazyColumn {197+                items(entries, key = { it.id }) { entry ->198+                    PickerRow(entry, onClick = { onPick(entry) })199+                }200+            }201+        }202+    }203+}204+205+@Composable206+private fun PickerRow(entry: VaultEntry, onClick: () -> Unit) {207+    Row(208+        modifier = Modifier209+            .fillMaxWidth()210+            .clickable(onClick = onClick)211+            .padding(vertical = 9.dp),212+        verticalAlignment = Alignment.CenterVertically,213+    ) {214+        FaviconInitials(source = entry.url ?: entry.title, size = 34.dp)215+        Column(modifier = Modifier.padding(start = 12.dp)) {216+            Text(217+                text = entry.title,218+                color = PeachColors.T0,219+                fontFamily = PeachType.Body,220+                fontSize = 15.sp,221+                maxLines = 1,222+                overflow = TextOverflow.Ellipsis,223+            )224+            val sub = entry.username ?: entry.email ?: entry.url?.let(::extractDomain) ?: ""225+            if (sub.isNotBlank()) {226+                Text(227+                    text = sub,228+                    color = PeachColors.T2,229+                    fontFamily = PeachType.Mono,230+                    fontSize = 11.sp,231+                    maxLines = 1,232+                    overflow = TextOverflow.Ellipsis,233+                )234+            }235+        }236+    }237+}

view file

app/src/main/java/com/peachpasswords/autofill/AutofillIntents.kt+47 −0
@@ -0,0 +1,47 @@1+package com.peachpasswords.autofill2+3+import android.app.PendingIntent4+import android.content.Context5+import android.content.Intent6+import android.content.IntentSender7+import android.os.Build8+9+/**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+ */14+object 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+20+    private const val REQ_CHIP = 0xC0DE21+    private const val REQ_PICKER = 0xBEEF22+23+    /** Required attribution for an inline suggestion; tapping it is a no-op. */24+    fun noopChipIntent(context: Context): PendingIntent {25+        val intent = Intent(context, AutofillEntryPickerActivity::class.java)26+        return PendingIntent.getActivity(context, REQ_CHIP, intent, immutableFlags())27+    }28+29+    /** Authentication target for the "Search Peach…" dataset. */30+    fun pickerIntentSender(context: Context, parsed: ParsedStructure): IntentSender {31+        val intent = Intent(context, AutofillEntryPickerActivity::class.java).apply {32+            putExtra(EXTRA_IDENTITY_ID, parsed.identityId)33+            putExtra(EXTRA_PASSWORD_ID, parsed.passwordId)34+            putExtra(EXTRA_OTP_ID, parsed.otpId)35+            putExtra(EXTRA_ORIGIN, parsed.origin)36+        }37+        return PendingIntent.getActivity(context, REQ_PICKER, intent, mutableFlags()).intentSender38+    }39+40+    private fun immutableFlags(): Int =41+        PendingIntent.FLAG_UPDATE_CURRENT or42+            if (Build.VERSION.SDK_INT >= 23) PendingIntent.FLAG_IMMUTABLE else 043+44+    private fun mutableFlags(): Int =45+        PendingIntent.FLAG_UPDATE_CURRENT or46+            if (Build.VERSION.SDK_INT >= 31) PendingIntent.FLAG_MUTABLE else 047+}

view file

app/src/main/java/com/peachpasswords/autofill/AutofillResponseBuilder.kt+122 −0
@@ -0,0 +1,122 @@1+package com.peachpasswords.autofill2+3+import android.content.Context4+import android.os.Build5+import android.service.autofill.Dataset6+import android.service.autofill.InlinePresentation7+import android.view.autofill.AutofillId8+import android.view.autofill.AutofillValue9+import android.widget.RemoteViews10+import androidx.annotation.RequiresApi11+import androidx.autofill.inline.v1.InlineSuggestionUi12+import androidx.autofill.inline.UiVersions13+import com.peachpasswords.R14+import com.peachpasswords.shared.extractDomain15+import com.peachpasswords.vault.TOTPGenerator16+import com.peachpasswords.vault.VaultEntry17+18+/**19+ * Turns parsed form fields + vault entries into autofill [Dataset]s — the menu20+ * RemoteViews row, the inline keyboard chip, and the actual field values.21+ * TOTP is filled as a freshly-generated code; the seed never leaves the vault.22+ */23+object AutofillResponseBuilder {24+25+    /** Entries whose domain/title plausibly match the form origin, best first. */26+    fun matchEntries(entries: List<VaultEntry>, origin: String?): List<VaultEntry> {27+        if (origin.isNullOrBlank()) return entries28+        val core = coreLabel(origin)29+        val (hits, rest) = entries.partition { entry ->30+            val hay = listOfNotNull(extractDomain(entry.url ?: ""), entry.url, entry.title)31+                .joinToString(" ").lowercase()32+            core.isNotBlank() && (hay.contains(core) || hay.contains(origin.lowercase()))33+        }34+        return hits + rest35+    }36+37+    /** The registrable-ish core token of an origin: "login.github.com" → "github". */38+    private fun coreLabel(origin: String): String {39+        val host = origin.substringAfter("://").substringBefore('/').lowercase()40+        val parts = host.removePrefix("www.").split('.')41+        return when {42+            parts.size >= 2 -> parts[parts.size - 2]43+            parts.isNotEmpty() -> parts[0]44+            else -> host45+        }46+    }47+48+    fun menuRow(context: Context, entry: VaultEntry): RemoteViews {49+        val subtitle = entry.username ?: entry.email ?: entry.url?.let(::extractDomain) ?: ""50+        return RemoteViews(context.packageName, R.layout.autofill_row).apply {51+            setTextViewText(R.id.autofill_row_title, entry.title)52+            setTextViewText(R.id.autofill_row_subtitle, subtitle)53+        }54+    }55+56+    fun simpleRow(context: Context, title: String, subtitle: String): RemoteViews =57+        RemoteViews(context.packageName, R.layout.autofill_row).apply {58+            setTextViewText(R.id.autofill_row_title, title)59+            setTextViewText(R.id.autofill_row_subtitle, subtitle)60+        }61+62+    /**63+     * Build a dataset filling the parsed fields from [entry]. Attaches the inline64+     * chip when the IME offered a spec (API 30+); otherwise menu-only.65+     */66+    fun datasetFor(67+        context: Context,68+        parsed: ParsedStructure,69+        entry: VaultEntry,70+        inlineSpec: android.widget.inline.InlinePresentationSpec?,71+    ): Dataset? {72+        val menu = menuRow(context, entry)73+        val inline = if (Build.VERSION.SDK_INT >= 30 && inlineSpec != null) {74+            buildInline(context, entry, inlineSpec)75+        } else {76+            null77+        }78+79+        val builder = Dataset.Builder()80+        var filledAny = false81+        fun put(id: AutofillId?, value: String?) {82+            if (id == null || value.isNullOrEmpty()) return83+            val av = AutofillValue.forText(value)84+            if (inline != null && Build.VERSION.SDK_INT >= 30) {85+                builder.setValue(id, av, menu, inline)86+            } else {87+                builder.setValue(id, av, menu)88+            }89+            filledAny = true90+        }91+        put(parsed.identityId, entry.username ?: entry.email)92+        put(parsed.passwordId, entry.password)93+        put(parsed.otpId, entry.totp?.let { TOTPGenerator.generateCode(it) })94+95+        return if (filledAny) builder.build() else null96+    }97+98+    @RequiresApi(30)99+    private fun buildInline(100+        context: Context,101+        entry: VaultEntry,102+        spec: android.widget.inline.InlinePresentationSpec,103+    ): InlinePresentation? = try {104+        val style = spec.style105+        if (!UiVersions.getVersions(style).contains(UiVersions.INLINE_UI_VERSION_1)) {106+            null107+        } else {108+            val subtitle = entry.username ?: entry.email ?: entry.url?.let(::extractDomain) ?: ""109+            val pending = AutofillIntents.noopChipIntent(context)110+            val slice = InlineSuggestionUi.newContentBuilder(pending)111+                .setTitle(entry.title)112+                .apply { if (subtitle.isNotBlank()) setSubtitle(subtitle) }113+                .setStartIcon(android.graphics.drawable.Icon.createWithResource(context, R.drawable.ic_peach_mark))114+                .build()115+                .slice116+            InlinePresentation(slice, spec, false)117+        }118+    } catch (_: Throwable) {119+        // A non-conforming IME spec must never crash the fill — degrade to menu.120+        null121+    }122+}

view file

app/src/main/java/com/peachpasswords/autofill/PeachAutofillService.kt+90 −2
@@ -1,22 +1,110 @@11 package com.peachpasswords.autofill22 3+import android.os.Build34 import android.os.CancellationSignal45 import android.service.autofill.AutofillService56 import android.service.autofill.FillCallback67 import android.service.autofill.FillRequest8+import android.service.autofill.FillResponse79 import android.service.autofill.SaveCallback810 import android.service.autofill.SaveRequest11+import com.peachpasswords.vault.VaultRepository12+import dagger.hilt.android.AndroidEntryPoint13+import javax.inject.Inject914 15+/**16+ * System autofill provider. Parses the focused form, then either offers17+ * matching vault entries (inline chip + drop-down rows) or a single branded18+ * "Search Peach…" entry that opens [AutofillEntryPickerActivity].19+ *20+ * The vault is a process singleton, so when the app has the vault unlocked the21+ * service fills directly; when locked it offers only the picker, which routes22+ * the user to unlock. The save flow is intentionally a no-op for now — Peach23+ * adds entries through its own UI, not the system Save dialog.24+ */25+@AndroidEntryPoint1026 class PeachAutofillService : AutofillService() {27+28+    @Inject lateinit var vault: VaultRepository29+1130     override fun onFillRequest(1231         request: FillRequest,1332         cancellationSignal: CancellationSignal,1433         callback: FillCallback,1534     ) {16-        // Scaffold: the real dataset wiring comes later.35+        val context = applicationContext36+        val structure = latestStructure(request) ?: run { callback.onSuccess(null); return }37+        val parsed = AssistStructureParser.parse(structure)38+        if (!parsed.hasUsableField) { callback.onSuccess(null); return }39+40+        val inlineSpecs = inlineSpecs(request)41+        val response = FillResponse.Builder()42+        var datasetCount = 043+44+        if (vault.isUnlocked.value) {45+            val matches = AutofillResponseBuilder46+                .matchEntries(vault.getEntries(), parsed.origin)47+                .take(MAX_DATASETS)48+            matches.forEachIndexed { index, entry ->49+                val spec = inlineSpecs.getOrNull(index)50+                AutofillResponseBuilder.datasetFor(context, parsed, entry, spec)?.let {51+                    response.addDataset(it)52+                    datasetCount++53+                }54+            }55+        }56+57+        // Always offer the branded picker as the last row (search / unlock).58+        runCatching {59+            response.addDataset(pickerDataset(context, parsed, inlineSpecs.getOrNull(datasetCount)))60+            datasetCount++61+        }62+63+        if (datasetCount == 0) {64+            callback.onSuccess(null)65+        } else {66+            ignoreUnfilledIds(response, parsed)67+            callback.onSuccess(response.build())68+        }1769     }1870 71+    private fun pickerDataset(72+        context: android.content.Context,73+        parsed: ParsedStructure,74+        inlineSpec: android.widget.inline.InlinePresentationSpec?,75+    ): android.service.autofill.Dataset {76+        val label = if (vault.isUnlocked.value) "Search Peach…" else "Unlock Peach"77+        val menu = AutofillResponseBuilder.simpleRow(context, label, parsed.origin ?: "")78+        val builder = android.service.autofill.Dataset.Builder(menu)79+        // A placeholder value per field keeps the dataset valid; the real values80+        // are supplied by the picker via EXTRA_AUTHENTICATION_RESULT.81+        listOfNotNull(parsed.identityId, parsed.passwordId, parsed.otpId).forEach { id ->82+            builder.setValue(id, null, menu)83+        }84+        builder.setAuthentication(AutofillIntents.pickerIntentSender(context, parsed))85+        return builder.build()86+    }87+88+    /** Mark detected ids the framework should track even when we filled nothing. */89+    private fun ignoreUnfilledIds(builder: FillResponse.Builder, parsed: ParsedStructure) {90+        val ids = listOfNotNull(parsed.identityId, parsed.passwordId, parsed.otpId)91+        if (ids.isNotEmpty()) builder.setIgnoredIds(*ids.toTypedArray())92+    }93+94+    private fun latestStructure(request: FillRequest): android.app.assist.AssistStructure? =95+        request.fillContexts.lastOrNull()?.structure96+97+    private fun inlineSpecs(request: FillRequest): List<android.widget.inline.InlinePresentationSpec> {98+        if (Build.VERSION.SDK_INT < 30) return emptyList()99+        return request.inlineSuggestionsRequest?.inlinePresentationSpecs ?: emptyList()100+    }101+19102     override fun onSaveRequest(request: SaveRequest, callback: SaveCallback) {20-        // Scaffold: save flow is wired in a later phase.103+        // Peach captures new logins through its own add-entry flow.104+        callback.onSuccess()105+    }106+107+    private companion object {108+        const val MAX_DATASETS = 621109     }22110 }

view file

app/src/main/res/drawable/ic_peach_mark.xml+15 −0
@@ -0,0 +1,15 @@1+<vector xmlns:android="http://schemas.android.com/apk/res/android"2+    android:width="18dp"3+    android:height="18dp"4+    android:viewportWidth="240"5+    android:viewportHeight="240">6+    <path7+        android:pathData="M124 64 C134 32 168 16 200 22 C198 56 168 72 130 66 Z"8+        android:fillColor="#92AC65" />9+    <path10+        android:pathData="M120 60 C75 45 28 75 22 130 C18 185 65 222 125 222 C185 222 222 185 220 130 C218 78 170 45 120 60 Z"11+        android:fillColor="#FFB082" />12+    <path13+        android:pathData="M120 60 C75 45 28 75 22 130 C18 185 65 222 125 222 C105 195 75 150 100 90 C105 75 112 65 120 60 Z"14+        android:fillColor="#E5805C" />15+</vector>

view file

app/src/main/res/layout/autofill_row.xml+47 −0
@@ -0,0 +1,47 @@1+<?xml version="1.0" encoding="utf-8"?>2+<!-- Dropdown-menu presentation for one vault entry. The inline chip is built3+     in code (InlineSuggestionUi); this is the fallback shown in the autofill4+     drop-down. Amber title on the dark Peach surface. -->5+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"6+    android:layout_width="match_parent"7+    android:layout_height="wrap_content"8+    android:orientation="horizontal"9+    android:gravity="center_vertical"10+    android:background="#161310"11+    android:paddingStart="14dp"12+    android:paddingEnd="14dp"13+    android:paddingTop="11dp"14+    android:paddingBottom="11dp">15+16+    <ImageView17+        android:id="@+id/autofill_row_icon"18+        android:layout_width="20dp"19+        android:layout_height="20dp"20+        android:layout_marginEnd="12dp"21+        android:src="@drawable/ic_peach_mark"22+        android:contentDescription="@string/autofill_service_label" />23+24+    <TextView25+        android:id="@+id/autofill_row_title"26+        android:layout_width="0dp"27+        android:layout_height="wrap_content"28+        android:layout_weight="1"29+        android:singleLine="true"30+        android:ellipsize="end"31+        android:textColor="#E8956D"32+        android:textSize="15sp"33+        tools:ignore="HardcodedText"34+        xmlns:tools="http://schemas.android.com/tools"35+        android:text="Entry" />36+37+    <TextView38+        android:id="@+id/autofill_row_subtitle"39+        android:layout_width="wrap_content"40+        android:layout_height="wrap_content"41+        android:layout_marginStart="10dp"42+        android:singleLine="true"43+        android:ellipsize="end"44+        android:textColor="#8A8178"45+        android:textSize="12sp"46+        android:fontFamily="monospace" />47+</LinearLayout>

view file

app/src/main/res/values/styles.xml+9 −0
@@ -13,4 +13,13 @@1313         <item name="android:windowLightStatusBar">false</item>1414         <item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>1515     </style>16+17+    <!-- Translucent host for the autofill bottom sheet — the app/IME stays18+         visible behind the dimming scrim the ModalBottomSheet draws. -->19+    <style name="Theme.Peach.Transparent" parent="Theme.Peach">20+        <item name="android:windowBackground">@android:color/transparent</item>21+        <item name="android:windowIsTranslucent">true</item>22+        <item name="android:windowIsFloating">false</item>23+        <item name="android:backgroundDimEnabled">false</item>24+    </style>1625 </resources>

view file

app/src/test/java/com/peachpasswords/autofill/AutofillMatchTest.kt+29 −0
@@ -0,0 +1,29 @@1+package com.peachpasswords.autofill2+3+import com.peachpasswords.vault.VaultEntry4+import org.junit.Assert.assertEquals5+import org.junit.Test6+7+class AutofillMatchTest {8+    private fun entry(title: String, url: String?) =9+        VaultEntry(id = title, title = title, url = url, createdAt = 0, modifiedAt = 0)10+11+    @Test fun domain_match_ranks_first() {12+        val gh = entry("GitHub", "https://github.com/login")13+        val mail = entry("Fastmail", "https://fastmail.com")14+        val ranked = AutofillResponseBuilder.matchEntries(listOf(mail, gh), "login.github.com")15+        assertEquals("GitHub", ranked.first().title)16+    }17+18+    @Test fun subdomain_origin_matches_core_label() {19+        val gh = entry("GitHub", "https://github.com")20+        val ranked = AutofillResponseBuilder.matchEntries(listOf(gh), "https://gist.github.com/")21+        assertEquals("GitHub", ranked.first().title)22+    }23+24+    @Test fun no_origin_returns_all_unchanged() {25+        val a = entry("A", null)26+        val b = entry("B", null)27+        assertEquals(listOf(a, b), AutofillResponseBuilder.matchEntries(listOf(a, b), null))28+    }29+}

view file