Skip to content

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

Add aliasvault logo to autofill list item (#846)

Leendert de Borst4b844189bcdc
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 156219b27..3bdbeb7ee 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
@@ -71,11 +71,11 @@ class AutofillService : AutofillService() {
fieldFinder.parseStructure()
// If no password field was found, return an empty response
- /*if (!fieldFinder.foundPasswordField) {
+ if (!fieldFinder.foundPasswordField) {
Log.d(TAG, "No password field found, skipping autofill")
callback.onSuccess(null)
return
- }*/
+ }
// If we found a password field but no username field, and we have a last field,
// assume it's the username field
@@ -144,8 +144,11 @@ class AutofillService : AutofillService() {
val responseBuilder = FillResponse.Builder()
// Create presentation for the "no matches" option
- val presentation = RemoteViews(packageName, android.R.layout.simple_list_item_1)
- presentation.setTextViewText(android.R.id.text1, "AliasVault: no matches")
+ val presentation = RemoteViews(packageName, R.layout.autofill_dataset_item_logo)
+ presentation.setTextViewText(
+ R.id.text,
+ "AliasVault: no matches"
+ )
val dataSetBuilder = Dataset.Builder(presentation)
@@ -162,10 +165,11 @@ class AutofillService : AutofillService() {
)
dataSetBuilder.setAuthentication(pendingIntent.intentSender)
- // Add a placeholder value to satisfy the requirement that at least one value must be set
+ // 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()) {
- val firstField = fieldFinder.autofillableFields.first()
- dataSetBuilder.setValue(firstField.first, AutofillValue.forText(""))
+ for (field in fieldFinder.autofillableFields) {
+ dataSetBuilder.setValue(field.first, AutofillValue.forText(""))
+ }
}
// Add this dataset to the response
@@ -185,6 +189,38 @@ class AutofillService : AutofillService() {
addDatasetForCredential(responseBuilder, fieldFinder, credential)
}
+ // Add "Open AliasVault app" as the last option
+ val openAppPresentation = RemoteViews(packageName, R.layout.autofill_dataset_item_logo)
+ openAppPresentation.setTextViewText(
+ R.id.text,
+ "Open app"
+ )
+
+ val openAppDataSetBuilder = Dataset.Builder(openAppPresentation)
+
+ // 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
+ )
+ openAppDataSetBuilder.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) {
+ openAppDataSetBuilder.setValue(field.first, AutofillValue.forText(""))
+ }
+ }
+
+ // Add this dataset to the response
+ responseBuilder.addDataset(openAppDataSetBuilder.build())
+
// Send the response back
callback.onSuccess(responseBuilder.build())
@@ -317,10 +353,10 @@ class AutofillService : AutofillService() {
fieldFinder: FieldFinder,
credential: Credential
) {
- // Create presentation for this credential
- val presentation = RemoteViews(packageName, android.R.layout.simple_list_item_1)
+ // Create presentation for this credential using our custom layout
+ val presentation = RemoteViews(packageName, R.layout.autofill_dataset_item)
presentation.setTextViewText(
- android.R.id.text1,
+ R.id.text,
"${credential.username} (${credential.service.name})"
)
@@ -480,6 +516,11 @@ class AutofillService : AutofillService() {
for (i in 0 until attributes.size) {
val name = attributes.get(i)?.first
val value = attributes.get(i)?.second
+
+ if (name == "name" && (value == "username" || value == "name" || value == "email" || value == "user")) {
+ return true;
+ }
+
if (name == "type" && (value == "text" || value == "email")) {
// Check if there's a label or placeholder that suggests username
val label = node.hint
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
new file mode 100644
index 000000000..e0f2e1e3a
--- /dev/null
+++ b/apps/mobile-app/android/app/src/main/res/layout/autofill_dataset_item.xml
@@ -0,0 +1,16 @@
+<?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:gravity="center_vertical"
+ android:orientation="horizontal"
+ android:padding="8dp">
+
+ <TextView
+ android:id="@+id/text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="16sp"
+ android:textColor="?android:attr/textColorPrimary" />
+
+</LinearLayout>
diff --git a/apps/mobile-app/android/app/src/main/res/layout/autofill_dataset_item_logo.xml b/apps/mobile-app/android/app/src/main/res/layout/autofill_dataset_item_logo.xml
new file mode 100644
index 000000000..73ab08548
--- /dev/null
+++ b/apps/mobile-app/android/app/src/main/res/layout/autofill_dataset_item_logo.xml
@@ -0,0 +1,24 @@
+<?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:gravity="center_vertical"
+ android:orientation="horizontal"
+ android:padding="8dp">
+
+ <ImageView
+ android:id="@+id/icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_marginEnd="8dp"
+ android:src="@drawable/ic_launcher_foreground"
+ android:contentDescription="@string/aliasvault_icon" />
+
+ <TextView
+ android:id="@+id/text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="16sp"
+ android:textColor="?android:attr/textColorPrimary" />
+
+</LinearLayout>
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.xml
index 864e75844..304e41781 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
@@ -4,4 +4,5 @@
<string name="expo_splash_screen_resize_mode" translatable="false">contain</string>
<string name="expo_splash_screen_status_bar_translucent" translatable="false">false</string>
<string name="autofill_service_description" translatable="true">AliasVault AutoFill</string>
+ <string name="aliasvault_icon">AliasVault icon</string>
</resources>
diff --git a/docs/mobile-apps/android/autofill.md b/docs/mobile-apps/android/autofill.md
index ddf90a1aa..05e57e2e0 100644
--- a/docs/mobile-apps/android/autofill.md
+++ b/docs/mobile-apps/android/autofill.md
@@ -26,4 +26,17 @@ Currently AliasVault implements the `Native Autofill` API which shows an autofil
To configure AliasVault as the autofill provider in Chrome:
1. Open Chrome
2. Go to Menu > Settings > Autofill services
-3. Choose the option `Autofill using another service`
\ No newline at end of file
+3. Choose the option `Autofill using another service`
+
+## Frequently Asked Questions
+
+### Chrome Autofill Issues
+
+#### Autofill suggestions stopped appearing in Chrome
+If you notice that autofill suggestions have stopped appearing in Chrome, this is often due to a Chrome process issue rather than an AliasVault problem. To resolve this:
+
+1. Fully close the Chrome browser on your Android device
+2. Reopen Chrome
+
+This simple restart of the browser process typically resolves the issue and restores autofill functionality.
+