Skip to content

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

Add native Android QR code scanner ZXing implementation (#1405)

Leendert de Borst3654b12cd7d1
diff --git a/apps/mobile-app/android/app/build.gradle b/apps/mobile-app/android/app/build.gradle
index e781eb448..c9d5b598d 100644
--- a/apps/mobile-app/android/app/build.gradle
+++ b/apps/mobile-app/android/app/build.gradle
@@ -202,6 +202,9 @@ dependencies {
// Add modern SQLite library with VACUUM INTO and backup API support
implementation("com.github.requery:sqlite-android:3.49.0")
+ // Add ZXing library for QR code scanning (F-Droid compatible)
+ implementation("com.journeyapps:zxing-android-embedded:4.3.0")
+
// Test dependencies
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:4.0.0'
diff --git a/apps/mobile-app/android/app/src/main/AndroidManifest.xml b/apps/mobile-app/android/app/src/main/AndroidManifest.xml
index d14b7086e..0dd908452 100644
--- a/apps/mobile-app/android/app/src/main/AndroidManifest.xml
+++ b/apps/mobile-app/android/app/src/main/AndroidManifest.xml
@@ -58,6 +58,13 @@
android:theme="@style/PasskeyRegistrationTheme"
android:screenOrientation="portrait" />
+ <!-- QR Scanner Activity -->
+ <activity
+ android:name=".qrscanner.QRScannerActivity"
+ android:exported="false"
+ android:theme="@style/zxing_CaptureTheme"
+ 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/MainActivity.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt
index dc98c2176..a282af1de 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt
@@ -113,6 +113,8 @@ class MainActivity : ReactActivity() {
handlePinUnlockResult(resultCode, data)
} else if (requestCode == net.aliasvault.app.nativevaultmanager.NativeVaultManager.PIN_SETUP_REQUEST_CODE) {
handlePinSetupResult(resultCode, data)
+ } else if (requestCode == net.aliasvault.app.nativevaultmanager.NativeVaultManager.QR_SCANNER_REQUEST_CODE) {
+ handleQRScannerResult(resultCode, data)
}
}
@@ -194,4 +196,31 @@ class MainActivity : ReactActivity() {
}
}
}
+
+ /**
+ * Handle QR scanner result.
+ * @param resultCode The result code from the QR scanner activity.
+ * @param data The intent data containing the scanned QR code.
+ */
+ private fun handleQRScannerResult(resultCode: Int, data: Intent?) {
+ val promise = net.aliasvault.app.nativevaultmanager.NativeVaultManager.pendingActivityResultPromise
+ net.aliasvault.app.nativevaultmanager.NativeVaultManager.pendingActivityResultPromise = null
+
+ if (promise == null) {
+ return
+ }
+
+ when (resultCode) {
+ RESULT_OK -> {
+ val scannedData = data?.getStringExtra("SCAN_RESULT")
+ promise.resolve(scannedData)
+ }
+ RESULT_CANCELED -> {
+ promise.resolve(null)
+ }
+ else -> {
+ promise.resolve(null)
+ }
+ }
+ }
}
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 0b3b1e44b..d8532d8bc 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
@@ -21,6 +21,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
+import net.aliasvault.app.qrscanner.QRScannerActivity
import net.aliasvault.app.vaultstore.VaultStore
import net.aliasvault.app.vaultstore.VaultSyncError
import net.aliasvault.app.vaultstore.keystoreprovider.AndroidKeystoreProvider
@@ -63,6 +64,11 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
*/
const val PIN_SETUP_REQUEST_CODE = 1002
+ /**
+ * Request code for QR scanner activity.
+ */
+ const val QR_SCANNER_REQUEST_CODE = 1003
+
/**
* Static holder for the pending promise from showPinUnlock.
* This allows MainActivity to resolve/reject the promise directly without
@@ -1436,6 +1442,29 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
* @param subtitle The subtitle for authentication. If null or empty, uses default.
* @param promise The promise to resolve with authentication result.
*/
+ @ReactMethod
+ override fun scanQRCode(promise: Promise) {
+ CoroutineScope(Dispatchers.Main).launch {
+ try {
+ val activity = currentActivity
+ if (activity == null) {
+ promise.reject("NO_ACTIVITY", "No activity available", null)
+ return@launch
+ }
+
+ // Store promise for later resolution by MainActivity
+ pendingActivityResultPromise = promise
+
+ // Launch QR scanner activity
+ val intent = Intent(activity, QRScannerActivity::class.java)
+ activity.startActivityForResult(intent, QR_SCANNER_REQUEST_CODE)
+ } catch (e: Exception) {
+ Log.e(TAG, "Failed to launch QR scanner", e)
+ promise.reject("SCANNER_ERROR", "Failed to launch QR scanner: ${e.message}", e)
+ }
+ }
+ }
+
@ReactMethod
override fun authenticateUser(title: String?, subtitle: String?, promise: Promise) {
CoroutineScope(Dispatchers.Main).launch {
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/qrscanner/QRScannerActivity.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/qrscanner/QRScannerActivity.kt
new file mode 100644
index 000000000..c4e711111
--- /dev/null
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/qrscanner/QRScannerActivity.kt
@@ -0,0 +1,115 @@
+package net.aliasvault.app.qrscanner
+
+import android.animation.ObjectAnimator
+import android.app.Activity
+import android.content.Intent
+import android.os.Bundle
+import android.view.View
+import com.google.zxing.ResultPoint
+import com.journeyapps.barcodescanner.BarcodeCallback
+import com.journeyapps.barcodescanner.BarcodeResult
+import com.journeyapps.barcodescanner.CaptureManager
+import com.journeyapps.barcodescanner.DecoratedBarcodeView
+
+/**
+ * Activity for scanning QR codes using ZXing.
+ */
+class QRScannerActivity : Activity() {
+ private lateinit var barcodeView: DecoratedBarcodeView
+ private lateinit var capture: CaptureManager
+ private var hasScanned = false
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ // Create and configure barcode view
+ barcodeView = DecoratedBarcodeView(this)
+ barcodeView.setStatusText("Scan AliasVault QR Code")
+ setContentView(barcodeView)
+
+ // Initialize capture manager
+ capture = CaptureManager(this, barcodeView)
+ capture.initializeFromIntent(intent, savedInstanceState)
+
+ // Set custom callback to add visual feedback
+ barcodeView.decodeContinuous(object : BarcodeCallback {
+ override fun barcodeResult(result: BarcodeResult?) {
+ if (result != null && !hasScanned) {
+ hasScanned = true
+
+ // Show success animation
+ showScanSuccessAnimation()
+
+ // Pause scanning
+ barcodeView.pause()
+
+ // Set result and finish after animation
+ val resultIntent = Intent()
+ resultIntent.putExtra("SCAN_RESULT", result.text)
+ setResult(RESULT_OK, resultIntent)
+
+ // Delay finish to allow animation to complete
+ barcodeView.postDelayed({
+ finish()
+ }, 400) // 400ms delay for animation
+ }
+ }
+
+ override fun possibleResultPoints(resultPoints: List<ResultPoint>) {
+ // No visualization needed
+ }
+ })
+ }
+
+ /**
+ * Show a success animation when QR code is scanned.
+ */
+ private fun showScanSuccessAnimation() {
+ // Flash animation - fade viewfinder quickly
+ val viewFinder: View? = barcodeView.viewFinder
+ if (viewFinder != null) {
+ // Create flash effect by animating alpha
+ val fadeOut = ObjectAnimator.ofFloat(viewFinder, "alpha", 1f, 0.3f)
+ fadeOut.duration = 100
+
+ val fadeIn = ObjectAnimator.ofFloat(viewFinder, "alpha", 0.3f, 1f)
+ fadeIn.duration = 100
+
+ fadeOut.start()
+ fadeOut.addListener(object : android.animation.AnimatorListenerAdapter() {
+ override fun onAnimationEnd(animation: android.animation.Animator) {
+ fadeIn.start()
+ }
+ })
+ }
+ }
+
+ override fun onResume() {
+ super.onResume()
+ capture.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ capture.onPause()
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ capture.onDestroy()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ capture.onSaveInstanceState(outState)
+ }
+
+ @Deprecated("Deprecated in Java")
+ override fun onRequestPermissionsResult(
+ requestCode: Int,
+ permissions: Array<String>,
+ grantResults: IntArray,
+ ) {
+ capture.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ }
+}
diff --git a/apps/mobile-app/app/(tabs)/settings/qr-scanner.tsx b/apps/mobile-app/app/(tabs)/settings/qr-scanner.tsx
index 9f2f250eb..273022ee1 100644
--- a/apps/mobile-app/app/(tabs)/settings/qr-scanner.tsx
+++ b/apps/mobile-app/app/(tabs)/settings/qr-scanner.tsx
@@ -1,8 +1,6 @@
-import { Ionicons } from '@expo/vector-icons';
import { Href, router, useLocalSearchParams } from 'expo-router';
import { useEffect, useCallback, useRef } from 'react';
-import { View, Alert, StyleSheet, Linking } from 'react-native';
-import { Camera, useCameraDevice, useCameraPermission, useCodeScanner } from 'react-native-vision-camera';
+import { View, StyleSheet, Platform, Alert } from 'react-native';
import { useColors } from '@/hooks/useColorScheme';
import { useTranslation } from '@/hooks/useTranslation';
@@ -10,6 +8,7 @@ import { useTranslation } from '@/hooks/useTranslation';
import LoadingIndicator from '@/components/LoadingIndicator';
import { ThemedContainer } from '@/components/themed/ThemedContainer';
import { ThemedText } from '@/components/themed/ThemedText';
+import NativeVaultManager from '@/specs/NativeVaultManager';
// QR Code type prefixes
const QR_CODE_PREFIXES = {
@@ -54,63 +53,17 @@ function parseQRCode(data: string): ScannedQRCode {
export default function QRScannerScreen() : React.ReactNode {
const colors = useColors();
const { t } = useTranslation();
- const { hasPermission, requestPermission } = useCameraPermission();
- const device = useCameraDevice('back');
const { url } = useLocalSearchParams<{ url?: string }>();
const hasProcessedUrl = useRef(false);
const processedUrls = useRef(new Set<string>());
-
- // Request camera permission on mount
- useEffect(() => {
- /**
- * Request camera permission.
- */
- const requestCameraPermission = async () : Promise<void> => {
- if (hasPermission === undefined) {
- return; // Still loading permission status
- }
-
- if (!hasPermission) {
- const permission = await requestPermission();
-
- if (!permission) {
- // Permission was denied
- Alert.alert(
- t('settings.qrScanner.cameraPermissionTitle'),
- t('settings.qrScanner.cameraPermissionMessage'),
- [
- { text: t('common.cancel'),
- /**
- * Go back to the settings tab.
- */
- onPress: (): void => router.back(),
- style: 'cancel'
- },
- {
- text: t('common.openSettings'),
- /**
- * Open app settings.
- */
- onPress: (): void => {
- Linking.openSettings();
- router.back();
- }
- }
- ]
- );
- }
- }
- };
-
- requestCameraPermission();
- }, [hasPermission, requestPermission, t]);
+ const hasLaunchedScanner = useRef(false);
/*
* Handle barcode scanned - parse and navigate to appropriate page.
* Only processes AliasVault QR codes, silently ignores others.
* Validation is handled by the destination page.
*/
- const handleBarcodeScanned = useCallback((data: string) : void => {
+ const handleQRCodeScanned = useCallback((data: string) : void => {
// Prevent processing the same URL multiple times
if (processedUrls.current.has(data)) {
return;
@@ -121,6 +74,8 @@ export default function QRScannerScreen() : React.ReactNode {
// Silently ignore non-AliasVault QR codes
if (!parsedData.type) {
+ // Go back if not an AliasVault QR code
+ router.back();
return;
}
@@ -136,19 +91,37 @@ export default function QRScannerScreen() : React.ReactNode {
}
}, []);
- // Configure code scanner
- const codeScanner = useCodeScanner({
- codeTypes: ['qr'],
- /**
- * Handle QR code scanned.
- * @param codes - Scanned codes.
- */
- onCodeScanned: (codes) => {
- if (codes.length > 0 && codes[0]?.value) {
- handleBarcodeScanned(codes[0].value);
+ /**
+ * Launch the native QR scanner.
+ */
+ const launchScanner = useCallback(async () => {
+ if (hasLaunchedScanner.current) {
+ return;
+ }
+
+ hasLaunchedScanner.current = true;
+
+ try {
+ const scannedData = await NativeVaultManager.scanQRCode();
+
+ if (scannedData) {
+ handleQRCodeScanned(scannedData);
+ } else {
+ // User cancelled or scan failed, go back
+ router.back();
}
- },
- });
+ } catch (error) {
+ console.error('QR scan error:', error);
+ Alert.alert(
+ t('common.error'),
+ 'Failed to scan QR code',
+ [{ text: t('common.ok'), /**
+ * Navigate back.
+ */
+ onPress: (): void => router.back() }]
+ );
+ }
+ }, [handleQRCodeScanned, t]);
/**
* Reset hasProcessedUrl when URL changes to allow processing new URLs.
@@ -163,45 +136,24 @@ export default function QRScannerScreen() : React.ReactNode {
useEffect(() => {
if (url && typeof url === 'string' && !hasProcessedUrl.current) {
hasProcessedUrl.current = true;
- handleBarcodeScanned(url);
+ handleQRCodeScanned(url);
}
- }, [url, handleBarcodeScanned]);
+ }, [url, handleQRCodeScanned]);
+
+ /**
+ * Launch scanner when component mounts (Android/iOS only).
+ */
+ useEffect(() => {
+ if (Platform.OS === 'android' || Platform.OS === 'ios') {
+ launchScanner();
+ }
+ }, [launchScanner]);
const styles = StyleSheet.create({
container: {
flex: 1,
paddingHorizontal: 0,
},
- camera: {
- flex: 1,
- },
- cameraContainer: {
- backgroundColor: colors.black,
- flex: 1,
- },
- cameraOverlay: {
- alignItems: 'center',
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
- bottom: 0,
- justifyContent: 'center',
- left: 0,
- position: 'absolute',
- right: 0,
- top: 0,
- },
- cameraOverlayText: {
- color: colors.white,
- fontSize: 16,
- marginTop: 20,
- paddingHorizontal: 40,
- textAlign: 'center',
- },
- closeButton: {
- position: 'absolute',
- right: 16,
- top: 16,
- zIndex: 10,
- },
loadingContainer: {
alignItems: 'center',
flex: 1,
@@ -210,33 +162,14 @@ export default function QRScannerScreen() : React.ReactNode {
},
});
- // Show permission request screen or loading if device not ready
- if (hasPermission === undefined || !hasPermission || !device) {
- return (
- <ThemedContainer>
- <View style={styles.loadingContainer}>
- <LoadingIndicator />
- </View>
- </ThemedContainer>
- );
- }
-
+ // Show loading while scanner is launching
return (
<ThemedContainer style={styles.container}>
- <View style={styles.cameraContainer}>
- <Camera
- style={styles.camera}
- device={device}
- isActive={true}
- codeScanner={codeScanner}
- >
- <View style={styles.cameraOverlay}>
- <Ionicons name="qr-code-outline" size={100} color={colors.white} />
- <ThemedText style={styles.cameraOverlayText}>
- {t('settings.qrScanner.scanningMessage')}
- </ThemedText>
- </View>
- </Camera>
+ <View style={styles.loadingContainer}>
+ <LoadingIndicator />
+ <ThemedText style={{ marginTop: 20, color: colors.textMuted }}>
+ {t('settings.qrScanner.scanningMessage')}
+ </ThemedText>
</View>
</ThemedContainer>
);
diff --git a/apps/mobile-app/package-lock.json b/apps/mobile-app/package-lock.json
index 9a16c4d0d..9734ec7a8 100644
--- a/apps/mobile-app/package-lock.json
+++ b/apps/mobile-app/package-lock.json
@@ -54,7 +54,6 @@
"react-native-svg": "15.11.2",
"react-native-svg-transformer": "^1.5.0",
"react-native-toast-message": "^2.2.1",
- "react-native-vision-camera": "^4.7.3",
"react-native-webview": "13.13.5",
"secure-remote-password": "github:LinusU/secure-remote-password#73e5f732b6ca0cdbdc19da1a0c5f48cdbad2cbf0",
"yup": "^1.6.1"
@@ -14926,30 +14925,6 @@
"react-native": "*"
}
},
- "node_modules/react-native-vision-camera": {
- "version": "4.7.3",
- "resolved": "https://registry.npmjs.org/react-native-vision-camera/-/react-native-vision-camera-4.7.3.tgz",
- "integrity": "sha512-g1/neOyjSqn1kaAa2FxI/qp5KzNvPcF0bnQw6NntfbxH6tm0+8WFZszlgb5OV+iYlB6lFUztCbDtyz5IpL47OA==",
- "license": "MIT",
- "peerDependencies": {
- "@shopify/react-native-skia": "*",
- "react": "*",
- "react-native": "*",
- "react-native-reanimated": "*",
- "react-native-worklets-core": "*"
- },
- "peerDependenciesMeta": {
- "@shopify/react-native-skia": {
- "optional": true
- },
- "react-native-reanimated": {
- "optional": true
- },
- "react-native-worklets-core": {
- "optional": true
- }
- }
- },
"node_modules/react-native-webview": {
"version": "13.13.5",
"resolved": "https://registry.npmjs.org/react-native-webview/-/react-native-webview-13.13.5.tgz",
diff --git a/apps/mobile-app/package.json b/apps/mobile-app/package.json
index 534905ee2..cc4fa0fcf 100644
--- a/apps/mobile-app/package.json
+++ b/apps/mobile-app/package.json
@@ -75,7 +75,6 @@
"react-native-svg": "15.11.2",
"react-native-svg-transformer": "^1.5.0",
"react-native-toast-message": "^2.2.1",
- "react-native-vision-camera": "^4.7.3",
"react-native-webview": "13.13.5",
"secure-remote-password": "github:LinusU/secure-remote-password#73e5f732b6ca0cdbdc19da1a0c5f48cdbad2cbf0",
"yup": "^1.6.1"
@@ -86,7 +85,6 @@
"@eslint/js": "^9.35.0",
"@react-native-community/cli": "^20.0.0",
"@stylistic/eslint-plugin": "^5.3.1",
- "expo-dev-client": "~5.1.8",
"@types/fbemitter": "^2.0.35",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.16",
@@ -98,6 +96,7 @@
"eslint-config-expo": "~9.2.0",
"eslint-plugin-jsdoc": "^55.2.0",
"eslint-plugin-react-native": "^5.0.0",
+ "expo-dev-client": "~5.1.8",
"globals": "^16.3.0",
"jest": "^29.2.1",
"jest-expo": "~53.0.0",
diff --git a/apps/mobile-app/specs/NativeVaultManager.ts b/apps/mobile-app/specs/NativeVaultManager.ts
index bec75b1ee..f0dd023fb 100644
--- a/apps/mobile-app/specs/NativeVaultManager.ts
+++ b/apps/mobile-app/specs/NativeVaultManager.ts
@@ -105,6 +105,10 @@ export interface Spec extends TurboModule {
// Re-authentication methods
// Authenticate user with biometric or PIN. If title/subtitle are null/empty, defaults to "Unlock Vault" context.
authenticateUser(title: string | null, subtitle: string | null): Promise<boolean>;
+
+ // QR code scanner
+ // Scan a QR code and return the scanned data. Returns null if cancelled or failed.
+ scanQRCode(): Promise<string | null>;
}
export default TurboModuleRegistry.getEnforcing<Spec>('NativeVaultManager');