Skip to content

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

Refactor android to satisfy linting rules (#846)

Leendert de Borst5a8b6b7f2969
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 06aafdb05..19d63a068 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -155,10 +155,10 @@
}
},
{
- "label": "Run Android App",
+ "label": "Run release Android App (device)",
"type": "shell",
"command": "npx",
- "args": ["expo", "run:android"],
+ "args": ["expo", "run:android", "--device", "--variant", "release"],
"problemMatcher": [],
"group": {
"kind": "build",
diff --git a/apps/mobile-app/android/app/build.gradle b/apps/mobile-app/android/app/build.gradle
index 1e83c715b..4631c281a 100644
--- a/apps/mobile-app/android/app/build.gradle
+++ b/apps/mobile-app/android/app/build.gradle
@@ -224,13 +224,14 @@ ktlint {
version.set("0.50.0")
}
-task lintFixAll {
+task lintFormat {
description = "Run all auto-fixers (ktlint and Android lint)"
group = "formatting"
dependsOn 'ktlintFormat'
+ dependsOn 'detekt'
}
-task lintAll {
+task lintCheck {
description = "Run all linting checks (ktlint, Detekt and Android lint)"
group = "formatting"
dependsOn 'ktlintCheck'
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 9e4f64180..450f161f9 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
@@ -7,7 +7,13 @@ import com.facebook.react.defaults.DefaultReactActivityDelegate
import expo.modules.ReactActivityDelegateWrapper
import expo.modules.splashscreen.SplashScreenManager
+/**
+ * The main activity of the app.
+ */
class MainActivity : ReactActivity() {
+ /**
+ * Called when the activity is created.
+ */
override fun onCreate(savedInstanceState: Bundle?) {
// Set the theme to AppTheme BEFORE onCreate to support
// coloring the background, status bar, and navigation bar.
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainApplication.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainApplication.kt
index 03dd14032..3dc5a361b 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainApplication.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainApplication.kt
@@ -15,8 +15,14 @@ import expo.modules.ApplicationLifecycleDispatcher
import expo.modules.ReactNativeHostWrapper
import net.aliasvault.app.nativevaultmanager.NativeVaultManagerPackage
+/**
+ * The main application class.
+ */
class MainApplication : Application(), ReactApplication {
+ /**
+ * The react native host.
+ */
override val reactNativeHost: ReactNativeHost = ReactNativeHostWrapper(
this,
object : DefaultReactNativeHost(this) {
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 8c191375f..07db467c9 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
@@ -28,12 +28,19 @@ import net.aliasvault.app.autofill.utils.CredentialMatcher
import net.aliasvault.app.autofill.utils.FieldFinder
import net.aliasvault.app.autofill.utils.ImageUtils
import net.aliasvault.app.vaultstore.VaultStore
-import net.aliasvault.app.vaultstore.VaultStore.CredentialOperationCallback
+import net.aliasvault.app.vaultstore.interfaces.CredentialOperationCallback
import net.aliasvault.app.vaultstore.models.Credential
+/**
+ * The AutofillService class.
+ */
class AutofillService : AutofillService() {
- private val TAG = "AliasVaultAutofill"
- private val credentialMatcher = CredentialMatcher()
+ companion object {
+ /**
+ * The tag for logging.
+ */
+ private const val TAG = "AliasVaultAutofill"
+ }
override fun onFillRequest(
request: FillRequest,
@@ -65,11 +72,10 @@ class AutofillService : AutofillService() {
// If we found a password field but no username field, and we have a last field,
// assume it's the username field
- // TODO: do we actually need this part?
- if (!fieldFinder.foundUsernameField && fieldFinder.lastField != null) {
+ /*if (!fieldFinder.foundUsernameField && fieldFinder.lastField != null) {
fieldFinder.autofillableFields.add(Pair(fieldFinder.lastField!!, FieldType.USERNAME))
Log.d(TAG, "Using last field as username field: ${fieldFinder.lastField}")
- }
+ }*/
launchActivityForAutofill(fieldFinder, callback)
}
@@ -116,7 +122,7 @@ class AutofillService : AutofillService() {
// Filter credentials based on app/website info
val filteredCredentials = if (appInfo != null) {
- filterCredentialsByAppInfo(result, appInfo)
+ CredentialMatcher.filterCredentialsByAppInfo(result, appInfo)
} else {
result
}
@@ -175,7 +181,12 @@ class AutofillService : AutofillService() {
callback.onSuccess(responseBuilder.build())
}
- // Helper method to create a dataset from a credential
+ /**
+ * Create a dataset from a credential.
+ * @param fieldFinder The field finder
+ * @param credential The credential
+ * @return The dataset
+ */
private fun createCredentialDataset(fieldFinder: FieldFinder, credential: Credential): Dataset {
// Choose layout based on whether we have a logo
val layoutId = if (credential.service.logo != null) {
@@ -269,6 +280,11 @@ class AutofillService : AutofillService() {
return dataSetBuilder.build()
}
+ /**
+ * Create a dataset for the "no matches" option.
+ * @param fieldFinder The field finder
+ * @return The dataset
+ */
private fun createNoMatchesDataset(fieldFinder: FieldFinder): Dataset {
// Create presentation for the "no matches" option
val presentation = RemoteViews(packageName, R.layout.autofill_dataset_item_logo)
@@ -309,6 +325,11 @@ class AutofillService : AutofillService() {
return dataSetBuilder.build()
}
+ /**
+ * Create a dataset for the "open app" option.
+ * @param fieldFinder The field finder
+ * @return The dataset
+ */
private fun createOpenAppDataset(fieldFinder: FieldFinder): Dataset {
val openAppPresentation = RemoteViews(packageName, R.layout.autofill_dataset_item_logo)
openAppPresentation.setTextViewText(
@@ -348,6 +369,11 @@ class AutofillService : AutofillService() {
return dataSetBuilder.build()
}
+ /**
+ * Create a dataset for the "vault locked" option.
+ * @param fieldFinder The field finder
+ * @return The dataset
+ */
private fun createVaultLockedDataset(fieldFinder: FieldFinder): Dataset {
// Create presentation for the "vault locked" option
val presentation = RemoteViews(packageName, R.layout.autofill_dataset_item_logo)
@@ -380,15 +406,4 @@ class AutofillService : AutofillService() {
return dataSetBuilder.build()
}
-
- private fun filterCredentialsByAppInfo(
- credentials: List<Credential>,
- appInfo: String,
- ): List<Credential> {
- return credentialMatcher.filterCredentialsByAppInfo(credentials, appInfo)
- }
-
- companion object {
- private const val TAG = "AliasVaultAutofill"
- }
}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/CredentialMatcher.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/CredentialMatcher.kt
index 36478e7a3..3e2cc04bc 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/CredentialMatcher.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/autofill/utils/CredentialMatcher.kt
@@ -7,8 +7,7 @@ import net.aliasvault.app.vaultstore.models.Credential
* This class handles the logic of determining which credentials are relevant
* for a given app or website context.
*/
-class CredentialMatcher {
-
+object CredentialMatcher {
/**
* Filters a list of credentials based on app/package name or URL.
* Matching strategies in order of specificity:
@@ -30,12 +29,7 @@ class CredentialMatcher {
val rootDomain: String?
val domainKey: String
- if (isUrlLike && (
- input.startsWith("http://") || input.startsWith("https://") || input.startsWith(
- "www.",
- )
- )
- ) {
+ if (isUrlLike && listOf("http://", "https://", "www.").any { input.startsWith(it) }) {
// Treat as full or partial URL
val cleaned = input
.removePrefix("https://")
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 1c1cd6526..4e8e5bb72 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
@@ -9,16 +9,39 @@ import net.aliasvault.app.autofill.models.FieldType
/**
* Helper class to find fields in the assist structure.
+ * @param structure The assist structure to parse
*/
class FieldFinder(var structure: AssistStructure) {
- private val TAG = "AliasVaultAutofill"
+ companion object {
+ /**
+ * The tag for logging.
+ */
+ private const val TAG = "AliasVaultAutofill"
+ }
- // Store pairs of (AutofillId, net.aliasvault.app.autofill.models.FieldType)
+ /**
+ * The list of autofillable fields.
+ */
val autofillableFields = mutableListOf<Pair<AutofillId, FieldType>>()
- var foundPasswordField = false
+
+ /**
+ * Whether a username field has been found.
+ */
var foundUsernameField = false
+
+ /**
+ * Whether a password field has been found.
+ */
+ var foundPasswordField = false
+
+ /**
+ * Whether a username field has been found.
+ */
var lastField: AutofillId? = null
+ /**
+ * Parse the structure.
+ */
fun parseStructure() {
val nodeCount = structure.windowNodeCount
for (i in 0 until nodeCount) {
@@ -84,14 +107,33 @@ class FieldFinder(var structure: AssistStructure) {
* Attempt to find the web domain or URL in the assist structure.
*/
private fun findWebInfoInNode(node: AssistStructure.ViewNode): String? {
- // Check for web domain
+ return findWebInfoFromDomainAndScheme(node)
+ ?: findWebInfoFromUrl(node)
+ ?: findWebInfoFromHtmlAttributes(node)
+ ?: findWebInfoFromHints(node)
+ ?: findWebInfoFromChildren(node)
+ }
+
+ /**
+ * Find the web domain or URL in the assist structure.
+ * @param node The node to search in
+ * @return The web domain or URL
+ */
+ private fun findWebInfoFromDomainAndScheme(node: AssistStructure.ViewNode): String? {
val webDomain = node.webDomain
val webScheme = node.webScheme
if (webDomain != null && webScheme != null) {
return "$webScheme://$webDomain"
}
+ return null
+ }
- // Check for web URL
+ /**
+ * Find the web domain or URL in the assist structure.
+ * @param node The node to search in
+ * @return The web domain or URL
+ */
+ private fun findWebInfoFromUrl(node: AssistStructure.ViewNode): String? {
val webUrl = node.webDomain
if (webUrl != null) {
try {
@@ -104,8 +146,15 @@ class FieldFinder(var structure: AssistStructure) {
Log.e(TAG, "Error parsing web URL: $webUrl", e)
}
}
+ return null
+ }
- // Check HTML info for domain or URL
+ /**
+ * Find the web domain or URL in the assist structure.
+ * @param node The node to search in
+ * @return The web domain or URL
+ */
+ private fun findWebInfoFromHtmlAttributes(node: AssistStructure.ViewNode): String? {
val htmlInfo = node.htmlInfo
if (htmlInfo != null) {
val attributes = htmlInfo.attributes
@@ -119,8 +168,15 @@ class FieldFinder(var structure: AssistStructure) {
}
}
}
+ return null
+ }
- // Check for web-specific hints
+ /**
+ * Find the web domain or URL in the assist structure.
+ * @param node The node to search in
+ * @return The web domain or URL
+ */
+ private fun findWebInfoFromHints(node: AssistStructure.ViewNode): String? {
val hints = node.autofillHints
if (hints != null) {
for (hint in hints) {
@@ -132,8 +188,15 @@ class FieldFinder(var structure: AssistStructure) {
}
}
}
+ return null
+ }
- // Recursively check child nodes
+ /**
+ * Find the web domain or URL in the assist structure.
+ * @param node The node to search in
+ * @return The web domain or URL
+ */
+ private fun findWebInfoFromChildren(node: AssistStructure.ViewNode): String? {
val childCount = node.childCount
for (i in 0 until childCount) {
val webInfo = findWebInfoInNode(node.getChildAt(i))
@@ -141,10 +204,13 @@ class FieldFinder(var structure: AssistStructure) {
return webInfo
}
}
-
return null
}
+ /**
+ * Parse a node.
+ * @param node The node to parse
+ */
private fun parseNode(node: AssistStructure.ViewNode) {
val viewId = node.autofillId
@@ -171,6 +237,11 @@ class FieldFinder(var structure: AssistStructure) {
}
}
+ /**
+ * 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 {
// Check input type for email
if ((node.inputType and android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS) != 0) {
@@ -217,13 +288,20 @@ class FieldFinder(var structure: AssistStructure) {
return false
}
+ /**
+ * Check if a node is a username field.
+ * @param node The node to check
+ * @return Whether the node is a username field
+ */
private fun isUsernameField(node: AssistStructure.ViewNode): Boolean {
+ val searchTerms = listOf("username", "user")
+
// Check autofill hints
val hints = node.autofillHints
if (hints != null) {
for (hint in hints) {
if (hint == View.AUTOFILL_HINT_USERNAME ||
- hint.contains("username", ignoreCase = true)
+ searchTerms.any { term -> hint.contains(term, ignoreCase = true) }
) {
return true
}
@@ -238,20 +316,23 @@ class FieldFinder(var structure: AssistStructure) {
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 == "user")) {
+ if (name == "name" && value != null && searchTerms.any { term ->
+ value.equals(term, ignoreCase = true)
+ }
+ ) {
return true
}
}
}
}
- // Check ID and hint text
+ // Check if ID or hint text contains one of the search terms
val idEntry = node.idEntry
val hint = node.hint
- if (idEntry?.contains("username", ignoreCase = true) == true ||
- idEntry?.contains("user", ignoreCase = true) == true ||
- hint?.contains("username", ignoreCase = true) == true ||
- hint?.contains("user", ignoreCase = true) == true
+ if (searchTerms.any { term ->
+ idEntry?.contains(term, ignoreCase = true) == true ||
+ hint?.contains(term, ignoreCase = true) == true
+ }
) {
return true
}
@@ -259,6 +340,11 @@ class FieldFinder(var structure: AssistStructure) {
return false
}
+ /**
+ * Check if a node is an editable field.
+ * @param node The node to check
+ * @return Whether the node is an editable field
+ */
private fun isEditableField(node: AssistStructure.ViewNode): Boolean {
// Check if the node is editable in any way
return node.inputType > 0 ||
@@ -267,6 +353,11 @@ class FieldFinder(var structure: AssistStructure) {
node.htmlInfo?.tag?.equals("input", ignoreCase = true) == true
}
+ /**
+ * Check if a node is a password field.
+ * @param node The node to check
+ * @return Whether the node is a password field
+ */
private fun isLikelyPasswordField(node: AssistStructure.ViewNode): Boolean {
// Try to determine if this is a password field
val hints = node.autofillHints
@@ -324,6 +415,11 @@ class FieldFinder(var structure: AssistStructure) {
return false
}
+ /**
+ * Find a node by ID.
+ * @param fieldId The ID of the field to find
+ * @return The node
+ */
private fun findNodeById(fieldId: AutofillId): AssistStructure.ViewNode? {
val nodeCount = structure.windowNodeCount
for (i in 0 until nodeCount) {
@@ -337,6 +433,12 @@ class FieldFinder(var structure: AssistStructure) {
return null
}
+ /**
+ * Find a node by ID recursively.
+ * @param node The node to start searching from
+ * @param fieldId The ID of the field to find
+ * @return The node
+ */
private fun findNodeByIdRecursive(
node: AssistStructure.ViewNode,
fieldId: AutofillId,
diff --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.kt
index e4d268ca7..a7a14eabb 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
@@ -17,12 +17,29 @@ object ImageUtils {
private const val TARGET_SIZE_DP = 24
private const val RENDER_SCALE_FACTOR = 4
+ /**
+ * Convert bytes to a bitmap.
+ * @param bytes The bytes to convert
+ * @return The bitmap
+ */
+ fun bytesToBitmap(bytes: ByteArray): Bitmap? {
+ return try {
+ when (detectMimeType(bytes)) {
+ "image/svg+xml" -> svgToBitmap(bytes)
+ else -> BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
+ }
+ } catch (e: Exception) {
+ Log.e(TAG, "Error converting bytes to bitmap", e)
+ null
+ }
+ }
+
/**
* Detect the mime type of the bytes.
* @param bytes The bytes to detect the mime type of
* @return The mime type
*/
- fun detectMimeType(bytes: ByteArray): String {
+ private fun detectMimeType(bytes: ByteArray): String {
// SVG heuristic
if (bytes.size >= 5) {
val header = String(bytes, 0, 5).lowercase()
@@ -51,23 +68,6 @@ object ImageUtils {
return "image/x-icon"
}
- /**
- * Convert bytes to a bitmap.
- * @param bytes The bytes to convert
- * @return The bitmap
- */
- fun bytesToBitmap(bytes: ByteArray): Bitmap? {
- return try {
- when (detectMimeType(bytes)) {
- "image/svg+xml" -> svgToBitmap(bytes)
- else -> BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
- }
- } catch (e: Exception) {
- Log.e(TAG, "Error converting bytes to bitmap", e)
- null
- }
- }
-
/**
* Convert SVG bytes to a bitmap.
* @param bytes The bytes to convert
@@ -98,6 +98,11 @@ object ImageUtils {
}
}
+ /**
+ * Convert a bitmap to bytes.
+ * @param bitmap The bitmap to convert
+ * @return The bytes
+ */
fun bitmapToBytes(bitmap: Bitmap): ByteArray {
return ByteArrayOutputStream().use { stream ->
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
@@ -105,11 +110,12 @@ object ImageUtils {
}
}
- fun base64ToBytes(base64: String): ByteArray? {
- return try {
- Base64.decode(base64, Base64.DEFAULT)
- } catch (e: Exception) {
- null
- }
+ /**
+ * Convert a base64 string to bytes.
+ * @param base64 The base64 string to convert
+ * @return The bytes
+ */
+ fun base64ToBytes(base64: String): ByteArray {
+ return Base64.decode(base64, Base64.DEFAULT)
}
}
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 17a99cff4..c07d2da85 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
@@ -20,13 +20,27 @@ import net.aliasvault.app.vaultstore.keystoreprovider.AndroidKeystoreProvider
import net.aliasvault.app.vaultstore.storageprovider.AndroidStorageProvider
import org.json.JSONArray
+/**
+ * The native vault manager that manages the vault store and all input/output operations on it.
+ * This class implements the NativeVaultManagerSpec React Native interface and then calls the
+ * VaultStore class to perform the actual operations.
+ *
+ * @param reactContext The React context
+ */
@ReactModule(name = NativeVaultManager.NAME)
class NativeVaultManager(reactContext: ReactApplicationContext) :
NativeVaultManagerSpec(reactContext), TurboModule, LifecycleEventListener {
companion object {
- private const val TAG = "NativeVaultManager"
+ /**
+ * The name of the module.
+ */
const val NAME = "NativeVaultManager"
+
+ /**
+ * The tag for logging.
+ */
+ private const val TAG = "NativeVaultManager"
}
private val vaultStore = VaultStore.getInstance(
@@ -39,34 +53,41 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
reactContext.addLifecycleEventListener(this)
}
+ /**
+ * Called when the app enters the background.
+ */
override fun onHostPause() {
Log.d(TAG, "App entered background")
vaultStore.onAppBackgrounded()
}
+ /**
+ * Called when the app enters the foreground.
+ */
override fun onHostResume() {
Log.d(TAG, "App entered foreground")
vaultStore.onAppForegrounded()
}
+ /**
+ * Called when the app is destroyed.
+ */
override fun onHostDestroy() {
// Not needed
}
+ /**
+ * Get the name of the module.
+ * @return The name of the module
+ */
override fun getName(): String {
return NAME
}
- private fun getFragmentActivity(): FragmentActivity? {
- val activity = currentActivity
- return if (activity is FragmentActivity) {
- activity
- } else {
- null
- }
- }
-
- // Basic credential operations
+ /**
+ * Clear the vault.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun clearVault(promise: Promise) {
try {
@@ -78,12 +99,19 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
- // Vault state management
+ /**
+ * Check if the vault is unlocked.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun isVaultUnlocked(promise: Promise) {
promise.resolve(vaultStore.isVaultUnlocked())
}
+ /**
+ * Get the vault metadata.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun getVaultMetadata(promise: Promise) {
try {
@@ -95,6 +123,10 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Unlock the vault.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun unlockVault(promise: Promise) {
try {
@@ -106,7 +138,11 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
- // Database operations
+ /**
+ * Store the encrypted database.
+ * @param base64EncryptedDb The encrypted database as a base64 encoded string
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun storeDatabase(base64EncryptedDb: String, promise: Promise) {
try {
@@ -118,6 +154,11 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Store the metadata.
+ * @param metadata The metadata as a string
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun storeMetadata(metadata: String, promise: Promise) {
try {
@@ -129,6 +170,11 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Set the auth methods.
+ * @param authMethods The auth methods
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun setAuthMethods(authMethods: ReadableArray, promise: Promise) {
try {
@@ -144,6 +190,11 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Store the encryption key.
+ * @param base64EncryptionKey The encryption key as a base64 encoded string
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun storeEncryptionKey(base64EncryptionKey: String, promise: Promise) {
try {
@@ -155,6 +206,11 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Store the encryption key derivation parameters.
+ * @param keyDerivationParams The encryption key derivation parameters
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun storeEncryptionKeyDerivationParams(keyDerivationParams: String, promise: Promise) {
try {
@@ -170,6 +226,10 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Get the encryption key derivation parameters.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun getEncryptionKeyDerivationParams(promise: Promise) {
try {
@@ -185,6 +245,10 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Check if the encrypted database exists.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun hasEncryptedDatabase(promise: Promise) {
try {
@@ -196,6 +260,10 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Get the encrypted database.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun getEncryptedDatabase(promise: Promise) {
try {
@@ -207,6 +275,10 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Get the current vault revision number.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun getCurrentVaultRevisionNumber(promise: Promise) {
try {
@@ -218,6 +290,11 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Set the current vault revision number.
+ * @param revisionNumber The revision number
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun setCurrentVaultRevisionNumber(revisionNumber: Double, promise: Promise?) {
try {
@@ -229,7 +306,12 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
- // SQL operations
+ /**
+ * Execute a query on the vault.
+ * @param query The query
+ * @param params The parameters to the query
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun executeQuery(query: String, params: ReadableArray, promise: Promise) {
try {
@@ -274,6 +356,12 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Execute an update on the vault.
+ * @param query The query
+ * @param params The parameters to the query
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun executeUpdate(query: String, params: ReadableArray, promise: Promise) {
try {
@@ -295,6 +383,10 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Begin a transaction on the vault.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun beginTransaction(promise: Promise) {
try {
@@ -306,6 +398,10 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Commit a transaction on the vault.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun commitTransaction(promise: Promise) {
try {
@@ -321,6 +417,10 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Rollback a transaction on the vault.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun rollbackTransaction(promise: Promise) {
try {
@@ -336,6 +436,11 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Set the auto-lock timeout.
+ * @param timeout The timeout in seconds
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun setAutoLockTimeout(timeout: Double, promise: Promise?) {
try {
@@ -347,6 +452,10 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Get the auto-lock timeout.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun getAutoLockTimeout(promise: Promise) {
try {
@@ -358,6 +467,10 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Get the auth methods.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun getAuthMethods(promise: Promise) {
try {
@@ -376,6 +489,10 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Open the autofill settings page.
+ * @param promise The promise to resolve
+ */
@ReactMethod
override fun openAutofillSettingsPage(promise: Promise) {
try {
@@ -405,4 +522,12 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
)
}
}
+
+ /**
+ * Get the current fragment activity.
+ * @return The fragment activity
+ */
+ private fun getFragmentActivity(): FragmentActivity? {
+ return currentActivity as? FragmentActivity
+ }
}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManagerPackage.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManagerPackage.kt
index 0ec05dacb..e59768495 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManagerPackage.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManagerPackage.kt
@@ -7,7 +7,13 @@ import com.facebook.react.module.model.ReactModuleInfo
import com.facebook.react.module.model.ReactModuleInfoProvider
import java.util.HashMap
+/**
+ * The package for the NativeVaultManager module.
+ */
class NativeVaultManagerPackage : TurboReactPackage() {
+ /**
+ * Get the module for the given name.
+ */
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
return when (name) {
NativeVaultManager.NAME -> NativeVaultManager(reactContext)
@@ -15,6 +21,10 @@ class NativeVaultManagerPackage : TurboReactPackage() {
}
}
+ /**
+ * Get the React module info provider.
+ * @return The React module info provider
+ */
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
return ReactModuleInfoProvider {
val moduleMap: MutableMap<String, ReactModuleInfo> = HashMap()
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
index f5b8d46de..89bc8cd96 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
@@ -6,6 +6,8 @@ import android.os.Handler
import android.os.Looper
import android.util.Base64
import android.util.Log
+import net.aliasvault.app.vaultstore.interfaces.CredentialOperationCallback
+import net.aliasvault.app.vaultstore.interfaces.CryptoOperationCallback
import net.aliasvault.app.vaultstore.keystoreprovider.KeystoreOperationCallback
import net.aliasvault.app.vaultstore.keystoreprovider.KeystoreProvider
import net.aliasvault.app.vaultstore.models.Alias
@@ -24,42 +26,141 @@ import javax.crypto.Cipher
import javax.crypto.spec.GCMParameterSpec
import javax.crypto.spec.SecretKeySpec
+/**
+ * The vault store that manages the encrypted vault and all input/output operations on it.
+ * This class is used both by React Native and by the native Android autofill service.
+ *
+ * @param storageProvider The storage provider
+ * @param keystoreProvider The keystore provider
+ */
class VaultStore(
private val storageProvider: StorageProvider,
private val keystoreProvider: KeystoreProvider,
) {
- private val TAG = "VaultStore"
- private val BIOMETRICS_AUTH_METHOD = "faceid"
+ companion object {
+ /**
+ * The tag for logging.
+ */
+ private const val TAG = "VaultStore"
+
+ /**
+ * The biometrics auth method.
+ */
+ private const val BIOMETRICS_AUTH_METHOD = "faceid"
+
+ /**
+ * Minimum date definition.
+ */
+ private val MIN_DATE: Date = Calendar.getInstance(TimeZone.getTimeZone("UTC")).apply {
+ set(Calendar.YEAR, 1)
+ set(Calendar.MONTH, Calendar.JANUARY)
+ set(Calendar.DAY_OF_MONTH, 1)
+ set(Calendar.HOUR_OF_DAY, 0)
+ set(Calendar.MINUTE, 0)
+ set(Calendar.SECOND, 0)
+ set(Calendar.MILLISECOND, 0)
+ }.time
+
+ /**
+ * The instance of the vault store.
+ */
+ @Volatile
+ private var instance: VaultStore? = null
+
+ /**
+ * Get the instance of the vault store.
+ * @param keystoreProvider The keystore provider
+ * @param storageProvider The storage provider
+ * @return The instance of the vault store
+ */
+ @JvmStatic
+ fun getInstance(
+ keystoreProvider: KeystoreProvider,
+ storageProvider: StorageProvider,
+ ): VaultStore {
+ return instance ?: synchronized(this) {
+ instance ?: VaultStore(storageProvider, keystoreProvider).also { instance = it }
+ }
+ }
+
+ /**
+ * Get the existing instance of the vault store.
+ * @return The existing instance of the vault store
+ */
+ @JvmStatic
+ fun getExistingInstance(): VaultStore? {
+ return instance
+ }
+ }
+ /**
+ * The encryption key.
+ */
private var encryptionKey: ByteArray? = null
+
+ /**
+ * The database connection.
+ */
private var dbConnection: SQLiteDatabase? = null
- private var lastUnlockTime: Long = 0
+
+ /**
+ * The auto-lock handler.
+ */
private var autoLockHandler: Handler? = null
+
+ /**
+ * The auto-lock runnable.
+ */
private var autoLockRunnable: Runnable? = null
+ /**
+ * The last unlock time.
+ */
+ private var lastUnlockTime: Long = 0
+
init {
- // Initialize the handler on the main thread
+ // Initialize the auto-lock handler on the main thread
autoLockHandler = Handler(Looper.getMainLooper())
}
- // Interface for operations that need callbacks
- interface CryptoOperationCallback {
- fun onSuccess(result: String)
- fun onError(e: Exception)
+ /**
+ * Called when the app enters the background.
+ */
+ fun onAppBackgrounded() {
+ Log.d(TAG, "App entered background, starting auto-lock timer with ${getAutoLockTimeout()}s")
+ if (getAutoLockTimeout() > 0) {
+ // Cancel any existing auto-lock timer
+ autoLockRunnable?.let { autoLockHandler?.removeCallbacks(it) }
+
+ // Create and schedule new auto-lock timer
+ autoLockRunnable = Runnable {
+ Log.d(TAG, "Auto-lock timer fired, clearing cache")
+ clearCache()
+ }
+ autoLockHandler?.postDelayed(autoLockRunnable!!, getAutoLockTimeout().toLong() * 1000)
+ }
}
- interface CredentialOperationCallback {
- fun onSuccess(result: List<Credential>)
- fun onError(e: Exception)
+ /**
+ * Called when the app enters the foreground.
+ */
+ fun onAppForegrounded() {
+ Log.d(TAG, "App entered foreground, canceling auto-lock timer")
+ // Cancel the auto-lock timer
+ autoLockRunnable?.let { autoLockHandler?.removeCallbacks(it) }
+ autoLockRunnable = null
}
+ /**
+ * Store the encryption key.
+ * @param base64EncryptionKey The encryption key as a base64 encoded string
+ */
fun storeEncryptionKey(base64EncryptionKey: String) {
this.encryptionKey = Base64.decode(base64EncryptionKey, Base64.NO_WRAP)
// Check if biometric auth is enabled in auth methods
val authMethods = getAuthMethods()
if (authMethods.contains(BIOMETRICS_AUTH_METHOD) && keystoreProvider.isBiometricAvailable()) {
- // Create a latch to wait for the callback
val latch = java.util.concurrent.CountDownLatch(1)
var error: Exception? = null
@@ -79,14 +180,15 @@ class VaultStore(
},
)
- // Wait for the callback to complete
latch.await()
-
- // Throw any error that occurred
error?.let { throw it }
}
}
+ /**
+ * Get the encryption key.
+ * @param callback The callback to call when the key is retrieved
+ */
fun getEncryptionKey(callback: CryptoOperationCallback) {
// If key is already in memory, use it
encryptionKey?.let {
@@ -122,22 +224,34 @@ class VaultStore(
}
}
+ /**
+ * Store the encryption key derivation parameters.
+ * @param keyDerivationParams The encryption key derivation parameters
+ */
fun storeEncryptionKeyDerivationParams(keyDerivationParams: String) {
this.storageProvider.setKeyDerivationParams(keyDerivationParams)
}
+ /**
+ * Get the encryption key derivation parameters.
+ * @return The encryption key derivation parameters
+ */
fun getEncryptionKeyDerivationParams(): String {
return this.storageProvider.getKeyDerivationParams()
}
+ /**
+ * Store the encrypted database in the storage provider.
+ * @param encryptedData The encrypted database as a base64 encoded string
+ */
fun storeEncryptedDatabase(encryptedData: String) {
// Write the encrypted blob to the filesystem via the supplied file provider
- // which can either be the real Android file system or a fake file system for testing
+ // which can either be the real Android file system or a mock file system for testing
storageProvider.setEncryptedDatabaseFile(encryptedData)
}
/**
- * Get the encrypted database from the storage provider
+ * Get the encrypted database from the storage provider.
* @return The encrypted database as a base64 encoded string
*/
fun getEncryptedDatabase(): String {
@@ -146,7 +260,7 @@ class VaultStore(
}
/**
- * Check if the encrypted database exists in the storage provider
+ * Check if the encrypted database exists in the storage provider.
* @return True if the encrypted database exists, false otherwise
*/
fun hasEncryptedDatabase(): Boolean {
@@ -154,7 +268,7 @@ class VaultStore(
}
/**
- * Store the metadata in the storage provider
+ * Store the metadata in the storage provider.
* @param metadata The metadata to store
*/
fun storeMetadata(metadata: String) {
@@ -162,13 +276,16 @@ class VaultStore(
}
/**
- * Get the metadata from the storage provider
+ * Get the metadata from the storage provider.
* @return The metadata as a string
*/
fun getMetadata(): String {
return storageProvider.getMetadata()
}
+ /**
+ * Unlock the vault. This can trigger biometric authentication.
+ */
fun unlockVault() {
val encryptedDbBase64 = getEncryptedDatabase()
val decryptedDbBase64 = decryptData(encryptedDbBase64)
@@ -181,6 +298,13 @@ class VaultStore(
}
}
+ /**
+ * Execute a read-only SQL query (SELECT) on the vault.
+ * @param query The SQL query
+ * @param params The parameters to the query
+ * @return The results of the query
+ */
+ @Suppress("NestedBlockDepth")
fun executeQuery(query: String, params: Array<Any?>): List<Map<String, Any?>> {
val results = mutableListOf<Map<String, Any?>>()
@@ -226,6 +350,12 @@ class VaultStore(
return results
}
+ /**
+ * Execute an SQL update on the vault that mutates it.
+ * @param query The SQL query
+ * @param params The parameters to the query
+ * @return The number of affected rows
+ */
fun executeUpdate(query: String, params: Array<Any?>): Int {
dbConnection?.let { db ->
// Convert any base64 strings with the special flag to blobs
@@ -250,10 +380,16 @@ class VaultStore(
return 0
}
+ /**
+ * Begin a SQL transaction on the vault.
+ */
fun beginTransaction() {
dbConnection?.beginTransaction()
}
+ /**
+ * Commit a SQL transaction on the vault. This also persists the new version of the encrypted vault from memory to the filesystem.
+ */
fun commitTransaction() {
dbConnection?.setTransactionSuccessful()
dbConnection?.endTransaction()
@@ -288,9 +424,6 @@ class VaultStore(
// Commit the copy transaction
dbConnection?.setTransactionSuccessful()
- } catch (e: Exception) {
- // If anything fails, rollback the transaction
- throw e
} finally {
dbConnection?.endTransaction()
}
@@ -316,10 +449,17 @@ class VaultStore(
}
}
+ /**
+ * Rollback a SQL transaction on the vault.
+ */
fun rollbackTransaction() {
dbConnection?.endTransaction()
}
+ /**
+ * Check if the vault is unlocked.
+ * @return True if the vault is unlocked, false otherwise
+ */
fun isVaultUnlocked(): Boolean {
if (encryptionKey == null) {
return false
@@ -328,14 +468,26 @@ class VaultStore(
return true
}
+ /**
+ * Set the auto-lock timeout.
+ * @param timeout The timeout in seconds
+ */
fun setAutoLockTimeout(timeout: Int) {
storageProvider.setAutoLockTimeout(timeout)
}
+ /**
+ * Get the auto-lock timeout.
+ * @return The timeout in seconds
+ */
fun getAutoLockTimeout(): Int {
return storageProvider.getAutoLockTimeout()
}
+ /**
+ * Set the auth methods.
+ * @param authMethods The auth methods
+ */
fun setAuthMethods(authMethods: String) {
storageProvider.setAuthMethods(authMethods)
@@ -345,10 +497,18 @@ class VaultStore(
}
}
+ /**
+ * Get the auth methods.
+ * @return The auth methods
+ */
fun getAuthMethods(): String {
return storageProvider.getAuthMethods()
}
+ /**
+ * Set the vault revision number.
+ * @param revisionNumber The revision number
+ */
fun setVaultRevisionNumber(revisionNumber: Int) {
val metadata = getVaultMetadataObject() ?: VaultMetadata()
val updatedMetadata = metadata.copy(vaultRevisionNumber = revisionNumber)
@@ -361,10 +521,18 @@ class VaultStore(
)
}
+ /**
+ * Get the vault revision number.
+ * @return The revision number
+ */
fun getVaultRevisionNumber(): Int {
return getVaultMetadataObject()?.vaultRevisionNumber ?: 0
}
+ /**
+ * Get the vault metadata object.
+ * @return The vault metadata object
+ */
private fun getVaultMetadataObject(): VaultMetadata? {
val metadataJson = getMetadata()
if (metadataJson.isBlank()) {
@@ -388,7 +556,7 @@ class VaultStore(
}
/**
- * Clear the memory - remove the encryption key and decrypted database from memory
+ * Clear the memory, removing the encryption key and decrypted database from memory.
*/
fun clearCache() {
Log.d(TAG, "Clearing cache - removing encryption key and decrypted database from memory")
@@ -397,6 +565,9 @@ class VaultStore(
dbConnection = null
}
+ /**
+ * Clear all vault data including from persisted storage. This removes all data from the local device.
+ */
fun clearVault() {
// Remove cached data from memory
clearCache()
@@ -437,6 +608,11 @@ class VaultStore(
}
}
+ /**
+ * Decrypt data.
+ * @param encryptedData The encrypted data
+ * @return The decrypted data
+ */
private fun decryptData(encryptedData: String): String {
var decryptedResult: String? = null
var error: Exception? = null
@@ -487,114 +663,13 @@ class VaultStore(
return decryptedResult ?: error("Decryption failed")
}
- private fun encryptData(data: String): String {
- try {
- // Generate random IV
- val iv = ByteArray(12)
- SecureRandom().nextBytes(iv)
-
- // Create cipher
- val cipher = Cipher.getInstance("AES/GCM/NoPadding")
- val keySpec = SecretKeySpec(encryptionKey!!, "AES")
- val gcmSpec = GCMParameterSpec(128, iv)
-
- // Initialize cipher for encryption
- cipher.init(Cipher.ENCRYPT_MODE, keySpec, gcmSpec)
-
- // Encrypt
- val encrypted = cipher.doFinal(data.toByteArray(Charsets.UTF_8))
-
- // Combine IV and encrypted content
- val result = ByteArray(iv.size + encrypted.size)
- System.arraycopy(iv, 0, result, 0, iv.size)
- System.arraycopy(encrypted, 0, result, iv.size, encrypted.size)
-
- return Base64.encodeToString(result, Base64.NO_WRAP)
- } catch (e: Exception) {
- Log.e(TAG, "Error encrypting data", e)
- throw e
- }
- }
-
- private fun setupDatabaseWithDecryptedData(decryptedDbBase64: String) {
- var tempDbFile: File? = null
- try {
- // Decode the base64 data
- val decryptedDbData = Base64.decode(decryptedDbBase64, Base64.NO_WRAP)
-
- // Create a temporary file to store the decrypted database
- tempDbFile = File.createTempFile("temp_db", ".sqlite")
- tempDbFile.writeBytes(decryptedDbData)
-
- // Close any existing connection if it exists
- dbConnection?.close()
-
- // Create an in-memory database
- dbConnection = SQLiteDatabase.create(null)
-
- // Begin transaction
- dbConnection?.beginTransaction()
-
- try {
- // Attach the temporary database
- val attachQuery = "ATTACH DATABASE '${tempDbFile.path}' AS source"
- dbConnection?.execSQL(attachQuery)
-
- // Verify the attachment worked by checking if we can access the source database
- val verifyCursor = dbConnection?.rawQuery(
- "SELECT name FROM source.sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'",
- null,
- )
-
- if (verifyCursor == null) {
- throw SQLiteException("Failed to attach source database")
- }
-
- verifyCursor.use {
- if (!it.moveToFirst()) {
- throw SQLiteException("No tables found in source database")
- }
-
- do {
- val tableName = it.getString(0)
- // Create table and copy data using rawQuery
- dbConnection?.execSQL(
- "CREATE TABLE $tableName AS SELECT * FROM source.$tableName",
- )
- } while (it.moveToNext())
- }
-
- // Commit transaction
- dbConnection?.setTransactionSuccessful()
- } finally {
- dbConnection?.endTransaction()
- }
-
- // Detach the source database
- dbConnection?.rawQuery("DETACH DATABASE source", null)
-
- // Set database pragmas using rawQuery
- dbConnection?.rawQuery("PRAGMA journal_mode = WAL", null)
- dbConnection?.rawQuery("PRAGMA synchronous = NORMAL", null)
- dbConnection?.rawQuery("PRAGMA foreign_keys = ON", null)
-
- lastUnlockTime = System.currentTimeMillis()
- } catch (e: Exception) {
- Log.e(TAG, "Error setting up database with decrypted data", e)
- throw e
- } finally {
- // Clean up temporary file
- tempDbFile?.delete()
- }
- }
-
/**
* Get all credentials from the vault.
* @return The list of credentials
*/
fun getAllCredentials(): List<Credential> {
if (dbConnection == null) {
- throw IllegalStateException("Database not initialized")
+ error("Database not initialized")
}
Log.d(TAG, "Executing get all credentials query..")
@@ -724,7 +799,117 @@ class VaultStore(
}
/**
- * Parse a date string from the database into a Date object
+ * Encrypt data.
+ * @param data The data to encrypt
+ * @return The encrypted data
+ */
+ private fun encryptData(data: String): String {
+ try {
+ // Generate random IV
+ val iv = ByteArray(12)
+ SecureRandom().nextBytes(iv)
+
+ // Create cipher
+ val cipher = Cipher.getInstance("AES/GCM/NoPadding")
+ val keySpec = SecretKeySpec(encryptionKey!!, "AES")
+ val gcmSpec = GCMParameterSpec(128, iv)
+
+ // Initialize cipher for encryption
+ cipher.init(Cipher.ENCRYPT_MODE, keySpec, gcmSpec)
+
+ // Encrypt
+ val encrypted = cipher.doFinal(data.toByteArray(Charsets.UTF_8))
+
+ // Combine IV and encrypted content
+ val result = ByteArray(iv.size + encrypted.size)
+ System.arraycopy(iv, 0, result, 0, iv.size)
+ System.arraycopy(encrypted, 0, result, iv.size, encrypted.size)
+
+ return Base64.encodeToString(result, Base64.NO_WRAP)
+ } catch (e: Exception) {
+ Log.e(TAG, "Error encrypting data", e)
+ throw e
+ }
+ }
+
+ /**
+ * Setup the database with decrypted data. This initializes the decrypted database in memory.
+ * @param decryptedDbBase64 The decrypted database as a base64 encoded string
+ */
+ private fun setupDatabaseWithDecryptedData(decryptedDbBase64: String) {
+ var tempDbFile: File? = null
+ try {
+ // Decode the base64 data
+ val decryptedDbData = Base64.decode(decryptedDbBase64, Base64.NO_WRAP)
+
+ // Create a temporary file to store the decrypted database
+ tempDbFile = File.createTempFile("temp_db", ".sqlite")
+ tempDbFile.writeBytes(decryptedDbData)
+
+ // Close any existing connection if it exists
+ dbConnection?.close()
+
+ // Create an in-memory database
+ dbConnection = SQLiteDatabase.create(null)
+
+ // Begin transaction
+ dbConnection?.beginTransaction()
+
+ try {
+ // Attach the temporary database
+ val attachQuery = "ATTACH DATABASE '${tempDbFile.path}' AS source"
+ dbConnection?.execSQL(attachQuery)
+
+ // Verify the attachment worked by checking if we can access the source database
+ val verifyCursor = dbConnection?.rawQuery(
+ "SELECT name FROM source.sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'",
+ null,
+ )
+
+ if (verifyCursor == null) {
+ throw SQLiteException("Failed to attach source database")
+ }
+
+ verifyCursor.use {
+ if (!it.moveToFirst()) {
+ throw SQLiteException("No tables found in source database")
+ }
+
+ do {
+ val tableName = it.getString(0)
+ // Create table and copy data using rawQuery
+ dbConnection?.execSQL(
+ "CREATE TABLE $tableName AS SELECT * FROM source.$tableName",
+ )
+ } while (it.moveToNext())
+ }
+
+ // Commit transaction
+ dbConnection?.setTransactionSuccessful()
+ } finally {
+ dbConnection?.endTransaction()
+ }
+
+ // Detach the source database
+ dbConnection?.rawQuery("DETACH DATABASE source", null)
+
+ // Set database pragmas using rawQuery
+ dbConnection?.rawQuery("PRAGMA journal_mode = WAL", null)
+ dbConnection?.rawQuery("PRAGMA synchronous = NORMAL", null)
+ dbConnection?.rawQuery("PRAGMA foreign_keys = ON", null)
+
+ lastUnlockTime = System.currentTimeMillis()
+ } catch (e: Exception) {
+ Log.e(TAG, "Error setting up database with decrypted data", e)
+ throw e
+ } finally {
+ // Clean up temporary file
+ tempDbFile?.delete()
+ }
+ }
+
+ /**
+ * Parse a date string from the database into a Date object.
*
* @param dateString The date string to parse
* @return The parsed Date object or null if the date string is null or cannot be parsed
@@ -747,7 +932,8 @@ class VaultStore(
try {
return format.parse(dateString)
} catch (e: Exception) {
- // Continue to next format if this one fails
+ // Log the parsing error for this format
+ Log.d(TAG, "Failed to parse date '$dateString' with format '${format.toPattern()}': ${e.message}")
continue
}
}
@@ -755,62 +941,4 @@ class VaultStore(
Log.e(TAG, "Error parsing date: $dateString")
return null
}
-
- /**
- * Called when the app enters the background.
- */
- fun onAppBackgrounded() {
- Log.d(TAG, "App entered background, starting auto-lock timer with ${getAutoLockTimeout()}s")
- if (getAutoLockTimeout() > 0) {
- // Cancel any existing auto-lock timer
- autoLockRunnable?.let { autoLockHandler?.removeCallbacks(it) }
-
- // Create and schedule new auto-lock timer
- autoLockRunnable = Runnable {
- Log.d(TAG, "Auto-lock timer fired, clearing cache")
- clearCache()
- }
- autoLockHandler?.postDelayed(autoLockRunnable!!, getAutoLockTimeout().toLong() * 1000)
- }
- }
-
- /**
- * Called when the app enters the foreground.
- */
- fun onAppForegrounded() {
- Log.d(TAG, "App entered foreground, canceling auto-lock timer")
- // Cancel the auto-lock timer
- autoLockRunnable?.let { autoLockHandler?.removeCallbacks(it) }
- autoLockRunnable = null
- }
-
- companion object {
- private val MIN_DATE: Date = Calendar.getInstance(TimeZone.getTimeZone("UTC")).apply {
- set(Calendar.YEAR, 1)
- set(Calendar.MONTH, Calendar.JANUARY)
- set(Calendar.DAY_OF_MONTH, 1)
- set(Calendar.HOUR_OF_DAY, 0)
- set(Calendar.MINUTE, 0)
- set(Calendar.SECOND, 0)
- set(Calendar.MILLISECOND, 0)
- }.time
-
- @Volatile
- private var instance: VaultStore? = null
-
- @JvmStatic
- fun getInstance(
- keystoreProvider: KeystoreProvider,
- storageProvider: StorageProvider,
- ): VaultStore {
- return instance ?: synchronized(this) {
- instance ?: VaultStore(storageProvider, keystoreProvider).also { instance = it }
- }
- }
-
- @JvmStatic
- fun getExistingInstance(): VaultStore? {
- return instance
- }
- }
}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/interfaces/CredentialOperationCallback.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/interfaces/CredentialOperationCallback.kt
new file mode 100644
index 000000000..5a00b8e46
--- /dev/null
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/interfaces/CredentialOperationCallback.kt
@@ -0,0 +1,20 @@
+package net.aliasvault.app.vaultstore.interfaces
+
+import net.aliasvault.app.vaultstore.models.Credential
+
+/**
+ * Interface for operations that need callbacks for credentials.
+ */
+interface CredentialOperationCallback {
+ /**
+ * Called when the operation is successful.
+ * @param result The result of the operation
+ */
+ fun onSuccess(result: List<Credential>)
+
+ /**
+ * Called when the operation fails.
+ * @param e The exception that occurred
+ */
+ fun onError(e: Exception)
+}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/interfaces/CryptoOperationCallback.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/interfaces/CryptoOperationCallback.kt
new file mode 100644
index 000000000..bb6a344d0
--- /dev/null
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/interfaces/CryptoOperationCallback.kt
@@ -0,0 +1,18 @@
+package net.aliasvault.app.vaultstore.interfaces
+
+/**
+ * Interface for operations that need callbacks.
+ */
+interface CryptoOperationCallback {
+ /**
+ * Called when the operation is successful.
+ * @param result The result of the operation
+ */
+ fun onSuccess(result: String)
+
+ /**
+ * Called when the operation fails.
+ * @param e The exception that occurred
+ */
+ fun onError(e: Exception)
+}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/AndroidKeystoreProvider.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/AndroidKeystoreProvider.kt
index 9fa6e1da1..c177eaaa8 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/AndroidKeystoreProvider.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/AndroidKeystoreProvider.kt
@@ -27,24 +27,62 @@ class AndroidKeystoreProvider(
private val context: Context,
private val getCurrentActivity: () -> Activity?,
) : KeystoreProvider {
- private val biometricManager = BiometricManager.from(context)
- private val executor: Executor = Executors.newSingleThreadExecutor()
- private val mainHandler = Handler(Looper.getMainLooper())
- private val TAG = "AndroidKeystoreProvider"
- private val KEYSTORE_ALIAS = "aliasvault_biometric_key"
- private val ENCRYPTED_KEY_PREF = "encrypted_vault_key"
- private val SHARED_PREFS_NAME = "net.aliasvault.keystore"
+ companion object {
+ /**
+ * The tag for logging.
+ */
+ private const val TAG = "AndroidKeystoreProvider"
+
+ /**
+ * The alias for the keystore.
+ */
+ private const val KEYSTORE_ALIAS = "alias_vault_key"
+
+ /**
+ * The tag for logging.
+ */
+ private const val ENCRYPTED_KEY_PREF = "encrypted_vault_key"
+
+ /**
+ * The shared preferences name.
+ */
+ private const val SHARED_PREFS_NAME = "net.aliasvault.keystore"
+ }
+ /**
+ * The biometric manager.
+ */
+ private val _biometricManager = BiometricManager.from(context)
+
+ /**
+ * The executor.
+ */
+ private val _executor: Executor = Executors.newSingleThreadExecutor()
+
+ /**
+ * The main handler.
+ */
+ private val _mainHandler = Handler(Looper.getMainLooper())
+
+ /**
+ * Whether the biometric is available.
+ * @return Whether the biometric is available
+ */
override fun isBiometricAvailable(): Boolean {
- return biometricManager.canAuthenticate(
+ return _biometricManager.canAuthenticate(
BiometricManager.Authenticators.BIOMETRIC_WEAK or
BiometricManager.Authenticators.BIOMETRIC_STRONG or
BiometricManager.Authenticators.DEVICE_CREDENTIAL,
) == BiometricManager.BIOMETRIC_SUCCESS
}
+ /**
+ * Store the key in the keystore.
+ * @param key The key to store
+ * @param callback The callback to call when the operation is complete
+ */
override fun storeKey(key: String, callback: KeystoreOperationCallback) {
- mainHandler.post {
+ _mainHandler.post {
try {
val currentActivity = getCurrentActivity()
if (currentActivity == null || !(currentActivity is FragmentActivity)) {
@@ -95,7 +133,7 @@ class AndroidKeystoreProvider(
val biometricPrompt = BiometricPrompt(
currentActivity,
- executor,
+ _executor,
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationSucceeded(
result: BiometricPrompt.AuthenticationResult,
@@ -168,7 +206,7 @@ class AndroidKeystoreProvider(
}
override fun retrieveKey(callback: KeystoreOperationCallback) {
- mainHandler.post {
+ _mainHandler.post {
try {
val currentActivity = getCurrentActivity()
if (currentActivity == null || !(currentActivity is FragmentActivity)) {
@@ -213,16 +251,14 @@ class AndroidKeystoreProvider(
val biometricPrompt = BiometricPrompt(
currentActivity,
- executor,
+ _executor,
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationSucceeded(
result: BiometricPrompt.AuthenticationResult,
) {
try {
// Get the cipher from the result
- val cipher = result.cryptoObject?.cipher ?: throw Exception(
- "Cipher is null",
- )
+ val cipher = result.cryptoObject?.cipher ?: error("Cipher is null")
// Decode combined data
val combined = Base64.decode(encryptedKeyB64, Base64.NO_WRAP)
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/KeystoreProvider.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/KeystoreProvider.kt
index 67bd9eb5a..2ec87126a 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/KeystoreProvider.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/KeystoreProvider.kt
@@ -6,13 +6,13 @@ package net.aliasvault.app.vaultstore.keystoreprovider
*/
interface KeystoreProvider {
/**
- * Check if biometric authentication is available on the device
+ * Check if biometric authentication is available on the device.
* @return true if biometric authentication is available, false otherwise
*/
fun isBiometricAvailable(): Boolean
/**
- * Store an encryption key with biometric protection
+ * Store an encryption key with biometric protection.
* @param activity The activity to show the biometric prompt on
* @param key The encryption key to store
* @param callback The callback to handle the result
@@ -20,22 +20,31 @@ interface KeystoreProvider {
fun storeKey(key: String, callback: KeystoreOperationCallback)
/**
- * Retrieve an encryption key using biometric authentication
+ * Retrieve an encryption key using biometric authentication.
* @param activity The activity to show the biometric prompt on
* @param callback The callback to handle the result
*/
fun retrieveKey(callback: KeystoreOperationCallback)
/**
- * Clear all stored keys
+ * Clear all stored keys.
*/
fun clearKeys()
}
/**
- * Callback interface for keystore operations
+ * Callback interface for keystore operations.
*/
interface KeystoreOperationCallback {
+ /**
+ * Called when the operation is successful.
+ * @param result The result of the operation
+ */
fun onSuccess(result: String)
+
+ /**
+ * Called when the operation fails.
+ * @param e The exception that occurred
+ */
fun onError(e: Exception)
}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/Credential.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/Credential.kt
index 3e9e236f6..3ce0c011e 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/Credential.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/Credential.kt
@@ -3,25 +3,93 @@ package net.aliasvault.app.vaultstore.models
import java.util.Date
import java.util.UUID
+/**
+ * Credential object.
+ */
data class Credential(
+ /**
+ * The ID of the credential.
+ */
val id: UUID,
+
+ /**
+ * The alias of the credential.
+ */
val alias: Alias?,
+
+ /**
+ * The service of the credential.
+ */
val service: Service,
+
+ /**
+ * The username of the credential.
+ */
val username: String?,
+
+ /**
+ * The notes of the credential.
+ */
val notes: String?,
+
+ /**
+ * The password of the credential.
+ */
val password: Password?,
+
+ /**
+ * The creation date of the credential.
+ */
val createdAt: Date,
+
+ /**
+ * The update date of the credential.
+ */
val updatedAt: Date,
+
+ /**
+ * Whether the credential is deleted.
+ */
val isDeleted: Boolean,
)
+/**
+ * Service object.
+ */
data class Service(
+ /**
+ * The ID of the service.
+ */
val id: UUID,
+
+ /**
+ * The name of the service.
+ */
val name: String?,
+
+ /**
+ * The URL of the service.
+ */
val url: String?,
+
+ /**
+ * The logo of the service.
+ */
val logo: ByteArray?,
+
+ /**
+ * The creation date of the service.
+ */
val createdAt: Date,
+
+ /**
+ * The update date of the service.
+ */
val updatedAt: Date,
+
+ /**
+ * Whether the service is deleted.
+ */
val isDeleted: Boolean,
) {
override fun equals(other: Any?): Boolean {
@@ -53,25 +121,93 @@ data class Service(
}
}
+/**
+ * Password object.
+ */
data class Password(
+ /**
+ * The ID of the password.
+ */
val id: UUID,
+
+ /**
+ * The credential ID of the password.
+ */
val credentialId: UUID,
+
+ /**
+ * The value of the password.
+ */
val value: String,
+
+ /**
+ * The creation date of the password.
+ */
val createdAt: Date,
+
+ /**
+ * The update date of the password.
+ */
val updatedAt: Date,
+
+ /**
+ * Whether the password is deleted.
+ */
val isDeleted: Boolean,
)
+/**
+ * Alias object.
+ */
data class Alias(
+ /**
+ * The ID of the alias.
+ */
val id: UUID,
+
+ /**
+ * The gender of the alias.
+ */
val gender: String?,
+
+ /**
+ * The first name of the alias.
+ */
val firstName: String?,
+
+ /**
+ * The last name of the alias.
+ */
val lastName: String?,
+
+ /**
+ * The nick name of the alias.
+ */
val nickName: String?,
+
+ /**
+ * The birth date of the alias.
+ */
val birthDate: Date,
+
+ /**
+ * The email of the alias.
+ */
val email: String?,
+
+ /**
+ * The creation date of the alias.
+ */
val createdAt: Date,
+
+ /**
+ * The update date of the alias.
+ */
val updatedAt: Date,
+
+ /**
+ * Whether the alias is deleted.
+ */
val isDeleted: Boolean,
) {
override fun equals(other: Any?): Boolean {
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/VaultMetadata.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/VaultMetadata.kt
index 4fb5b5c53..dc5a89759 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/VaultMetadata.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/VaultMetadata.kt
@@ -1,7 +1,21 @@
package net.aliasvault.app.vaultstore.models
+/**
+ * Vault metadata object.
+ */
data class VaultMetadata(
+ /**
+ * The public email domains of the vault.
+ */
val publicEmailDomains: List<String> = emptyList(),
+
+ /**
+ * The private email domains of the vault.
+ */
val privateEmailDomains: List<String> = emptyList(),
+
+ /**
+ * The revision number of the vault.
+ */
val vaultRevisionNumber: Int = 0,
)
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/storageprovider/StorageProvider.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/storageprovider/StorageProvider.kt
index af0f8eacc..41b5f40d1 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/storageprovider/StorageProvider.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/storageprovider/StorageProvider.kt
@@ -8,31 +8,31 @@ import java.io.File
*/
interface StorageProvider {
/**
- * Get the encrypted database file
+ * Get the encrypted database file.
* @return The encrypted database file
*/
fun getEncryptedDatabaseFile(): File
/**
- * Set the encrypted database file
+ * Set the encrypted database file.
* @param encryptedData The encrypted database data as a base64 encoded string
*/
fun setEncryptedDatabaseFile(encryptedData: String)
/**
- * Get the key derivation parameters
+ * Get the key derivation parameters.
* @return The key derivation parameters as a string
*/
fun getKeyDerivationParams(): String
/**
- * Set the key derivation parameters
+ * Set the key derivation parameters.
* @param keyDerivationParams The key derivation parameters as a string
*/
fun setKeyDerivationParams(keyDerivationParams: String)
/**
- * Get the metadata
+ * Get the metadata.
* @return The metadata as a string
*/
fun getMetadata(): String
@@ -44,31 +44,31 @@ interface StorageProvider {
fun setMetadata(metadata: String)
/**
- * Get the auto-lock timeout
+ * Get the auto-lock timeout.
* @return The auto-lock timeout in seconds
*/
fun getAutoLockTimeout(): Int
/**
- * Set the auto-lock timeout
+ * Set the auto-lock timeout.
* @param timeout The auto-lock timeout in seconds
*/
fun setAutoLockTimeout(timeout: Int)
/**
- * Get the authentication methods
+ * Get the authentication methods.
* @return The authentication methods as a string
*/
fun getAuthMethods(): String
/**
- * Set the authentication methods
+ * Set the authentication methods.
* @param authMethods The authentication methods as a string
*/
fun setAuthMethods(authMethods: String)
/**
- * Clear all data from the storage provider
+ * Clear all data from the storage provider.
*/
fun clearStorage()
}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/storageprovider/TestStorageProvider.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/storageprovider/TestStorageProvider.kt
index 07e136b85..e2fa891e5 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/storageprovider/TestStorageProvider.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/storageprovider/TestStorageProvider.kt
@@ -5,7 +5,7 @@ import java.io.File
/**
* A fake file provider that mocks the storage of the encrypted database file and metadata.
*/
-class TestStorageProvider() : StorageProvider {
+class TestStorageProvider : StorageProvider {
private var defaultAutoLockTimeout = 3600 // 1 hour default
private val tempFile = File.createTempFile("encrypted_database", ".db")
diff --git a/apps/mobile-app/android/app/src/main/res/values/colors.xml b/apps/mobile-app/android/app/src/main/res/values/colors.xml
index f387b9011..c0ed1675d 100644
--- a/apps/mobile-app/android/app/src/main/res/values/colors.xml
+++ b/apps/mobile-app/android/app/src/main/res/values/colors.xml
@@ -1,6 +1,4 @@
<resources>
<color name="splashscreen_background">#ffffff</color>
- <color name="iconBackground">#ffffff</color>
<color name="colorPrimary">#023c69</color>
- <color name="colorPrimaryDark">#ffffff</color>
</resources>
\ No newline at end of file
diff --git a/apps/mobile-app/android/build.gradle b/apps/mobile-app/android/build.gradle
index 755b32d4e..2e5072511 100644
--- a/apps/mobile-app/android/build.gradle
+++ b/apps/mobile-app/android/build.gradle
@@ -35,7 +35,7 @@ detekt {
baseline = file("$projectDir/baseline.xml")
}
-tasks.register('lintAll') {
+tasks.register('lintCheck') {
dependsOn 'ktlintCheck'
dependsOn 'detekt'
group = 'verification'
diff --git a/apps/mobile-app/android/detekt.yml b/apps/mobile-app/android/detekt.yml
index bec790fcb..87b447a8a 100644
--- a/apps/mobile-app/android/detekt.yml
+++ b/apps/mobile-app/android/detekt.yml
@@ -14,10 +14,22 @@ complexity:
constructorThreshold: 6
TooManyFunctions:
active: true
- thresholdInFiles: 11
- thresholdInClasses: 11
- thresholdInInterfaces: 11
- thresholdInObjects: 11
+ thresholdInFiles: 40
+ thresholdInClasses: 40
+ thresholdInInterfaces: 40
+ thresholdInObjects: 40
+ CyclomaticComplexMethod:
+ active: true
+ threshold: 26
+ NestedBlockDepth:
+ active: true
+ threshold: 5
+ LongMethod:
+ active: true
+ threshold: 120
+ ComplexCondition:
+ active: true
+ threshold: 6
comments:
UndocumentedPublicClass:
@@ -37,6 +49,11 @@ style:
ReturnCount:
active: true
max: 6
+ MagicNumber:
+ active: false
+ ThrowsCount:
+ active: true
+ max: 3
exceptions:
TooGenericExceptionCaught:
diff --git a/apps/mobile-app/package-lock.json b/apps/mobile-app/package-lock.json
index 9d268d8a5..3a734999f 100644
--- a/apps/mobile-app/package-lock.json
+++ b/apps/mobile-app/package-lock.json
@@ -24,7 +24,6 @@
"expo-linear-gradient": "~14.0.2",
"expo-linking": "~7.0.5",
"expo-local-authentication": "~15.0.2",
- "expo-modules-core": "~2.2.3",
"expo-router": "~4.0.20",
"expo-sharing": "~13.0.1",
"expo-splash-screen": "~0.29.24",
@@ -47,7 +46,7 @@
"react-native-quick-crypto": "^0.7.13",
"react-native-reanimated": "~3.16.1",
"react-native-safe-area-context": "4.12.0",
- "react-native-screens": "~4.4.0",
+ "react-native-screens": "~4.11.1",
"react-native-svg": "15.8.0",
"react-native-toast-message": "^2.2.1",
"react-native-web": "~0.19.13",
@@ -17988,12 +17987,13 @@
}
},
"node_modules/react-native-screens": {
- "version": "4.4.0",
- "resolved": "https://registry.npmjs.org/react-native-screens/-/react-native-screens-4.4.0.tgz",
- "integrity": "sha512-c7zc7Zwjty6/pGyuuvh9gK3YBYqHPOxrhXfG1lF4gHlojQSmIx2piNbNaV+Uykj+RDTmFXK0e/hA+fucw/Qozg==",
+ "version": "4.11.1",
+ "resolved": "https://registry.npmjs.org/react-native-screens/-/react-native-screens-4.11.1.tgz",
+ "integrity": "sha512-F0zOzRVa3ptZfLpD0J8ROdo+y1fEPw+VBFq1MTY/iyDu08al7qFUO5hLMd+EYMda5VXGaTFCa8q7bOppUszhJw==",
"license": "MIT",
"dependencies": {
"react-freeze": "^1.0.0",
+ "react-native-is-edge-to-edge": "^1.1.7",
"warn-once": "^0.1.0"
},
"peerDependencies": {
diff --git a/apps/mobile-app/package.json b/apps/mobile-app/package.json
index 66aa840a1..5af965813 100644
--- a/apps/mobile-app/package.json
+++ b/apps/mobile-app/package.json
@@ -66,7 +66,7 @@
"react-native-quick-crypto": "^0.7.13",
"react-native-reanimated": "~3.16.1",
"react-native-safe-area-context": "4.12.0",
- "react-native-screens": "~4.4.0",
+ "react-native-screens": "~4.11.1",
"react-native-svg": "15.8.0",
"react-native-toast-message": "^2.2.1",
"react-native-web": "~0.19.13",
diff --git a/docs/misc/dev/mobile-apps/android.md b/docs/misc/dev/mobile-apps/android.md
index 44aed1af7..d5d927086 100644
--- a/docs/misc/dev/mobile-apps/android.md
+++ b/docs/misc/dev/mobile-apps/android.md
@@ -50,11 +50,11 @@ Linting is ran automatically during normal Android app build. You can however al
### Kotlin
```bash
-./gradlew lintAll
+./gradlew lintCheck
```
### Auto fix linting issues
To automatically fix linting issues (where possible), run this command:
```bash
-./gradlew lintFixAll
-```
+./gradlew lintFormat
+```
\ No newline at end of file
diff --git a/docs/mobile-apps/android/build-from-source.md b/docs/mobile-apps/android/build-from-source.md
index 75dd6c6d4..aacb4cb52 100644
--- a/docs/mobile-apps/android/build-from-source.md
+++ b/docs/mobile-apps/android/build-from-source.md
@@ -6,21 +6,16 @@ grand_parent: Mobile Apps
nav_order: 1
---
-# Building AliasVault iOS App from Source
+# Building AliasVault Android App from Source
-This guide explains how to build and install the AliasVault iOS app from source code using React Native.
+This guide explains how to build and install the AliasVault Android app from source code using React Native.
## Prerequisites
-- macOS with Xcode installed (required for building iOS apps)
-- [Homebrew](https://brew.sh) installed
-- Node.js installed
-- CocoaPods installed (`brew install cocoapods`)
+- MacOS or Windows machine with Android Studio installed
- Git to clone the repository
-- Xcode Command Line Tools (`xcode-select --install`)
-- An Apple developer account for signing and installing on real devices (optional for simulator)
-## Building the iOS App
+## Building the Android app
1. Clone the repository:
```bash
@@ -37,19 +32,23 @@ cd AliasVault/apps/mobile-app
npm install
```
-4. Install iOS native dependencies via CocoaPods:
+4. Install and build Android dependencies:
```bash
-npx pod-install
+cd android
+./gradlew assembleRelease
```
-5. Open the iOS workspace in Xcode:
+5. Deploy release build to your device:
+
+For MacOS, install adb to deploy the app to a phone or simulator via command line:
```bash
-./apps/mobile-app/ios/AliasVault.xcworkspace
-```
+# Install adb
+brew install android-platform-tools
-6. In Xcode, select a simulator or a connected physical device.
+# List devices (physical devices connected via USB and any running simulators)
+adb devices
-7. Click Run (▶️) in Xcode to build and launch the app.
+# Deploy to chosen device
+adb -s [device-id] install android/app/build/outputs/apk/release/app-release.apk
+```
-## Notes
-- If you're running on a physical iPhone, you'll need to configure code signing with your Apple ID in Xcode under Signing & Capabilities.
\ No newline at end of file