Skip to content

Commit 0bffdb8

Browse files
committed
feat: Propogate NFC availability config to ID Check SDK
1 parent ae6a388 commit 0bffdb8

11 files changed

Lines changed: 54 additions & 28 deletions

File tree

features/config/public-api/src/testFixtures/kotlin/uk/gov/onelogin/criorchestrator/features/config/publicapi/FakeConfig.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package uk.gov.onelogin.criorchestrator.features.config.publicapi
33
import kotlinx.collections.immutable.persistentListOf
44
import uk.gov.onelogin.criorchestrator.features.config.publicapi.SdkConfigKey.IdCheckAsyncBackendBaseUrl
55
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.publicapi.IdCheckWrapperConfigKey
6+
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.publicapi.nfc.NfcConfigKey
67

78
object FakeConfig {
89
const val ID_CHECK_BACKEND_ASYNC_URL_TEST_VALUE = "https://test.backend.url"
@@ -31,6 +32,10 @@ object FakeConfig {
3132
key = IdCheckWrapperConfigKey.ExperimentalComposeNavigation,
3233
value = Config.Value.BooleanValue(false),
3334
),
35+
Config.Entry<Config.Value.StringValue>(
36+
key = NfcConfigKey.NfcAvailability,
37+
value = Config.Value.StringValue(NfcConfigKey.NfcAvailability.OPTION_DEVICE),
38+
),
3439
),
3540
)
3641
}

features/id-check-wrapper/internal/src/main/kotlin/uk/gov/onelogin/criorchestrator/features/idcheckwrapper/internal/activity/IdCheckSdkActivityParameters.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ internal fun LauncherData.toIdCheckSdkActivityParameters() =
1111
bioToken = this.biometricToken,
1212
backendMode = this.backendMode,
1313
experimentalComposeNavigation = this.experimentalComposeNavigation,
14+
nfcAvailability = this.nfcAvailability,
1415
)

features/id-check-wrapper/internal/src/main/kotlin/uk/gov/onelogin/criorchestrator/features/idcheckwrapper/internal/data/LauncherDataReader.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internal.data
33
import dev.zacsweers.metro.Inject
44
import kotlinx.coroutines.FlowPreview
55
import kotlinx.coroutines.flow.first
6+
import uk.gov.idcheck.repositories.api.config.NfcAvailability
67
import uk.gov.idcheck.repositories.api.webhandover.backend.BackendMode
78
import uk.gov.onelogin.criorchestrator.features.config.internalapi.ConfigStore
89
import uk.gov.onelogin.criorchestrator.features.config.publicapi.SdkConfigKey
@@ -12,6 +13,7 @@ import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internal.model.La
1213
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internal.nav.toDocumentType
1314
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internalapi.DocumentVariety
1415
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.publicapi.IdCheckWrapperConfigKey
16+
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.publicapi.nfc.NfcConfigKey
1517
import uk.gov.onelogin.criorchestrator.features.session.internalapi.domain.Session
1618
import uk.gov.onelogin.criorchestrator.features.session.internalapi.domain.SessionStore
1719

@@ -30,6 +32,13 @@ class LauncherDataReader(
3032
val experimentalComposeNavigation: Boolean =
3133
configStore.readSingle(IdCheckWrapperConfigKey.ExperimentalComposeNavigation).value
3234

35+
val nfcAvailability =
36+
when (configStore.readSingle(NfcConfigKey.NfcAvailability).value) {
37+
NfcConfigKey.NfcAvailability.OPTION_AVAILABLE -> NfcAvailability.Available
38+
NfcConfigKey.NfcAvailability.OPTION_NOT_AVAILABLE -> NfcAvailability.Unavailable
39+
else -> NfcAvailability.Device
40+
}
41+
3342
if (result is BiometricTokenResult.Success) {
3443
sessionStore.updateToDocumentSelected()
3544
}
@@ -73,6 +82,7 @@ class LauncherDataReader(
7382
documentType = documentVariety.toDocumentType(),
7483
backendMode = backendMode,
7584
experimentalComposeNavigation = experimentalComposeNavigation,
85+
nfcAvailability = nfcAvailability,
7686
),
7787
)
7888
}

