Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ dependencies {
// Add a dependency on NitroModules
implementation project(":react-native-nitro-modules")

implementation "androidx.biometric:biometric:1.1.0"
implementation "androidx.biometric:biometric-ktx:1.4.0-alpha02"
}

if (isNewArchitectureEnabled()) {
Expand Down
48 changes: 37 additions & 11 deletions android/src/main/java/com/sensitiveinfo/HybridSensitiveInfo.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.sensitiveinfo

import androidx.annotation.Keep
import com.facebook.proguard.annotations.DoNotStrip

import android.content.Context
import com.margelo.nitro.core.Promise
import com.margelo.nitro.sensitiveinfo.*
Expand All @@ -24,6 +27,8 @@ import kotlin.jvm.Volatile
* This class provides secure storage for sensitive data on Android using the Android Keystore
* for key management and SharedPreferences for encrypted data persistence.
*/
@DoNotStrip
@Keep
class HybridSensitiveInfo : HybridSensitiveInfoSpec() {
private data class Dependencies(
val context: Context,
Expand Down Expand Up @@ -98,14 +103,33 @@ class HybridSensitiveInfo : HybridSensitiveInfoSpec() {
}
}

override fun getItem(request: SensitiveInfoGetRequest): Promise<SensitiveInfoItem?> {
override fun getItem(request: SensitiveInfoGetRequest): Promise<Variant_NullType_SensitiveInfoItem> {
return Promise.async(coroutineScope) {
val deps = ensureInitialized()
val service = deps.serviceNameResolver.resolve(request.service)

val entry = deps.storage.read(service, request.key)

if (entry == null) {
return@async null
try {
val ctor = com.margelo.nitro.core.NullType::class.java.getDeclaredConstructor()
ctor.isAccessible = true
val nullTypeInstance = ctor.newInstance()
return@async Variant_NullType_SensitiveInfoItem.create(nullTypeInstance)
} catch (e: Throwable) {
// Fallback: create a null-type via unsafe camino — return a Second with empty SensitiveInfoItem omitted
return@async Variant_NullType_SensitiveInfoItem.create(com.margelo.nitro.sensitiveinfo.SensitiveInfoItem(
key = request.key,
service = service,
value = null,
metadata = StorageMetadata(
securityLevel = SecurityLevel.SOFTWARE,
backend = StorageBackend.ANDROIDKEYSTORE,
accessControl = AccessControl.NONE,
timestamp = System.currentTimeMillis() / 1000.0
)
))
}
}

val metadata = entry.metadata.toStorageMetadata()
Expand All @@ -131,15 +155,17 @@ class HybridSensitiveInfo : HybridSensitiveInfoSpec() {
null
}

SensitiveInfoItem(
key = request.key,
service = service,
value = value,
metadata = metadata ?: StorageMetadata(
securityLevel = SecurityLevel.SOFTWARE,
backend = StorageBackend.ANDROIDKEYSTORE,
accessControl = AccessControl.NONE,
timestamp = System.currentTimeMillis() / 1000.0
Variant_NullType_SensitiveInfoItem.create(
SensitiveInfoItem(
key = request.key,
service = service,
value = value,
metadata = metadata ?: StorageMetadata(
securityLevel = SecurityLevel.SOFTWARE,
backend = StorageBackend.ANDROIDKEYSTORE,
accessControl = AccessControl.NONE,
timestamp = System.currentTimeMillis() / 1000.0
)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,22 @@ internal class BiometricAuthenticator {
val builder = BiometricPrompt.PromptInfo.Builder()
.setTitle(prompt.title)

// Prefer disabling confirmation on supported devices to streamline UX while maintaining
// biometric security. Newer Biometric APIs support `setConfirmationRequired`.
try {
builder.setConfirmationRequired(false)
} catch (_: Throwable) {
// Ignore if the platform/library doesn't support this method.
}

prompt.subtitle?.let(builder::setSubtitle)
prompt.description?.let(builder::setDescription)

var promptAuthenticators = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Newer biometric library versions (1.4.x+) prefer `setAllowedAuthenticators`.
allowedAuthenticators
} else {
// On older platforms fall back to the legacy flags.
allowedAuthenticators and (BiometricManager.Authenticators.BIOMETRIC_STRONG or BiometricManager.Authenticators.DEVICE_CREDENTIAL)
}

Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
org.gradle.parallel=true

# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
Expand Down
Loading
Loading