Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add overlay unlock activity for autofill (#1845)
Leendert de Borst28d409f3b36c
diff --git a/apps/mobile-app/android/app/src/main/AndroidManifest.xml b/apps/mobile-app/android/app/src/main/AndroidManifest.xmlindex 939a9841c..133dff472 100644--- a/apps/mobile-app/android/app/src/main/AndroidManifest.xml+++ b/apps/mobile-app/android/app/src/main/AndroidManifest.xml@@ -41,14 +41,14 @@<activityandroid:name=".credentialprovider.PasskeyAuthenticationActivity"android:exported="false"- android:theme="@style/PasskeyRegistrationTheme"+ android:theme="@style/Theme.App.Overlay"android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboardHidden|uiMode|fontScale|density" /><!-- Passkey Registration Activity --><activityandroid:name=".credentialprovider.PasskeyRegistrationActivity"android:exported="false"- android:theme="@style/PasskeyRegistrationTheme"+ android:theme="@style/Theme.App.Overlay"android:windowSoftInputMode="adjustResize"android:fitsSystemWindows="true"android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboardHidden|uiMode|fontScale|density" />@@ -57,14 +57,14 @@<activityandroid:name=".pinunlock.PinUnlockActivity"android:exported="false"- android:theme="@style/PasskeyRegistrationTheme"+ android:theme="@style/Theme.App.Overlay"android:screenOrientation="portrait" /><!-- Password Unlock Activity --><activityandroid:name=".passwordunlock.PasswordUnlockActivity"android:exported="false"- android:theme="@style/PasskeyRegistrationTheme"+ android:theme="@style/Theme.App.Overlay"android:screenOrientation="portrait"android:windowSoftInputMode="adjustPan" />@@ -82,6 +82,14 @@android:excludeFromRecents="true"android:theme="@style/Theme.App.NoDisplay" />+ <!-- Autofill Unlock Activity (launched via FillResponse.setAuthentication when the vault is locked) -->+ <activity+ android:name=".autofill.AutofillUnlockActivity"+ android:exported="false"+ android:excludeFromRecents="true"+ android:theme="@style/Theme.App.Overlay"+ android:screenOrientation="portrait" />+<activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait"><intent-filter><action android:name="android.intent.action.MAIN"/>diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/AutofillService.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/AutofillService.ktindex ee77c13e5..332474db0 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/AutofillService.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/AutofillService.kt@@ -24,13 +24,10 @@ import android.text.style.StyleSpanimport android.util.Logimport android.view.autofill.AutofillValueimport android.widget.RemoteViews-import net.aliasvault.app.MainActivityimport net.aliasvault.app.R-import net.aliasvault.app.autofill.utils.AutofillFieldMapper+import net.aliasvault.app.autofill.utils.AutofillDatasetBuilderimport net.aliasvault.app.autofill.utils.FieldFinder-import net.aliasvault.app.autofill.utils.ImageUtilsimport net.aliasvault.app.autofill.utils.RustItemMatcher-import net.aliasvault.app.utils.ItemTypeIconimport net.aliasvault.app.vaultstore.VaultStoreimport net.aliasvault.app.vaultstore.interfaces.ItemOperationCallbackimport net.aliasvault.app.vaultstore.models.Item@@ -187,12 +184,19 @@ class AutofillService : AutofillService() {TAG,"No items found for this app, showing 'no matches' option",)- responseBuilder.addDataset(createNoMatchesDataset(fieldFinder))+ responseBuilder.addDataset(+ AutofillDatasetBuilder.createNoMatchesDataset(+ this@AutofillService,+ fieldFinder.autofillableFields,+ appInfo,+ ),+ )} else {// If there are matches, add them to the datasetfor (item in filteredItems) {- val dataset = createItemDataset(- fieldFinder = fieldFinder,+ val dataset = AutofillDatasetBuilder.createItemDataset(+ context = this@AutofillService,+ fields = fieldFinder.autofillableFields,item = item,copyTotpOnSelect = copyTotpOnFill && item.hasTotp,)@@ -239,164 +243,43 @@ class AutofillService : AutofillService() {}}- // If we get here, either there was no instance or the vault wasn't unlocked- // Show a "vault locked" placeholder instead of launching the activity- Log.d(TAG, "Vault is locked, showing placeholder")-- val responseBuilder = FillResponse.Builder()- responseBuilder.addDataset(createVaultLockedDataset(fieldFinder))- callback(responseBuilder.build())+ // If we get here, either there was no instance or the vault wasn't unlocked.+ // Use FillResponse-level authentication so that after the user unlocks+ // through AutofillUnlockActivity, the OS automatically restores the+ // calling app and shows the (now-populated) autofill picker.+ Log.d(TAG, "Vault is locked, requiring authentication before fill")+ callback(buildLockedFillResponse(fieldFinder, appInfo))}/**- * Build the picker Dataset for an item. Sets presentation (label + icon),- * stages placeholder values via [AutofillFieldMapper], and wires- * `Dataset.setAuthentication` to [AutofillFillActivity], passing- * [copyTotpOnSelect] through so the activity copies the TOTP code on- * selection when requested. The OS discards the placeholder values and- * substitutes the dataset returned by the activity.+ * Build a [FillResponse] whose only entry is a "Vault locked" row that, when+ * tapped, launches [AutofillUnlockActivity] to unlock the vault and resume+ * the autofill flow in the calling app.*/- private fun createItemDataset(- fieldFinder: FieldFinder,- item: Item,- copyTotpOnSelect: Boolean,- ): Dataset {- val presentation = RemoteViews(packageName, R.layout.autofill_dataset_item_icon)- val builder = Dataset.Builder(presentation)-- val applyResult = AutofillFieldMapper.applyItem(builder, item, fieldFinder.autofillableFields)- if (!applyResult.hasValue && fieldFinder.autofillableFields.isNotEmpty()) {- Log.w(TAG, "Item ${item.name} has no autofillable data - this should have been filtered")- builder.setValue(- fieldFinder.autofillableFields.first().first,- AutofillValue.forText(""),- )- }-- val displayValue = if (applyResult.labelSuffix != null) {- "${item.name} (${applyResult.labelSuffix})"- } else {- item.name- }- presentation.setTextViewText(R.id.text, displayValue)-- val logoBytes = item.logo- val bitmap = if (logoBytes != null) {- ImageUtils.bytesToBitmap(logoBytes)- } else {- ItemTypeIcon.getIcon(- context = this@AutofillService,- itemType = ItemTypeIcon.ItemType.LOGIN,- size = 96,- )- }- if (bitmap != null) {- presentation.setImageViewBitmap(R.id.icon, bitmap)- }-+ private fun buildLockedFillResponse(fieldFinder: FieldFinder, appInfo: String?): FillResponse {val autofillIds = fieldFinder.autofillableFields.map { it.first }.toTypedArray()val fieldTypeOrdinals = IntArray(fieldFinder.autofillableFields.size) { i ->fieldFinder.autofillableFields[i].second.ordinal}- val authIntent = Intent(this, AutofillFillActivity::class.java).apply {- putExtra(AutofillFillActivity.EXTRA_ITEM_ID, item.id.toString().uppercase())- putExtra(AutofillFillActivity.EXTRA_AUTOFILL_IDS, autofillIds)- putExtra(AutofillFillActivity.EXTRA_FIELD_TYPES, fieldTypeOrdinals)- putExtra(AutofillFillActivity.EXTRA_COPY_TOTP, copyTotpOnSelect)- }- val pendingIntent = PendingIntent.getActivity(- this,- item.id.hashCode(),- authIntent,- PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_CANCEL_CURRENT,- )- builder.setAuthentication(pendingIntent.intentSender)-- return builder.build()- }- /**- * Create a dataset for the "no matches" option.- * @param fieldFinder The field finder- * @return The dataset- */- private fun createNoMatchesDataset(fieldFinder: FieldFinder): Dataset {- // Create presentation for the "no matches" option- val presentation = RemoteViews(packageName, R.layout.autofill_dataset_item_logo)- presentation.setTextViewText(- R.id.text,- getString(R.string.autofill_no_match_found),- )-- val dataSetBuilder = Dataset.Builder(presentation)-- // Get the app/website information to use as item URL- val appInfo = fieldFinder.getAppInfo()- val encodedUrl = appInfo?.let { java.net.URLEncoder.encode(it, "UTF-8") } ?: ""-- // Open the action picker so the user can choose between linking this app- // to an existing credential or creating a new one.- val deepLinkUrl = "aliasvault://items/autofill-open-app?itemUrl=$encodedUrl"-- // Add a click listener to open AliasVault app with deep link- val intent = Intent(Intent.ACTION_VIEW).apply {- data = android.net.Uri.parse(deepLinkUrl)- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)+ val unlockIntent = Intent(this, AutofillUnlockActivity::class.java).apply {+ putExtra(AutofillUnlockActivity.EXTRA_AUTOFILL_IDS, autofillIds)+ putExtra(AutofillUnlockActivity.EXTRA_FIELD_TYPES, fieldTypeOrdinals)+ putExtra(AutofillUnlockActivity.EXTRA_APP_INFO, appInfo)}val pendingIntent = PendingIntent.getActivity(- this@AutofillService,+ this,0,- intent,- PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,+ unlockIntent,+ PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_CANCEL_CURRENT,)- dataSetBuilder.setAuthentication(pendingIntent.intentSender)-- // Add a placeholder value to both username and password fields to satisfy the requirement that at least one value must be set- if (fieldFinder.autofillableFields.isNotEmpty()) {- for (field in fieldFinder.autofillableFields) {- dataSetBuilder.setValue(field.first, AutofillValue.forText(""))- }- }- return dataSetBuilder.build()- }-- /**- * Create a dataset for the "vault locked" option.- * @param fieldFinder The field finder- * @return The dataset- */- private fun createVaultLockedDataset(fieldFinder: FieldFinder): Dataset {- // Create presentation for the "vault locked" optionval presentation = RemoteViews(packageName, R.layout.autofill_dataset_item_logo)- presentation.setTextViewText(- R.id.text,- getString(R.string.autofill_vault_locked),- )+ presentation.setTextViewText(R.id.text, getString(R.string.autofill_vault_locked))- val dataSetBuilder = Dataset.Builder(presentation)-- // Add a click listener to open AliasVault app- val intent = Intent(this@AutofillService, MainActivity::class.java).apply {- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)- putExtra("OPEN_CREDENTIALS", true)- }- val pendingIntent = PendingIntent.getActivity(- this@AutofillService,- 0,- intent,- PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,- )- dataSetBuilder.setAuthentication(pendingIntent.intentSender)-- // Add a placeholder value to both username and password fields to satisfy the requirement that at least one value must be set- if (fieldFinder.autofillableFields.isNotEmpty()) {- for (field in fieldFinder.autofillableFields) {- dataSetBuilder.setValue(field.first, AutofillValue.forText(""))- }- }-- return dataSetBuilder.build()+ return FillResponse.Builder()+ .setAuthentication(autofillIds, pendingIntent.intentSender, presentation)+ .build()}/**diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/AutofillUnlockActivity.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/AutofillUnlockActivity.ktnew file mode 100644index 000000000..67a820c97--- /dev/null+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/AutofillUnlockActivity.kt@@ -0,0 +1,221 @@+package net.aliasvault.app.autofill++import android.content.Intent+import android.os.Build+import android.os.Bundle+import android.service.autofill.FillResponse+import android.util.Log+import android.view.View+import android.view.autofill.AutofillId+import android.view.autofill.AutofillManager+import android.widget.TextView+import androidx.fragment.app.FragmentActivity+import androidx.lifecycle.lifecycleScope+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.launch+import kotlinx.coroutines.withContext+import net.aliasvault.app.R+import net.aliasvault.app.autofill.models.FieldType+import net.aliasvault.app.autofill.utils.AutofillDatasetBuilder+import net.aliasvault.app.autofill.utils.RustItemMatcher+import net.aliasvault.app.credentialprovider.UnlockCoordinator+import net.aliasvault.app.vaultstore.VaultStore+import net.aliasvault.app.vaultstore.keystoreprovider.AndroidKeystoreProvider+import net.aliasvault.app.vaultstore.storageprovider.AndroidStorageProvider++/**+ * Activity launched by the OS when the user taps the "Vault locked" entry in+ * the autofill picker (wired via `FillResponse.setAuthentication`).+ *+ * Drives the vault unlock through [UnlockCoordinator] (biometric → PIN →+ * master password) and, on success, builds a [FillResponse] of matching+ * credentials and returns it via `AutofillManager.EXTRA_AUTHENTICATION_RESULT`.+ * The OS then restores the calling app and re-shows the autofill picker so the+ * user can complete the fill without ever leaving the original app.+ */+class AutofillUnlockActivity : FragmentActivity() {++ companion object {+ private const val TAG = "AliasVaultAutofill"++ /** Parceled `AutofillId`s for the target form fields. */+ const val EXTRA_AUTOFILL_IDS = "net.aliasvault.app.autofill.unlock.EXTRA_AUTOFILL_IDS"++ /** `FieldType` ordinals matching [EXTRA_AUTOFILL_IDS] one-to-one. */+ const val EXTRA_FIELD_TYPES = "net.aliasvault.app.autofill.unlock.EXTRA_FIELD_TYPES"++ /** Resolved web origin or package name for the calling app/site, used for matching. */+ const val EXTRA_APP_INFO = "net.aliasvault.app.autofill.unlock.EXTRA_APP_INFO"+ }++ private lateinit var vaultStore: VaultStore+ private lateinit var unlockCoordinator: UnlockCoordinator++ private lateinit var fields: List<Pair<AutofillId, FieldType>>+ private var appInfo: String? = null++ override fun onCreate(savedInstanceState: Bundle?) {+ super.onCreate(savedInstanceState)++ try {+ val autofillIds = parseAutofillIds(intent)+ val fieldTypeOrdinals = intent.getIntArrayExtra(EXTRA_FIELD_TYPES)+ if (autofillIds == null || fieldTypeOrdinals == null ||+ autofillIds.size != fieldTypeOrdinals.size+ ) {+ Log.w(TAG, "AutofillUnlockActivity: missing or mismatched extras, finishing")+ cancelAndFinish()+ return+ }+ fields = pairFields(autofillIds, fieldTypeOrdinals)+ appInfo = intent.getStringExtra(EXTRA_APP_INFO)++ vaultStore = VaultStore.getExistingInstance() ?: run {+ val keystoreProvider = AndroidKeystoreProvider(applicationContext) { this }+ val storageProvider = AndroidStorageProvider(applicationContext)+ VaultStore.getInstance(keystoreProvider, storageProvider)+ }++ setContentView(R.layout.activity_loading)++ // Vault may have been unlocked in another flow between the+ // FillResponse being built and the user tapping the row. Skip the+ // unlock prompt entirely in that case.+ if (vaultStore.isVaultUnlocked()) {+ onVaultUnlocked()+ return+ }++ unlockCoordinator = UnlockCoordinator(+ activity = this,+ vaultStore = vaultStore,+ onUnlocked = { onVaultUnlocked() },+ onCancelled = { cancelAndFinish() },+ onError = { message -> showError(message) },+ )+ unlockCoordinator.startUnlockFlow()+ } catch (e: Exception) {+ Log.e(TAG, "Error in onCreate", e)+ if (findViewById<View>(R.id.errorContainer) == null) {+ setContentView(R.layout.activity_loading)+ }+ showError("An error occurred: ${e.message}")+ }+ }++ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {+ super.onActivityResult(requestCode, resultCode, data)+ when (requestCode) {+ UnlockCoordinator.REQUEST_CODE_PIN_UNLOCK ->+ unlockCoordinator.handlePinUnlockResult(resultCode, data)+ UnlockCoordinator.REQUEST_CODE_PASSWORD_UNLOCK ->+ unlockCoordinator.handlePasswordUnlockResult(resultCode, data)+ }+ }++ /**+ * Build the post-unlock FillResponse on a background thread and finish the+ * activity with the result expected by the Autofill framework.+ */+ private fun onVaultUnlocked() {+ lifecycleScope.launch {+ try {+ val response = withContext(Dispatchers.IO) { buildFillResponse() }+ val result = Intent().apply {+ putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, response)+ }+ setResult(RESULT_OK, result)+ finish()+ } catch (e: Exception) {+ Log.e(TAG, "Error building post-unlock fill response", e)+ showError("Failed to load credentials")+ }+ }+ }++ private fun buildFillResponse(): FillResponse {+ val allItems = vaultStore.getAllItems()++ val filteredByApp = appInfo?.let {+ RustItemMatcher.filterItemsByAppInfo(allItems, it)+ } ?: allItems++ val matchingItems = filteredByApp.filter { item ->+ val hasIdentifier = !item.username.isNullOrEmpty() || !item.email.isNullOrEmpty()+ val hasPassword = !item.password.isNullOrEmpty()+ hasIdentifier && hasPassword+ }++ Log.d(+ TAG,+ "Post-unlock items: app matches=${filteredByApp.size}, with data=${matchingItems.size}",+ )++ val copyTotpOnFill = getSharedPreferences("AliasVaultPrefs", MODE_PRIVATE)+ .getBoolean("autofill_copy_totp_on_fill", true)++ val responseBuilder = FillResponse.Builder()+ if (matchingItems.isEmpty()) {+ responseBuilder.addDataset(+ AutofillDatasetBuilder.createNoMatchesDataset(this, fields, appInfo),+ )+ } else {+ for (item in matchingItems) {+ responseBuilder.addDataset(+ AutofillDatasetBuilder.createItemDataset(+ context = this,+ fields = fields,+ item = item,+ copyTotpOnSelect = copyTotpOnFill && item.hasTotp,+ ),+ )+ }+ }+ return responseBuilder.build()+ }++ @Suppress("DEPRECATION")+ private fun parseAutofillIds(intent: Intent): Array<AutofillId>? {+ return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {+ intent.getParcelableArrayExtra(EXTRA_AUTOFILL_IDS, AutofillId::class.java)+ } else {+ intent.getParcelableArrayExtra(EXTRA_AUTOFILL_IDS)+ ?.mapNotNull { it as? AutofillId }+ ?.toTypedArray()+ }+ }++ private fun pairFields(+ autofillIds: Array<AutofillId>,+ fieldTypeOrdinals: IntArray,+ ): List<Pair<AutofillId, FieldType>> {+ val types = FieldType.values()+ return autofillIds.mapIndexed { i, id ->+ id to (types.getOrNull(fieldTypeOrdinals[i]) ?: FieldType.UNKNOWN)+ }+ }++ private fun cancelAndFinish() {+ setResult(RESULT_CANCELED)+ finish()+ }++ /**+ * Show an inline error with a Close button. Mirrors the pattern used by+ * other unlock-driven activities.+ */+ private fun showError(message: String) {+ runOnUiThread {+ try {+ findViewById<View>(R.id.loadingIndicator)?.visibility = View.GONE+ findViewById<View>(R.id.errorContainer)?.visibility = View.VISIBLE+ findViewById<TextView>(R.id.errorMessage)?.text = message+ findViewById<com.google.android.material.button.MaterialButton>(R.id.closeButton)+ ?.setOnClickListener { cancelAndFinish() }+ } catch (e: Exception) {+ Log.e(TAG, "Error showing error UI", e)+ cancelAndFinish()+ }+ }+ }+}diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/AutofillDatasetBuilder.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/AutofillDatasetBuilder.ktnew file mode 100644index 000000000..dbcd68754--- /dev/null+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/AutofillDatasetBuilder.kt@@ -0,0 +1,126 @@+package net.aliasvault.app.autofill.utils++import android.app.PendingIntent+import android.content.Context+import android.content.Intent+import android.service.autofill.Dataset+import android.util.Log+import android.view.autofill.AutofillId+import android.view.autofill.AutofillValue+import android.widget.RemoteViews+import net.aliasvault.app.R+import net.aliasvault.app.autofill.AutofillFillActivity+import net.aliasvault.app.autofill.models.FieldType+import net.aliasvault.app.utils.ItemTypeIcon+import net.aliasvault.app.vaultstore.models.Item+import java.net.URLEncoder++/**+ * Shared builders for rendering autofill picker rows.+ */+object AutofillDatasetBuilder {+ private const val TAG = "AliasVaultAutofill"++ /**+ * Build a Dataset for a single vault item shown in the autofill picker.+ *+ * The Dataset wires `setAuthentication` to [AutofillFillActivity], which is+ * responsible for performing the actual fill (and optionally copying the+ * TOTP code to the clipboard) once the user selects the row.+ */+ fun createItemDataset(+ context: Context,+ fields: List<Pair<AutofillId, FieldType>>,+ item: Item,+ copyTotpOnSelect: Boolean,+ ): Dataset {+ val presentation = RemoteViews(context.packageName, R.layout.autofill_dataset_item_icon)+ val builder = Dataset.Builder(presentation)++ val applyResult = AutofillFieldMapper.applyItem(builder, item, fields)+ if (!applyResult.hasValue && fields.isNotEmpty()) {+ Log.w(TAG, "Item ${item.name} has no autofillable data - this should have been filtered")+ builder.setValue(fields.first().first, AutofillValue.forText(""))+ }++ val displayValue = if (applyResult.labelSuffix != null) {+ "${item.name} (${applyResult.labelSuffix})"+ } else {+ item.name+ }+ presentation.setTextViewText(R.id.text, displayValue)++ val logoBytes = item.logo+ val bitmap = if (logoBytes != null) {+ ImageUtils.bytesToBitmap(logoBytes)+ } else {+ ItemTypeIcon.getIcon(+ context = context,+ itemType = ItemTypeIcon.ItemType.LOGIN,+ size = 96,+ )+ }+ if (bitmap != null) {+ presentation.setImageViewBitmap(R.id.icon, bitmap)+ }++ val autofillIds = fields.map { it.first }.toTypedArray()+ val fieldTypeOrdinals = IntArray(fields.size) { i -> fields[i].second.ordinal }+ val authIntent = Intent(context, AutofillFillActivity::class.java).apply {+ putExtra(AutofillFillActivity.EXTRA_ITEM_ID, item.id.toString().uppercase())+ putExtra(AutofillFillActivity.EXTRA_AUTOFILL_IDS, autofillIds)+ putExtra(AutofillFillActivity.EXTRA_FIELD_TYPES, fieldTypeOrdinals)+ putExtra(AutofillFillActivity.EXTRA_COPY_TOTP, copyTotpOnSelect)+ }+ val pendingIntent = PendingIntent.getActivity(+ context,+ item.id.hashCode(),+ authIntent,+ PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_CANCEL_CURRENT,+ )+ builder.setAuthentication(pendingIntent.intentSender)++ return builder.build()+ }++ /**+ * Build a "No matches found" Dataset that deep-links into AliasVault's+ * action picker so the user can link the current site/app to an existing+ * credential or create a new one.+ */+ fun createNoMatchesDataset(+ context: Context,+ fields: List<Pair<AutofillId, FieldType>>,+ appInfo: String?,+ ): Dataset {+ val presentation = RemoteViews(context.packageName, R.layout.autofill_dataset_item_logo)+ presentation.setTextViewText(+ R.id.text,+ context.getString(R.string.autofill_no_match_found),+ )++ val dataSetBuilder = Dataset.Builder(presentation)++ val encodedUrl = appInfo?.let { URLEncoder.encode(it, "UTF-8") } ?: ""+ val deepLinkUrl = "aliasvault://items/autofill-open-app?itemUrl=$encodedUrl"++ val intent = Intent(Intent.ACTION_VIEW).apply {+ data = android.net.Uri.parse(deepLinkUrl)+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)+ }+ val pendingIntent = PendingIntent.getActivity(+ context,+ 0,+ intent,+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,+ )+ dataSetBuilder.setAuthentication(pendingIntent.intentSender)++ // Android requires at least one value to be set on a Dataset.+ for (field in fields) {+ dataSetBuilder.setValue(field.first, AutofillValue.forText(""))+ }++ return dataSetBuilder.build()+ }+}diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyAuthenticationActivity.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyAuthenticationActivity.ktindex fe44efede..a376214c7 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyAuthenticationActivity.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyAuthenticationActivity.kt@@ -108,9 +108,12 @@ class PasskeyAuthenticationActivity : FragmentActivity() {override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {super.onActivityResult(requestCode, resultCode, data)- // Delegate PIN unlock result to coordinator- if (requestCode == UnlockCoordinator.REQUEST_CODE_PIN_UNLOCK) {- unlockCoordinator.handlePinUnlockResult(resultCode, data)+ // Delegate unlock activity results to the coordinator+ when (requestCode) {+ UnlockCoordinator.REQUEST_CODE_PIN_UNLOCK ->+ unlockCoordinator.handlePinUnlockResult(resultCode, data)+ UnlockCoordinator.REQUEST_CODE_PASSWORD_UNLOCK ->+ unlockCoordinator.handlePasswordUnlockResult(resultCode, data)}}diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyRegistrationActivity.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyRegistrationActivity.ktindex 3ed750ea5..f2c811870 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyRegistrationActivity.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyRegistrationActivity.kt@@ -136,9 +136,12 @@ class PasskeyRegistrationActivity : FragmentActivity() {override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {super.onActivityResult(requestCode, resultCode, data)- // Delegate PIN unlock result to coordinator- if (requestCode == UnlockCoordinator.REQUEST_CODE_PIN_UNLOCK) {- unlockCoordinator.handlePinUnlockResult(resultCode, data)+ // Delegate unlock activity results to the coordinator+ when (requestCode) {+ UnlockCoordinator.REQUEST_CODE_PIN_UNLOCK ->+ unlockCoordinator.handlePinUnlockResult(resultCode, data)+ UnlockCoordinator.REQUEST_CODE_PASSWORD_UNLOCK ->+ unlockCoordinator.handlePasswordUnlockResult(resultCode, data)}}diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/UnlockCoordinator.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/UnlockCoordinator.ktindex 57c2006d5..ed4eeca39 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/UnlockCoordinator.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/UnlockCoordinator.kt@@ -3,7 +3,7 @@ package net.aliasvault.app.credentialproviderimport android.content.Intentimport android.util.Logimport androidx.fragment.app.FragmentActivity-import net.aliasvault.app.R+import net.aliasvault.app.passwordunlock.PasswordUnlockActivityimport net.aliasvault.app.pinunlock.PinUnlockActivityimport net.aliasvault.app.vaultstore.AppErrorimport net.aliasvault.app.vaultstore.VaultStore@@ -36,12 +36,20 @@ class UnlockCoordinator(* when handling onActivityResult for PIN unlock.*/const val REQUEST_CODE_PIN_UNLOCK = 1001++ /**+ * Request code for password unlock activity result.+ * Activities using UnlockCoordinator should use this constant+ * when handling onActivityResult for password unlock.+ */+ const val REQUEST_CODE_PASSWORD_UNLOCK = 1002}/*** Start the unlock flow by checking which auth method is enabled.- * Priority: Biometric -> PIN -> Error- * Biometrics takes priority, PIN serves as fallback if biometrics fails or is unavailable.+ * Priority: Biometric -> PIN -> Password+ * Biometrics takes priority, PIN serves as fallback, and master password+ * is the final fallback (always available).*/fun startUnlockFlow() {val pinEnabled = vaultStore.isPinEnabled()@@ -59,9 +67,9 @@ class UnlockCoordinator(launchPinUnlock()}else -> {- // Neither PIN nor biometric is enabled- Log.e(TAG, "No unlock method is enabled or available")- onError(activity.getString(R.string.error_unlock_method_required))+ // Neither PIN nor biometric is enabled - fall back to master password+ Log.d(TAG, "No biometric or PIN configured, falling back to password unlock")+ launchPasswordUnlock()}}}@@ -75,6 +83,16 @@ class UnlockCoordinator(activity.startActivityForResult(intent, REQUEST_CODE_PIN_UNLOCK)}+ /**+ * Launch password unlock activity.+ * Used as a final fallback when neither biometric nor PIN unlock is available+ * (or when both have failed).+ */+ fun launchPasswordUnlock() {+ val intent = Intent(activity, PasswordUnlockActivity::class.java)+ activity.startActivityForResult(intent, REQUEST_CODE_PASSWORD_UNLOCK)+ }+/*** Attempt biometric unlock using the keystore provider.* Can be called directly to retry biometric unlock.@@ -114,7 +132,6 @@ class UnlockCoordinator(/*** Handle result from PIN unlock activity.- * Call this from the activity's onActivityResult method.*/fun handlePinUnlockResult(resultCode: Int, data: Intent?) {when (resultCode) {@@ -141,14 +158,53 @@ class UnlockCoordinator(onCancelled()}PinUnlockActivity.RESULT_PIN_DISABLED -> {- // PIN was disabled due to max attempts - fall back to biometric if available- Log.w(TAG, "PIN was disabled, attempting biometric unlock fallback")+ // PIN was disabled due to max attempts - fall back to biometric if available,+ // otherwise master password.+ Log.w(TAG, "PIN was disabled, attempting fallback")if (vaultStore.isBiometricAuthEnabled()) {attemptBiometricUnlock()} else {- onError(activity.getString(R.string.error_unlock_method_required))+ launchPasswordUnlock()+ }+ }+ }+ }++ /**+ * Handle result from password unlock activity.+ * Call this from the activity's onActivityResult method.+ */+ fun handlePasswordUnlockResult(resultCode: Int, data: Intent?) {+ when (resultCode) {+ PasswordUnlockActivity.RESULT_SUCCESS -> {+ val encryptionKey = data?.getStringExtra(PasswordUnlockActivity.EXTRA_ENCRYPTION_KEY)+ if (encryptionKey != null) {+ try {+ vaultStore.storeEncryptionKeyInMemory(encryptionKey)+ vaultStore.unlockVault()+ onUnlocked()+ } catch (e: Exception) {+ Log.e(TAG, "Failed to unlock vault after password unlock", e)+ onError(getUnlockErrorMessage(e))+ }+ } else {+ Log.e(TAG, "No encryption key returned from password unlock")+ onError("Failed to unlock vault")}}+ PasswordUnlockActivity.RESULT_MAX_ATTEMPTS_REACHED -> {+ // Vault has been cleared due to too many failed attempts.+ Log.w(TAG, "Password unlock failed: max attempts reached")+ onError("Too many failed unlock attempts")+ }+ PasswordUnlockActivity.RESULT_CANCELLED -> {+ Log.d(TAG, "Password unlock cancelled by user")+ onCancelled()+ }+ else -> {+ Log.e(TAG, "Unknown result from password unlock: $resultCode")+ onError("Failed to unlock vault")+ }}}@@ -168,23 +224,22 @@ class UnlockCoordinator(}/**- * Handle errors during biometric keystore retrieval.- * Falls back to PIN if enabled, otherwise reports the error.+ * Handle errors during biometric keystore retrieval, including the+ * user dismissing the prompt. Falls back to PIN if enabled, otherwise to+ * master password, mirroring the in-app and iOS autofill behavior so the+ * user always has another way to unlock if biometrics is unavailable+ * (e.g. fingerprint not recognized, or they tapped Cancel deliberately+ * because they want to use a different method).*/private fun handleBiometricKeystoreError(e: Exception) {- // For any biometric error, try PIN fallback if enabledif (vaultStore.isPinEnabled()) {- Log.d(TAG, "Biometric failed (${e.message}), falling back to PIN")+ Log.d(TAG, "Biometric unavailable (${e.message}), falling back to PIN")launchPinUnlock()- return // Don't call onError, we're falling back to PIN+ return}- // No PIN fallback available - report the error- val errorMessage = when (e) {- is AppError.BiometricCancelled -> "Authentication cancelled"- else -> "Failed to retrieve encryption key"- }- onError(errorMessage)+ Log.d(TAG, "Biometric unavailable (${e.message}), falling back to password")+ launchPasswordUnlock()}/**diff --git a/apps/mobile-app/android/app/src/main/res/values-night/styles.xml b/apps/mobile-app/android/app/src/main/res/values-night/styles.xmlindex cc962162f..993513271 100644--- a/apps/mobile-app/android/app/src/main/res/values-night/styles.xml+++ b/apps/mobile-app/android/app/src/main/res/values-night/styles.xml@@ -10,8 +10,16 @@<item name="android:windowLightStatusBar">false</item><item name="android:windowLightNavigationBar">false</item></style>-- <style name="PasskeyRegistrationTheme" parent="Theme.Material3.DayNight.NoActionBar">+ <!-- Dark mode splash screen theme -->+ <style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">+ <item name="windowSplashScreenBackground">@color/splashscreen_background</item>+ <item name="windowSplashScreenAnimatedIcon">@drawable/splashscreen_logo</item>+ <item name="windowSplashScreenAnimationDuration">0</item>+ <item name="android:windowSplashScreenIconBackgroundColor">@android:color/transparent</item>+ <item name="postSplashScreenTheme">@style/AppTheme</item>+ </style>+ <!-- Dark mode overrides for Theme.App.Overlay. -->+ <style name="Theme.App.Overlay" parent="Theme.Material3.DayNight.NoActionBar"><item name="colorPrimary">@color/av_primary</item><item name="colorOnPrimary">#FFFFFF</item><item name="android:colorBackground">@color/av_background</item>@@ -22,22 +30,6 @@<item name="android:windowDrawsSystemBarBackgrounds">true</item><item name="android:windowLightStatusBar">false</item><item name="android:windowLightNavigationBar">false</item>- <!--- windowIsTranslucent keeps the calling app's activity in onPause rather than onStop- while our credential-provider UI is on top. Some apps (X.com) cancel their- CredentialManager request when their activity goes to onStop, so without this- flag the request is killed mid-biometric. The activity remains visually opaque- because its content view supplies its own background.- --><item name="android:windowIsTranslucent">true</item></style>-- <!-- Dark mode splash screen theme -->- <style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">- <item name="windowSplashScreenBackground">@color/splashscreen_background</item>- <item name="windowSplashScreenAnimatedIcon">@drawable/splashscreen_logo</item>- <item name="windowSplashScreenAnimationDuration">0</item>- <item name="android:windowSplashScreenIconBackgroundColor">@android:color/transparent</item>- <item name="postSplashScreenTheme">@style/AppTheme</item>- </style></resources>diff --git a/apps/mobile-app/android/app/src/main/res/values/styles.xml b/apps/mobile-app/android/app/src/main/res/values/styles.xmlindex 6fc3bf63f..0cf54e249 100644--- a/apps/mobile-app/android/app/src/main/res/values/styles.xml+++ b/apps/mobile-app/android/app/src/main/res/values/styles.xml@@ -10,26 +10,6 @@<item name="android:textColorHint">#c8c8c8</item><item name="android:textColor">@android:color/black</item></style>- <style name="PasskeyRegistrationTheme" parent="Theme.Material3.DayNight.NoActionBar">- <item name="colorPrimary">@color/av_primary</item>- <item name="colorOnPrimary">#FFFFFF</item>- <item name="android:colorBackground">@color/av_background</item>- <item name="android:textColorPrimary">@color/av_text</item>- <item name="android:textColorSecondary">@color/av_text_muted</item>- <item name="android:statusBarColor">@color/av_background</item>- <item name="android:navigationBarColor">@color/av_background</item>- <item name="android:windowDrawsSystemBarBackgrounds">true</item>- <item name="android:windowLightStatusBar">true</item>- <item name="android:windowLightNavigationBar">true</item>- <!--- windowIsTranslucent keeps the calling app's activity in onPause rather than onStop- while our credential-provider UI is on top. Some apps (X.com) cancel their- CredentialManager request when their activity goes to onStop, so without this- flag the request is killed mid-biometric. The activity remains visually opaque- because its content view supplies its own background.- -->- <item name="android:windowIsTranslucent">true</item>- </style><style name="PinNumpadButton" parent="Widget.MaterialComponents.Button"><item name="android:layout_width">0dp</item><item name="android:layout_height">56dp</item>@@ -52,5 +32,18 @@<item name="android:windowSplashScreenIconBackgroundColor">@android:color/transparent</item><item name="postSplashScreenTheme">@style/AppTheme</item></style>+ <style name="Theme.App.Overlay" parent="Theme.Material3.DayNight.NoActionBar">+ <item name="colorPrimary">@color/av_primary</item>+ <item name="colorOnPrimary">#FFFFFF</item>+ <item name="android:colorBackground">@color/av_background</item>+ <item name="android:textColorPrimary">@color/av_text</item>+ <item name="android:textColorSecondary">@color/av_text_muted</item>+ <item name="android:statusBarColor">@color/av_background</item>+ <item name="android:navigationBarColor">@color/av_background</item>+ <item name="android:windowDrawsSystemBarBackgrounds">true</item>+ <item name="android:windowLightStatusBar">true</item>+ <item name="android:windowLightNavigationBar">true</item>+ <item name="android:windowIsTranslucent">true</item>+ </style><style name="Theme.App.NoDisplay" parent="@android:style/Theme.NoDisplay" /></resources>\ No newline at end of file