features/id-check-wrapper/internal/src/main/kotlin/uk/gov/onelogin/criorchestrator/features/idcheckwrapper/internal/model/LauncherData.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internal.model
22

3+
import uk.gov.idcheck.repositories.api.config.NfcAvailability
34
import uk.gov.idcheck.repositories.api.vendor.BiometricToken
45
import uk.gov.idcheck.repositories.api.webhandover.backend.BackendMode
56
import uk.gov.idcheck.repositories.api.webhandover.documenttype.DocumentType
@@ -14,6 +15,7 @@ data class LauncherData(
1415
val documentType: DocumentType,
1516
val backendMode: BackendMode,
1617
val experimentalComposeNavigation: Boolean,
18+
val nfcAvailability: NfcAvailability,
1719
) {
1820
companion object;
1921

features/id-check-wrapper/internal/src/main/kotlin/uk/gov/onelogin/criorchestrator/features/idcheckwrapper/internal/nfc/NfcBindings.kt

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,11 @@ import android.nfc.NfcManager
55
import dev.zacsweers.metro.BindingContainer
66
import dev.zacsweers.metro.ContributesTo
77
import dev.zacsweers.metro.Provides
8-
import dev.zacsweers.metro.SingleIn
9-
import uk.gov.onelogin.criorchestrator.features.config.internalapi.ConfigStore
10-
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internalapi.nfc.NfcChecker
118
import uk.gov.onelogin.criorchestrator.libraries.di.CriOrchestratorScope
12-
import uk.gov.idcheck.sdk.passport.nfc.checker.NfcCheckerImpl as IdCheckSdkNfcCheckerImpl
139

1410
@BindingContainer
1511
@ContributesTo(CriOrchestratorScope::class)
1612
object NfcBindings {
1713
@Provides
18-
@SingleIn(CriOrchestratorScope::class)
19-
fun provideNfcChecker(
20-
context: Context,
21-
configStore: ConfigStore,
22-
): NfcChecker {
23-
val nfcManager = context.getSystemService(Context.NFC_SERVICE) as NfcManager
24-
25-
val idCheckSdkNfcCheckerImpl = IdCheckSdkNfcCheckerImpl(nfcManager)
26-
27-
return NfcCheckerImpl(
28-
configStore = configStore,
29-
deviceNfcChecker = idCheckSdkNfcCheckerImpl,
30-
)
31-
}
14+
fun provideNfcManager(context: Context): NfcManager = context.getSystemService(Context.NFC_SERVICE) as NfcManager
3215
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internal.nfc
22

3+
import android.nfc.NfcManager
4+
import dev.zacsweers.metro.ContributesBinding
35
import uk.gov.onelogin.criorchestrator.features.config.internalapi.ConfigStore
46
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internalapi.nfc.NfcChecker
57
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.publicapi.nfc.NfcConfigKey
6-
import uk.gov.idcheck.sdk.passport.nfc.checker.NfcChecker as IdCheckSdkNfcChecker
8+
import uk.gov.onelogin.criorchestrator.libraries.di.CriOrchestratorScope
79

10+
@ContributesBinding(CriOrchestratorScope::class)
811
class NfcCheckerImpl(
912
private val configStore: ConfigStore,
10-
private val deviceNfcChecker: IdCheckSdkNfcChecker,
13+
private val nfcManager: NfcManager,
1114
) : NfcChecker {
1215
override fun hasNfc(): Boolean =
1316
when (configStore.readSingle(NfcConfigKey.NfcAvailability).value) {
1417
NfcConfigKey.NfcAvailability.OPTION_AVAILABLE -> true
1518
NfcConfigKey.NfcAvailability.OPTION_NOT_AVAILABLE -> false
16-
else -> deviceNfcChecker.hasNfc()
19+
else -> nfcManager.defaultAdapter != null
1720
}
1821
}

features/id-check-wrapper/internal/src/main/kotlin/uk/gov/onelogin/criorchestrator/features/idcheckwrapper/internal/screen/SyncIdCheckScreenManualLauncherContent.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import uk.gov.android.ui.componentsv2.inputs.radio.TitleType
2121
import uk.gov.android.ui.patterns.leftalignedscreen.LeftAlignedScreen
2222
import uk.gov.android.ui.theme.m3.GdsTheme
2323
import uk.gov.android.ui.theme.util.UnstableDesignSystemAPI
24+
import uk.gov.idcheck.repositories.api.config.NfcAvailability
2425
import uk.gov.idcheck.repositories.api.vendor.BiometricToken
2526
import uk.gov.idcheck.repositories.api.webhandover.backend.BackendMode
2627
import uk.gov.idcheck.repositories.api.webhandover.documenttype.DocumentType
@@ -140,6 +141,7 @@ internal fun PreviewSyncIdCheckManualLauncherContent() {
140141
),
141142
backendMode = BackendMode.V2,
142143
experimentalComposeNavigation = false,
144+
nfcAvailability = NfcAvailability.Device,
143145
),
144146
exitStateOptions = ExitStateOption.entries.map { it.displayName }.toPersistentList(),
145147
selectedExitState = 0,

features/id-check-wrapper/internal/src/test/kotlin/uk/gov/onelogin/criorchestrator/features/idcheckwrapper/internal/data/LauncherDataReaderTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test
88
import org.junit.jupiter.api.assertThrows
99
import org.junit.jupiter.params.ParameterizedTest
1010
import org.junit.jupiter.params.provider.ValueSource
11+
import uk.gov.idcheck.repositories.api.config.NfcAvailability
1112
import uk.gov.idcheck.repositories.api.vendor.BiometricToken
1213
import uk.gov.idcheck.repositories.api.webhandover.backend.BackendMode
1314
import uk.gov.idcheck.repositories.api.webhandover.documenttype.DocumentType
@@ -23,6 +24,7 @@ import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internal.biometri
2324
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internal.model.LauncherData
2425
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internalapi.DocumentVariety
2526
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.publicapi.IdCheckWrapperConfigKey
27+
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.publicapi.nfc.NfcConfigKey
2628
import uk.gov.onelogin.criorchestrator.features.session.internalapi.domain.FakeSessionStore
2729
import uk.gov.onelogin.criorchestrator.features.session.internalapi.domain.Session
2830
import uk.gov.onelogin.criorchestrator.features.session.internalapi.domain.SessionStore
@@ -52,6 +54,11 @@ class LauncherDataReaderTest {
5254
value =
5355
Config.Value.BooleanValue(false),
5456
),
57+
Config.Entry<Config.Value.StringValue>(
58+
key = NfcConfigKey.NfcAvailability,
59+
value =
60+
Config.Value.StringValue(NfcConfigKey.NfcAvailability.OPTION_DEVICE),
61+
),
5562
),
5663
)
5764
private val configStore by lazy {
@@ -73,6 +80,7 @@ class LauncherDataReaderTest {
7380
documentType = DocumentType.NFC_PASSPORT,
7481
backendMode = BackendMode.V2,
7582
experimentalComposeNavigation = false,
83+
nfcAvailability = NfcAvailability.Device,
7684
),
7785
)
7886

