Skip to content

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

Add show search title option to Android autofill (#1332)

Leendert de Borst661f0574c568
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.kt
index 8a8de4b85..c7e18f01e 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
@@ -96,8 +96,12 @@ class AutofillService : AutofillService() {
val responseBuilder = FillResponse.Builder()
- // Add debug dataset showing what we're searching for
- responseBuilder.addDataset(createSearchDebugDataset(fieldFinder, appInfo ?: "unknown"))
+ // Add debug dataset if enabled in settings
+ val sharedPreferences = getSharedPreferences("AliasVaultPrefs", android.content.Context.MODE_PRIVATE)
+ val showSearchText = sharedPreferences.getBoolean("autofill_show_search_text", false)
+ if (showSearchText) {
+ responseBuilder.addDataset(createSearchDebugDataset(fieldFinder, appInfo ?: "unknown"))
+ }
// Add failed to retrieve dataset
responseBuilder.addDataset(createFailedToRetrieveDataset(fieldFinder))
@@ -169,8 +173,12 @@ class AutofillService : AutofillService() {
val responseBuilder = FillResponse.Builder()
- // Always add debug dataset as first option showing what we're searching for
- responseBuilder.addDataset(createSearchDebugDataset(fieldFinder, appInfo ?: "unknown"))
+ // Add debug dataset if enabled in settings
+ val sharedPreferences = getSharedPreferences("AliasVaultPrefs", android.content.Context.MODE_PRIVATE)
+ val showSearchText = sharedPreferences.getBoolean("autofill_show_search_text", false)
+ if (showSearchText) {
+ responseBuilder.addDataset(createSearchDebugDataset(fieldFinder, appInfo ?: "unknown"))
+ }
// If there are no results, return "no matches" placeholder option.
if (filteredCredentials.isEmpty()) {
@@ -193,7 +201,11 @@ class AutofillService : AutofillService() {
Log.e(TAG, "Error parsing credentials", e)
// Show "Failed to retrieve, open app" option instead of failing
val responseBuilder = FillResponse.Builder()
- responseBuilder.addDataset(createSearchDebugDataset(fieldFinder, appInfo ?: "unknown"))
+ val sharedPreferences = getSharedPreferences("AliasVaultPrefs", android.content.Context.MODE_PRIVATE)
+ val showSearchText = sharedPreferences.getBoolean("autofill_show_search_text", false)
+ if (showSearchText) {
+ responseBuilder.addDataset(createSearchDebugDataset(fieldFinder, appInfo ?: "unknown"))
+ }
responseBuilder.addDataset(createFailedToRetrieveDataset(fieldFinder))
callback(responseBuilder.build())
}
@@ -203,7 +215,11 @@ class AutofillService : AutofillService() {
Log.e(TAG, "Error getting credentials", e)
// Show "Failed to retrieve, open app" option instead of failing
val responseBuilder = FillResponse.Builder()
- responseBuilder.addDataset(createSearchDebugDataset(fieldFinder, appInfo ?: "unknown"))
+ val sharedPreferences = getSharedPreferences("AliasVaultPrefs", android.content.Context.MODE_PRIVATE)
+ val showSearchText = sharedPreferences.getBoolean("autofill_show_search_text", false)
+ if (showSearchText) {
+ responseBuilder.addDataset(createSearchDebugDataset(fieldFinder, appInfo ?: "unknown"))
+ }
responseBuilder.addDataset(createFailedToRetrieveDataset(fieldFinder))
callback(responseBuilder.build())
}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/FieldFinder.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/FieldFinder.kt
index b42ab6112..994110d70 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/FieldFinder.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/FieldFinder.kt
@@ -237,12 +237,49 @@ class FieldFinder(var structure: AssistStructure) {
}
}
+ /**
+ * Check if a field should be excluded from autofill (e.g., email composition, search fields).
+ * @param node The node to check
+ * @return Whether the node should be excluded from autofill
+ */
+ private fun isExcludedField(node: AssistStructure.ViewNode): Boolean {
+ val idEntry = node.idEntry?.lowercase()
+ val hint = node.hint?.lowercase()
+ val contentDescription = node.contentDescription?.toString()?.lowercase()
+
+ // Common patterns for non-login fields that should be excluded
+ val excludePatterns = listOf(
+ // Email composition fields
+ "to", "from", "cc", "bcc", "recipient", "compose", "subject",
+ // Search fields
+ "search", "query", "find",
+ // Other non-login contexts
+ "comment", "reply", "message", "chat", "filter",
+ )
+
+ // Check if any exclude pattern matches
+ for (pattern in excludePatterns) {
+ val idEntryContains = idEntry?.contains(pattern, ignoreCase = false) == true
+ val hintContains = hint?.contains(pattern, ignoreCase = false) == true
+ val contentContains = contentDescription?.contains(pattern, ignoreCase = false) == true
+
+ return idEntryContains || hintContains || contentContains
+ }
+
+ return false
+ }
+
/**
* Check if a node is an email field.
* @param node The node to check
* @return Whether the node is an email field
*/
private fun isEmailField(node: AssistStructure.ViewNode): Boolean {
+ // Exclude non-login email fields (like "To" in email clients)
+ if (isExcludedField(node)) {
+ return false
+ }
+
// Check input type for email - mask to get only the variation bits
val inputType = node.inputType
if ((inputType and android.text.InputType.TYPE_MASK_CLASS) == android.text.InputType.TYPE_CLASS_TEXT &&
@@ -297,6 +334,11 @@ class FieldFinder(var structure: AssistStructure) {
* @return Whether the node is a username field
*/
private fun isUsernameField(node: AssistStructure.ViewNode): Boolean {
+ // Exclude non-login fields
+ if (isExcludedField(node)) {
+ return false
+ }
+
val searchTerms = listOf("username", "user")
// Check autofill hints
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt
index 542dcd690..0e947404b 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt
@@ -845,6 +845,39 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Get the autofill show search text setting.
+ * @param promise The promise to resolve with boolean result
+ */
+ @ReactMethod
+ override fun getAutofillShowSearchText(promise: Promise) {
+ try {
+ val sharedPreferences = reactApplicationContext.getSharedPreferences("AliasVaultPrefs", android.content.Context.MODE_PRIVATE)
+ val showSearchText = sharedPreferences.getBoolean("autofill_show_search_text", false)
+ promise.resolve(showSearchText)
+ } catch (e: Exception) {
+ Log.e(TAG, "Error getting autofill show search text setting", e)
+ promise.reject("ERR_GET_AUTOFILL_SETTING", "Failed to get autofill show search text setting: ${e.message}", e)
+ }
+ }
+
+ /**
+ * Set the autofill show search text setting.
+ * @param showSearchText Whether to show search text in autofill
+ * @param promise The promise to resolve
+ */
+ @ReactMethod
+ override fun setAutofillShowSearchText(showSearchText: Boolean, promise: Promise) {
+ try {
+ val sharedPreferences = reactApplicationContext.getSharedPreferences("AliasVaultPrefs", android.content.Context.MODE_PRIVATE)
+ sharedPreferences.edit().putBoolean("autofill_show_search_text", showSearchText).apply()
+ promise.resolve(null)
+ } catch (e: Exception) {
+ Log.e(TAG, "Error setting autofill show search text setting", e)
+ promise.reject("ERR_SET_AUTOFILL_SETTING", "Failed to set autofill show search text setting: ${e.message}", e)
+ }
+ }
+
/**
* Get the current fragment activity.
* @return The fragment activity
diff --git a/apps/mobile-app/app/(tabs)/settings/android-autofill.tsx b/apps/mobile-app/app/(tabs)/settings/android-autofill.tsx
index 38dd4a5ab..b4ecb6def 100644
--- a/apps/mobile-app/app/(tabs)/settings/android-autofill.tsx
+++ b/apps/mobile-app/app/(tabs)/settings/android-autofill.tsx
@@ -1,6 +1,7 @@
import { router } from 'expo-router';
import { useTranslation } from 'react-i18next';
-import { StyleSheet, View, TouchableOpacity, Linking } from 'react-native';
+import { StyleSheet, View, TouchableOpacity, Linking, Switch } from 'react-native';
+import { useState, useEffect } from 'react';
import { useColors } from '@/hooks/useColorScheme';
@@ -17,6 +18,23 @@ export default function AndroidAutofillScreen() : React.ReactNode {
const colors = useColors();
const { t } = useTranslation();
const { markAutofillConfigured, shouldShowAutofillReminder } = useAuth();
+ const [advancedOptionsExpanded, setAdvancedOptionsExpanded] = useState(false);
+ const [showSearchText, setShowSearchText] = useState(false);
+
+ /**
+ * Load the show search text setting on mount.
+ */
+ useEffect(() => {
+ const loadSettings = async () => {
+ try {
+ const value = await NativeVaultManager.getAutofillShowSearchText();
+ setShowSearchText(value);
+ } catch (err) {
+ console.warn('Failed to load autofill settings:', err);
+ }
+ };
+ loadSettings();
+ }, []);
/**
* Handle the configure press.
@@ -45,10 +63,70 @@ export default function AndroidAutofillScreen() : React.ReactNode {
Linking.openURL('https://docs.aliasvault.net/mobile-apps/android/autofill.html');
};
+ /**
+ * Handle toggling the show search text setting.
+ */
+ const handleToggleShowSearchText = async (value: boolean) : Promise<void> => {
+ try {
+ await NativeVaultManager.setAutofillShowSearchText(value);
+ setShowSearchText(value);
+ } catch (err) {
+ console.warn('Failed to update show search text setting:', err);
+ }
+ };
+
const styles = StyleSheet.create({
+ advancedOptionsContainer: {
+ marginTop: 16,
+ paddingBottom: 16,
+ },
+ advancedOptionsDescription: {
+ color: colors.textMuted,
+ fontSize: 13,
+ lineHeight: 18,
+ marginBottom: 8,
+ },
+ advancedOptionsHeader: {
+ alignItems: 'center',
+ flexDirection: 'row',
+ justifyContent: 'space-between',
+ marginBottom: 12,
+ },
+ advancedOptionsTitle: {
+ color: colors.text,
+ fontSize: 15,
+ fontWeight: '600',
+ },
+ advancedOptionsToggle: {
+ alignItems: 'center',
+ backgroundColor: colors.accentBackground,
+ borderRadius: 8,
+ flexDirection: 'row',
+ justifyContent: 'space-between',
+ marginBottom: 16,
+ padding: 16,
+ },
+ advancedOptionsToggleContainer: {
+ flex: 1,
+ marginRight: 12,
+ },
+ advancedOptionsToggleHeader: {
+ alignItems: 'center',
+ flexDirection: 'row',
+ paddingVertical: 8,
+ },
+ advancedOptionsToggleText: {
+ color: colors.text,
+ fontSize: 15,
+ fontWeight: '500',
+ },
buttonContainer: {
padding: 16,
- paddingBottom: 32,
+ paddingBottom: 16,
+ },
+ chevron: {
+ color: colors.textMuted,
+ fontSize: 20,
},
configureButton: {
alignItems: 'center',
@@ -92,6 +170,31 @@ export default function AndroidAutofillScreen() : React.ReactNode {
fontSize: 16,
fontWeight: '600',
},
+ settingRow: {
+ alignItems: 'center',
+ backgroundColor: colors.accentBackground,
+ borderRadius: 10,
+ flexDirection: 'row',
+ justifyContent: 'space-between',
+ marginBottom: 12,
+ padding: 16,
+ },
+ settingRowDescription: {
+ color: colors.textMuted,
+ fontSize: 13,
+ lineHeight: 18,
+ marginTop: 4,
+ },
+ settingRowText: {
+ color: colors.text,
+ flex: 1,
+ marginRight: 12,
+ },
+ settingRowTitle: {
+ color: colors.text,
+ fontSize: 15,
+ fontWeight: '500',
+ },
tipStep: {
color: colors.textMuted,
fontSize: 13,
@@ -174,6 +277,41 @@ export default function AndroidAutofillScreen() : React.ReactNode {
)}
</View>
</View>
+
+ <View style={styles.advancedOptionsContainer}>
+ <TouchableOpacity
+ style={styles.advancedOptionsToggleHeader}
+ onPress={() => setAdvancedOptionsExpanded(!advancedOptionsExpanded)}
+ >
+ <ThemedText style={styles.advancedOptionsTitle}>
+ {t('settings.androidAutofillSettings.advancedOptions')}
+ </ThemedText>
+ <ThemedText style={styles.chevron}>
+ {advancedOptionsExpanded ? '▼' : '▶'}
+ </ThemedText>
+ </TouchableOpacity>
+
+ {advancedOptionsExpanded && (
+ <View>
+ <View style={styles.settingRow}>
+ <View style={styles.settingRowText}>
+ <ThemedText style={styles.settingRowTitle}>
+ {t('settings.androidAutofillSettings.showSearchText')}
+ </ThemedText>
+ <ThemedText style={styles.settingRowDescription}>
+ {t('settings.androidAutofillSettings.showSearchTextDescription')}
+ </ThemedText>
+ </View>
+ <Switch
+ value={showSearchText}
+ onValueChange={handleToggleShowSearchText}
+ trackColor={{ false: colors.accentBackground, true: colors.primary }}
+ thumbColor={colors.primarySurfaceText}
+ />
+ </View>
+ </View>
+ )}
+ </View>
</ThemedScrollView>
</ThemedContainer>
);
diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.json
index c29f11d02..1a93169a0 100644
--- a/apps/mobile-app/i18n/locales/en.json
+++ b/apps/mobile-app/i18n/locales/en.json
@@ -224,7 +224,10 @@
"openAutofillSettings": "Open Autofill Settings",
"buttonTip": "If the button above doesn't work it might be blocked because of security settings. You can manually go to Android Settings → General Management → Passwords and autofill.",
"step2": "2. Some apps, e.g. Google Chrome, may require manual configuration in their settings to allow third-party autofill apps. However, most apps should work with autofill by default.",
- "alreadyConfigured": "I already configured it"
+ "alreadyConfigured": "I already configured it",
+ "advancedOptions": "Advanced Options",
+ "showSearchText": "Show search text",
+ "showSearchTextDescription": "Include the text AliasVault receives from Android that it uses to search for a matching credential"
},
"vaultUnlock": "Vault Unlock Method",
"autoLock": "Auto-lock Timeout",
diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
index 2798942d3..758635656 100644
--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
@@ -413,6 +413,21 @@ public class VaultManager: NSObject {
}
}
+ @objc
+ func getAutofillShowSearchText(_ resolve: @escaping RCTPromiseResolveBlock,
+ rejecter reject: @escaping RCTPromiseRejectBlock) {
+ // iOS autofill doesn't have this feature, always return false
+ resolve(false)
+ }
+
+ @objc
+ func setAutofillShowSearchText(_ showSearchText: Bool,
+ resolver resolve: @escaping RCTPromiseResolveBlock,
+ rejecter reject: @escaping RCTPromiseRejectBlock) {
+ // iOS autofill doesn't have this feature, no-op
+ resolve(nil)
+ }
+
@objc
func copyToClipboardWithExpiration(_ text: String,
expirationSeconds: Double,
diff --git a/apps/mobile-app/specs/NativeVaultManager.ts b/apps/mobile-app/specs/NativeVaultManager.ts
index 955c216af..d6f1139ed 100644
--- a/apps/mobile-app/specs/NativeVaultManager.ts
+++ b/apps/mobile-app/specs/NativeVaultManager.ts
@@ -40,6 +40,8 @@ export interface Spec extends TurboModule {
getAutoLockTimeout(): Promise<number>;
getAuthMethods(): Promise<string[]>;
openAutofillSettingsPage(): Promise<void>;
+ getAutofillShowSearchText(): Promise<boolean>;
+ setAutofillShowSearchText(showSearchText: boolean): Promise<void>;
// Clipboard management
clearClipboardAfterDelay(delayInSeconds: number): Promise<void>;