Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Improve error reporting for Android native autofill issues (#2141)
Leendert de Borst5ddb23c9a6a9
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.ktindex 0db3eca5f..f9b742803 100644--- 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.kt@@ -8,7 +8,6 @@ import android.util.Logimport android.view.Viewimport android.view.autofill.AutofillIdimport android.view.autofill.AutofillManager-import android.widget.TextViewimport androidx.fragment.app.FragmentActivityimport androidx.lifecycle.lifecycleScopeimport kotlinx.coroutines.Dispatchers@@ -19,6 +18,7 @@ import net.aliasvault.app.autofill.models.FieldTypeimport net.aliasvault.app.autofill.utils.AutofillDatasetBuilderimport net.aliasvault.app.autofill.utils.RustItemMatcherimport net.aliasvault.app.credentialprovider.UnlockCoordinator+import net.aliasvault.app.utils.ErrorScreenViewimport net.aliasvault.app.vaultstore.VaultStoreimport net.aliasvault.app.vaultstore.keystoreprovider.AndroidKeystoreProviderimport net.aliasvault.app.vaultstore.storageprovider.AndroidStorageProvider@@ -97,7 +97,7 @@ class AutofillUnlockActivity : FragmentActivity() {if (findViewById<View>(R.id.errorContainer) == null) {setContentView(R.layout.activity_loading)}- showError("An error occurred: ${e.message}")+ showError("An error occurred: ${e.message}", buildErrorDetail(e))}}@@ -126,7 +126,7 @@ class AutofillUnlockActivity : FragmentActivity() {finish()} catch (e: Exception) {Log.e(TAG, "Error building post-unlock fill response", e)- showError("Failed to load credentials")+ showError("Failed to load credentials", buildErrorDetail(e))}}}@@ -199,21 +199,21 @@ class AutofillUnlockActivity : FragmentActivity() {}/**- * Show an inline error with a Close button. Mirrors the pattern used by- * other unlock-driven activities.+ * Show an inline error with a Close button, optionally exposing a collapsed+ * "Show details" toggle with the copy-pasteable [detail]. Delegates to the+ * shared [ErrorScreenView] used by the other native error screens.*/- 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()- }- }+ private fun showError(message: String, detail: String? = null) {+ ErrorScreenView.show(this, message, detail) { cancelAndFinish() }+ }++ /**+ * Build the diagnostic detail for a failure, adding the autofill-specific+ * context (target app and detected field count) to the shared device/app+ * info and stack trace.+ */+ private fun buildErrorDetail(e: Throwable): String {+ val extra = "App: ${appInfo ?: "unknown"}, fields=${if (::fields.isInitialized) fields.size else 0}"+ return ErrorScreenView.buildDiagnosticDetail(this, e, extra)}}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.ktindex 2c4e179a9..bd9b17b1f 100644--- 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.kt@@ -3,6 +3,7 @@ package net.aliasvault.app.autofill.utilsimport android.app.PendingIntentimport android.content.Contextimport android.content.Intent+import android.graphics.Bitmapimport android.service.autofill.Datasetimport android.util.Logimport android.view.autofill.AutofillId@@ -52,19 +53,7 @@ object AutofillDatasetBuilder {}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 bitmap = buildLogoBitmap(context, item, presentation)if (inlineSpec != null) {val itemDeepLink = "aliasvault://items/${item.id.toString().uppercase()}"@@ -107,6 +96,32 @@ object AutofillDatasetBuilder {return builder.build()}+ /**+ * Resolve the row icon and apply it to [presentation], returning the bitmap+ * so it can be reused for the inline presentation.+ */+ private fun buildLogoBitmap(context: Context, item: Item, presentation: RemoteViews): Bitmap? {+ return try {+ 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)+ }+ bitmap+ } catch (e: Exception) {+ Log.w(TAG, "Failed to render logo for '${item.name}' - showing credential without it", e)+ null+ }+ }+/*** 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 existingdiff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/ImageUtils.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/ImageUtils.ktindex a7a14eabb..ed70012e0 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/ImageUtils.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/ImageUtils.kt@@ -26,7 +26,7 @@ object ImageUtils {return try {when (detectMimeType(bytes)) {"image/svg+xml" -> svgToBitmap(bytes)- else -> BitmapFactory.decodeByteArray(bytes, 0, bytes.size)+ else -> decodeSampledRaster(bytes)}} catch (e: Exception) {Log.e(TAG, "Error converting bytes to bitmap", e)@@ -34,6 +34,47 @@ object ImageUtils {}}+ /**+ * Decode a raster image (PNG/JPEG/ICO) downsampled to roughly the autofill+ * icon size.+ */+ private fun decodeSampledRaster(bytes: ByteArray): Bitmap? {+ val density = Resources.getSystem().displayMetrics.density+ val maxSizePx = (TARGET_SIZE_DP * density).toInt().coerceAtLeast(1)++ // First pass: read the source dimensions without allocating the bitmap.+ val boundsOptions = BitmapFactory.Options().apply { inJustDecodeBounds = true }+ BitmapFactory.decodeByteArray(bytes, 0, bytes.size, boundsOptions)+ val srcWidth = boundsOptions.outWidth+ val srcHeight = boundsOptions.outHeight+ if (srcWidth <= 0 || srcHeight <= 0) {+ // Bounds unavailable (e.g. some ICO files) - fall back to a plain decode.+ return BitmapFactory.decodeByteArray(bytes, 0, bytes.size)+ }++ // Second pass: decode at the largest power-of-two sample that stays at or+ // above the target size, then scale the remainder down precisely.+ var sampleSize = 1+ while (srcWidth / (sampleSize * 2) >= maxSizePx && srcHeight / (sampleSize * 2) >= maxSizePx) {+ sampleSize *= 2+ }+ val decodeOptions = BitmapFactory.Options().apply { inSampleSize = sampleSize }+ val decoded = BitmapFactory.decodeByteArray(bytes, 0, bytes.size, decodeOptions) ?: return null++ val largestDim = maxOf(decoded.width, decoded.height)+ if (largestDim <= maxSizePx) {+ return decoded+ }+ val scale = maxSizePx.toFloat() / largestDim+ val scaledWidth = (decoded.width * scale).toInt().coerceAtLeast(1)+ val scaledHeight = (decoded.height * scale).toInt().coerceAtLeast(1)+ val scaled = Bitmap.createScaledBitmap(decoded, scaledWidth, scaledHeight, true)+ if (scaled != decoded) {+ decoded.recycle()+ }+ return scaled+ }+/*** Detect the mime type of the bytes.* @param bytes The bytes to detect the mime type ofdiff --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 1068ff076..7f26d0550 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@@ -14,6 +14,7 @@ import kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.launchimport kotlinx.coroutines.withContextimport net.aliasvault.app.R+import net.aliasvault.app.utils.ErrorScreenViewimport net.aliasvault.app.utils.Helpersimport net.aliasvault.app.vaultstore.VaultStoreimport net.aliasvault.app.vaultstore.keystoreprovider.AndroidKeystoreProvider@@ -100,7 +101,7 @@ class PasskeyAuthenticationActivity : FragmentActivity() {if (findViewById<View>(R.id.errorContainer) == null) {setContentView(R.layout.activity_loading)}- showError("An error occurred: ${e.message}")+ showError("An error occurred: ${e.message}", ErrorScreenView.buildDiagnosticDetail(this, e))}}@@ -392,42 +393,15 @@ class PasskeyAuthenticationActivity : FragmentActivity() {}/**- * Show error message in the loading view and display a close button.- * Hides the loading indicator and shows the error state.+ * Show error message in the loading view and display a close button,+ * optionally exposing a collapsed "Show details" toggle with the+ * copy-pasteable [detail]. Delegates to the shared [ErrorScreenView].*/- private fun showError(message: String) {+ private fun showError(message: String, detail: String? = null) {Log.d(TAG, "showError called with message: $message")- runOnUiThread {- try {- // Hide loading indicator- val loadingIndicator = findViewById<View>(R.id.loadingIndicator)- loadingIndicator?.visibility = View.GONE- Log.d(TAG, "Loading indicator hidden")-- // Show error container- val errorContainer = findViewById<View>(R.id.errorContainer)- errorContainer?.visibility = View.VISIBLE- Log.d(TAG, "Error container shown")-- // Set error message- val errorMessageView = findViewById<TextView>(R.id.errorMessage)- errorMessageView?.text = message- Log.d(TAG, "Error message set: $message")-- // Setup close button- val closeButton = findViewById<com.google.android.material.button.MaterialButton>(R.id.closeButton)- closeButton?.setOnClickListener {- Log.d(TAG, "Close button clicked")- setResult(RESULT_CANCELED)- finish()- }- Log.d(TAG, "Close button listener set")- } catch (e: Exception) {- Log.e(TAG, "Error in showError", e)- // Fallback: just finish the activity- setResult(RESULT_CANCELED)- finish()- }+ ErrorScreenView.show(this, message, detail) {+ setResult(RESULT_CANCELED)+ finish()}}}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 03d9ea21f..08b7a3839 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@@ -4,7 +4,6 @@ import android.content.Intentimport android.os.Buildimport android.os.Bundleimport android.util.Log-import android.view.Viewimport android.widget.TextViewimport androidx.activity.viewModelsimport androidx.credentials.CreatePublicKeyCredentialRequest@@ -17,6 +16,7 @@ import kotlinx.coroutines.launchimport kotlinx.coroutines.withContextimport net.aliasvault.app.Rimport net.aliasvault.app.credentialprovider.models.PasskeyRegistrationViewModel+import net.aliasvault.app.utils.ErrorScreenViewimport net.aliasvault.app.utils.Helpersimport net.aliasvault.app.vaultstore.VaultStoreimport net.aliasvault.app.vaultstore.keystoreprovider.AndroidKeystoreProvider@@ -226,7 +226,7 @@ class PasskeyRegistrationActivity : FragmentActivity() {}} catch (e: Exception) {Log.e(TAG, "Error verifying origin", e)- showError("Error verifying application: ${e.message}")+ showError("Error verifying application: ${e.message}", ErrorScreenView.buildDiagnosticDetail(this@PasskeyRegistrationActivity, e))}}}@@ -303,40 +303,12 @@ class PasskeyRegistrationActivity : FragmentActivity() {}/**- * Show error message in the loading view and display a close button.- * Hides the loading indicator and shows the error state.+ * Show error message in the loading view and display a close button,+ * optionally exposing a collapsed "Show details" toggle with the+ * copy-pasteable [detail]. Delegates to the shared [ErrorScreenView].*/- private fun showError(message: String) {+ private fun showError(message: String, detail: String? = null) {Log.d(TAG, "showError called with message: $message")- runOnUiThread {- try {- // Hide loading indicator- val loadingIndicator = findViewById<View>(R.id.loadingIndicator)- loadingIndicator?.visibility = View.GONE- Log.d(TAG, "Loading indicator hidden")-- // Show error container- val errorContainer = findViewById<View>(R.id.errorContainer)- errorContainer?.visibility = View.VISIBLE- Log.d(TAG, "Error container shown")-- // Set error message- val errorMessageView = findViewById<TextView>(R.id.errorMessage)- errorMessageView?.text = message- Log.d(TAG, "Error message set: $message")-- // Setup close button- val closeButton = findViewById<com.google.android.material.button.MaterialButton>(R.id.closeButton)- closeButton?.setOnClickListener {- Log.d(TAG, "Close button clicked")- finish()- }- Log.d(TAG, "Close button listener set")- } catch (e: Exception) {- Log.e(TAG, "Error in showError", e)- // Fallback: just finish the activity- finish()- }- }+ ErrorScreenView.show(this, message, detail) { finish() }}}diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/utils/ErrorScreenView.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/utils/ErrorScreenView.ktnew file mode 100644index 000000000..e798528bb--- /dev/null+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/utils/ErrorScreenView.kt@@ -0,0 +1,124 @@+package net.aliasvault.app.utils++import android.app.Activity+import android.content.ClipData+import android.content.ClipboardManager+import android.content.Context+import android.os.Build+import android.util.Log+import android.view.View+import android.widget.TextView+import android.widget.Toast+import com.google.android.material.button.MaterialButton+import net.aliasvault.app.R++/**+ * Shared helper for the error state of the `activity_loading.xml` layout used by+ * the native unlock / passkey / autofill activities.+ *+ * Includes a user facing error that can be expanded and copied.+ */+object ErrorScreenView {+ private const val TAG = "ErrorScreenView"+ private const val CLIP_LABEL = "AliasVault error detail"++ /**+ * Populate and reveal the error state.+ *+ * @param activity Hosting activity whose current content view exposes the+ * `activity_loading.xml` error view ids (errorContainer, errorMessage,+ * closeButton and the optional errorDetails* views).+ * @param message User-facing error message.+ * @param detail Optional technical detail shown behind the "Show details"+ * toggle and copyable to the clipboard. The toggle stays hidden when this+ * is null or blank.+ * @param onClose Invoked when the user taps Close, and as a fallback if the+ * error UI itself fails to render.+ */+ fun show(activity: Activity, message: String, detail: String? = null, onClose: () -> Unit) {+ activity.runOnUiThread {+ try {+ activity.findViewById<View>(R.id.loadingIndicator)?.visibility = View.GONE+ activity.findViewById<View>(R.id.errorContainer)?.visibility = View.VISIBLE+ activity.findViewById<TextView>(R.id.errorMessage)?.text = message+ activity.findViewById<MaterialButton>(R.id.closeButton)?.setOnClickListener { onClose() }+ bindDetail(activity, detail)+ } catch (e: Exception) {+ Log.e(TAG, "Error showing error UI", e)+ onClose()+ }+ }+ }++ /**+ * Build a copy-pasteable diagnostic string for a failure: app/device context+ * plus the full stack trace. Intended to be passed as [show]'s `detail`.+ *+ * @param context Hosting context, used to read the app version.+ * @param throwable The failure to describe.+ * @param extraContext Optional caller-specific context line, e.g.+ * "App: example.com, fields=2".+ */+ fun buildDiagnosticDetail(context: Context, throwable: Throwable, extraContext: String? = null): String {+ return buildString {+ appendLine("App version: ${appVersion(context)}")+ appendLine("Device: ${Build.MANUFACTURER} ${Build.MODEL}")+ appendLine("Android: ${Build.VERSION.RELEASE} (SDK ${Build.VERSION.SDK_INT})")+ if (!extraContext.isNullOrBlank()) {+ appendLine(extraContext)+ }+ appendLine()+ append(Log.getStackTraceString(throwable))+ }+ }++ /**+ * Wire the collapsible technical-detail section. Keeps the toggle hidden when+ * there is nothing useful to share, so callers that pass no detail get the+ * plain message-and-close error screen.+ */+ private fun bindDetail(activity: Activity, detail: String?) {+ val toggle = activity.findViewById<MaterialButton>(R.id.errorDetailsToggle)+ val container = activity.findViewById<View>(R.id.errorDetailsContainer)+ val detailText = activity.findViewById<TextView>(R.id.errorDetailsText)+ val copyButton = activity.findViewById<MaterialButton>(R.id.errorDetailsCopyButton)+ if (toggle == null || container == null || detailText == null || copyButton == null) { return }++ if (detail.isNullOrBlank()) {+ toggle.visibility = View.GONE+ container.visibility = View.GONE+ return+ }++ detailText.text = detail+ toggle.visibility = View.VISIBLE+ container.visibility = View.GONE+ toggle.setText(R.string.common_show_details)++ toggle.setOnClickListener {+ val expanded = container.visibility == View.VISIBLE+ container.visibility = if (expanded) View.GONE else View.VISIBLE+ toggle.setText(if (expanded) R.string.common_show_details else R.string.common_hide_details)+ }++ copyButton.setOnClickListener {+ try {+ val clipboard = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager+ clipboard.setPrimaryClip(ClipData.newPlainText(CLIP_LABEL, detail))+ Toast.makeText(activity, R.string.common_copied_to_clipboard, Toast.LENGTH_SHORT).show()+ } catch (e: Exception) {+ Log.e(TAG, "Error copying error detail to clipboard", e)+ }+ }+ }++ private fun appVersion(context: Context): String {+ return try {+ val pkg = context.packageManager.getPackageInfo(context.packageName, 0)+ "${pkg.versionName} (${pkg.longVersionCode})"+ } catch (e: Exception) {+ Log.e(TAG, "Error reading app version", e)+ "unknown"+ }+ }+}diff --git a/apps/mobile-app/android/app/src/main/res/layout/activity_loading.xml b/apps/mobile-app/android/app/src/main/res/layout/activity_loading.xmlindex c10ec7a1e..ecdc5f9e7 100644--- a/apps/mobile-app/android/app/src/main/res/layout/activity_loading.xml+++ b/apps/mobile-app/android/app/src/main/res/layout/activity_loading.xml@@ -33,6 +33,58 @@android:gravity="center"android:lineSpacingMultiplier="1.3" />+ <!-- Collapsible technical error detail. Hidden by default. -->+ <com.google.android.material.button.MaterialButton+ android:id="@+id/errorDetailsToggle"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_marginTop="8dp"+ android:text="@string/common_show_details"+ android:textColor="@color/av_primary"+ style="@style/Widget.Material3.Button.TextButton"+ android:textSize="14sp"+ android:visibility="gone" />++ <LinearLayout+ android:id="@+id/errorDetailsContainer"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:layout_marginTop="4dp"+ android:orientation="vertical"+ android:visibility="gone">++ <ScrollView+ android:layout_width="match_parent"+ android:layout_height="200dp"+ android:background="@color/av_accent_background"+ android:scrollbars="vertical">++ <TextView+ android:id="@+id/errorDetailsText"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:padding="12dp"+ android:textColor="@color/av_text"+ android:textSize="12sp"+ android:textIsSelectable="true"+ android:fontFamily="monospace"+ android:gravity="start" />++ </ScrollView>++ <com.google.android.material.button.MaterialButton+ android:id="@+id/errorDetailsCopyButton"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_gravity="center_horizontal"+ android:layout_marginTop="8dp"+ android:text="@string/common_copy"+ android:textColor="@color/av_primary"+ style="@style/Widget.Material3.Button.TextButton"+ android:textSize="14sp" />++ </LinearLayout>+<com.google.android.material.button.MaterialButtonandroid:id="@+id/closeButton"android:layout_width="match_parent"diff --git a/apps/mobile-app/android/app/src/main/res/values/strings.xml b/apps/mobile-app/android/app/src/main/res/values/strings.xmlindex 22e5ac4eb..ea172c57c 100644--- a/apps/mobile-app/android/app/src/main/res/values/strings.xml+++ b/apps/mobile-app/android/app/src/main/res/values/strings.xml@@ -9,6 +9,10 @@<string name="common_next">Next</string><string name="common_cancel">Cancel</string><string name="common_back">Back</string>+ <string name="common_show_details">Show details</string>+ <string name="common_hide_details">Hide details</string>+ <string name="common_copy">Copy</string>+ <string name="common_copied_to_clipboard">Copied to clipboard</string><string name="unknown_error">An unknown error occurred</string><string name="autofill_failed_to_retrieve">Failed to retrieve, open app</string><string name="autofill_no_match_found">No match found</string>