features/id-check-wrapper/internal/src/test/kotlin/uk/gov/onelogin/criorchestrator/features/idcheckwrapper/internal/nfc/NfcCheckerImplTest.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package uk.gov.onelogin.criorchestrator.features.idcheckwrapper.internal.nfc
22

3+
import android.nfc.NfcManager
34
import org.junit.jupiter.api.Assertions.assertFalse
45
import org.junit.jupiter.api.Assertions.assertTrue
56
import org.junit.jupiter.api.Test
@@ -8,15 +9,14 @@ import org.mockito.kotlin.given
89
import uk.gov.onelogin.criorchestrator.features.config.internalapi.FakeConfigStore
910
import uk.gov.onelogin.criorchestrator.features.config.publicapi.Config
1011
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.publicapi.nfc.NfcConfigKey
11-
import uk.gov.idcheck.sdk.passport.nfc.checker.NfcChecker as IdCheckSdkNfcChecker
1212

1313
class NfcCheckerImplTest {
1414
private val configStore = FakeConfigStore()
15-
private val deviceNfcChecker = mock<IdCheckSdkNfcChecker>()
15+
private val nfcManager = mock<NfcManager>()
1616
val nfcChecker =
1717
NfcCheckerImpl(
1818
configStore = configStore,
19-
deviceNfcChecker = deviceNfcChecker,
19+
nfcManager = nfcManager,
2020
)
2121

2222
@Test
@@ -28,7 +28,7 @@ class NfcCheckerImplTest {
2828
Config.Value.StringValue(NfcConfigKey.NfcAvailability.OPTION_DEVICE),
2929
),
3030
)
31-
given(deviceNfcChecker.hasNfc()).willReturn(true)
31+
givenDeviceNfc(available = true)
3232

