Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Show service logo if it has one in autofill suggestion (#846)

Leendert de Borst551fc42de199
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/AutofillService.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/AutofillService.kt
index 3bdbeb7ee..704be7eef 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/AutofillService.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/AutofillService.kt
@@ -44,6 +44,8 @@ import net.aliasvault.app.vaultstore.models.Credential
import net.aliasvault.app.autofill.CredentialMatcher
import androidx.core.net.toUri
import android.app.PendingIntent
+import android.graphics.Bitmap
+import net.aliasvault.app.autofill.ImageUtils
class AutofillService : AutofillService() {
private val TAG = "AliasVaultAutofill"
@@ -353,13 +355,40 @@ class AutofillService : AutofillService() {
fieldFinder: FieldFinder,
credential: Credential
) {
+ // Choose layout based on whether we have a logo
+ val layoutId = if (credential.service.logo != null) {
+ R.layout.autofill_dataset_item_icon
+ } else {
+ R.layout.autofill_dataset_item
+ }
+
// Create presentation for this credential using our custom layout
- val presentation = RemoteViews(packageName, R.layout.autofill_dataset_item)
+ val presentation = RemoteViews(packageName, layoutId)
presentation.setTextViewText(
R.id.text,
"${credential.username} (${credential.service.name})"
)
+ // Set the logo if available
+ val logoBytes = credential.service.logo
+ if (logoBytes != null) {
+ val mimeType = ImageUtils.detectMimeType(logoBytes)
+ if (mimeType == "image/svg+xml") {
+ // For SVG, we need to convert it to a bitmap first
+ // This is a simplified approach - in production you might want to use a proper SVG library
+ val bitmap = ImageUtils.bytesToBitmap(logoBytes)
+ if (bitmap != null) {
+ presentation.setImageViewBitmap(R.id.icon, bitmap)
+ }
+ } else {
+ // For other image types, try to decode directly
+ val bitmap = ImageUtils.bytesToBitmap(logoBytes)
+ if (bitmap != null) {
+ presentation.setImageViewBitmap(R.id.icon, bitmap)
+ }
+ }
+ }
+
val dataSetBuilder = Dataset.Builder(presentation)
// Add autofill values for all fields
@@ -380,8 +409,6 @@ class AutofillService : AutofillService() {
responseBuilder.addDataset(dataSetBuilder.build())
}
-
-
private fun filterCredentialsByAppInfo(credentials: List<Credential>, appInfo: String): List<Credential> {
return credentialMatcher.filterCredentialsByAppInfo(credentials, appInfo)
}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/ImageUtils.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/ImageUtils.kt
new file mode 100644
index 000000000..b11f26479
--- /dev/null
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/ImageUtils.kt
@@ -0,0 +1,63 @@
+package net.aliasvault.app.autofill
+
+import android.graphics.Bitmap
+import android.graphics.BitmapFactory
+import android.util.Base64
+import java.io.ByteArrayInputStream
+import java.io.ByteArrayOutputStream
+
+object ImageUtils {
+ fun detectMimeType(bytes: ByteArray): String {
+ // Check for SVG
+ if (bytes.size >= 5) {
+ val header = String(bytes.slice(0..4).toByteArray()).lowercase()
+ if (header.contains("<?xml") || header.contains("<svg")) {
+ return "image/svg+xml"
+ }
+ }
+
+ // Check for PNG
+ if (bytes.size >= 4 &&
+ bytes[0] == 0x89.toByte() &&
+ bytes[1] == 0x50.toByte() &&
+ bytes[2] == 0x4E.toByte() &&
+ bytes[3] == 0x47.toByte()
+ ) {
+ return "image/png"
+ }
+
+ // Check for ICO
+ if (bytes.size >= 4 &&
+ bytes[0] == 0x00.toByte() &&
+ bytes[1] == 0x00.toByte() &&
+ bytes[2] == 0x01.toByte() &&
+ bytes[3] == 0x00.toByte()
+ ) {
+ return "image/x-icon"
+ }
+
+ return "image/x-icon"
+ }
+
+ fun bytesToBitmap(bytes: ByteArray): Bitmap? {
+ return try {
+ BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
+ } catch (e: Exception) {
+ null
+ }
+ }
+
+ fun bitmapToBytes(bitmap: Bitmap): ByteArray {
+ val stream = ByteArrayOutputStream()
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
+ return stream.toByteArray()
+ }
+
+ fun base64ToBytes(base64: String): ByteArray? {
+ return try {
+ Base64.decode(base64, Base64.DEFAULT)
+ } catch (e: Exception) {
+ null
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/mobile-app/android/app/src/main/res/drawable/rounded_corner_background.xml b/apps/mobile-app/android/app/src/main/res/drawable/rounded_corner_background.xml
new file mode 100644
index 000000000..3ef9995cb
--- /dev/null
+++ b/apps/mobile-app/android/app/src/main/res/drawable/rounded_corner_background.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <corners android:radius="4dp" />
+ <solid android:color="#FFFFFF" />
+ <stroke
+ android:width="1dp"
+ android:color="#E0E0E0" />
+</shape>
diff --git a/apps/mobile-app/android/app/src/main/res/layout/autofill_dataset_item.xml b/apps/mobile-app/android/app/src/main/res/layout/autofill_dataset_item.xml
index e0f2e1e3a..148151909 100644
--- a/apps/mobile-app/android/app/src/main/res/layout/autofill_dataset_item.xml
+++ b/apps/mobile-app/android/app/src/main/res/layout/autofill_dataset_item.xml
@@ -2,14 +2,15 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:gravity="center_vertical"
android:orientation="horizontal"
- android:padding="8dp">
+ android:padding="8dp"
+ android:gravity="center_vertical">
<TextView
android:id="@+id/text"
- android:layout_width="wrap_content"
+ android:layout_width="0dp"
android:layout_height="wrap_content"
+ android:layout_weight="1"
android:textSize="16sp"
android:textColor="?android:attr/textColorPrimary" />
diff --git a/apps/mobile-app/android/app/src/main/res/layout/autofill_dataset_item_icon.xml b/apps/mobile-app/android/app/src/main/res/layout/autofill_dataset_item_icon.xml
new file mode 100644
index 000000000..e5aac88e1
--- /dev/null
+++ b/apps/mobile-app/android/app/src/main/res/layout/autofill_dataset_item_icon.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:padding="8dp"
+ android:gravity="center_vertical">
+
+ <ImageView
+ android:id="@+id/icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_marginEnd="8dp"
+ android:scaleType="fitCenter"
+ android:background="@drawable/rounded_corner_background" />
+
+ <TextView
+ android:id="@+id/text"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:textSize="16sp"
+ android:textColor="?android:attr/textColorPrimary" />
+
+</LinearLayout>