3333
assertTrue(nfcChecker.hasNfc())
3434
}
@@ -42,7 +42,7 @@ class NfcCheckerImplTest {
4242
Config.Value.StringValue(NfcConfigKey.NfcAvailability.OPTION_DEVICE),
4343
),
4444
)
45-
given(deviceNfcChecker.hasNfc()).willReturn(false)
45+
givenDeviceNfc(available = false)
4646

4747
assertFalse(nfcChecker.hasNfc())
4848
}
@@ -56,7 +56,7 @@ class NfcCheckerImplTest {
5656
Config.Value.StringValue(NfcConfigKey.NfcAvailability.OPTION_AVAILABLE),
5757
),
5858
)
59-
given(deviceNfcChecker.hasNfc()).willReturn(false)
59+
givenDeviceNfc(available = false)
6060

6161
assertTrue(nfcChecker.hasNfc())
6262
}
@@ -70,8 +70,13 @@ class NfcCheckerImplTest {
7070
Config.Value.StringValue(NfcConfigKey.NfcAvailability.OPTION_NOT_AVAILABLE),
7171
),
7272
)
73-
given(deviceNfcChecker.hasNfc()).willReturn(true)
73+
givenDeviceNfc(available = true)
7474

7575
assertFalse(nfcChecker.hasNfc())
7676
}
77+
78+
private fun givenDeviceNfc(available: Boolean) =
79+
given(nfcManager.defaultAdapter).willReturn(
80+
if (available) mock() else null,
81+
)
7782
}

features/id-check-wrapper/internal/src/testFixtures/kotlin/uk/gov/onelogin/criorchestrator/features/idcheckwrapper/internal/config/StubIdCheckWrapperConfig.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import kotlinx.collections.immutable.persistentListOf
44
import uk.gov.onelogin.criorchestrator.features.config.publicapi.Config
55
import uk.gov.onelogin.criorchestrator.features.config.publicapi.SdkConfigKey
66
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.publicapi.IdCheckWrapperConfigKey
7+
import uk.gov.onelogin.criorchestrator.features.idcheckwrapper.publicapi.nfc.NfcConfigKey
78

89
fun Config.Companion.createTestInstance(
910
enableManualLauncher: Boolean = false,
@@ -25,5 +26,9 @@ fun Config.Companion.createTestInstance(
2526
key = IdCheckWrapperConfigKey.ExperimentalComposeNavigation,
2627
value = Config.Value.BooleanValue(experimentalComposeNavigation),
2728
),
29+
Config.Entry<Config.Value.StringValue>(
30+
key = NfcConfigKey.NfcAvailability,
31+
value = Config.Value.StringValue(NfcConfigKey.NfcAvailability.OPTION_DEVICE),
32+
),
2833
),
2934
)

0 commit comments

Comments
 (0)