admin-ch / CovidCertificate-App-Android

CovidCertificate Apps for Android
Mozilla Public License 2.0
178 stars 42 forks source link

Modify vaccination offset #235

Closed slamcoderpt closed 3 years ago

slamcoderpt commented 3 years ago

Any way of changing the valid vaccination offset?? I tried to change it in sdk-android but i cant compile it and use it without the marven dependencies.

goebelUB commented 3 years ago

You'll notice that the actual offset is not hardcoded anywhere. Instead, it is part of the national verification rules that are retrieved from the backend and passed to the verification task. Ideally, you'll set up your own backend and point your app to it.

Some general notes that may help: the ruleset retrieved from the backend uses certlogic. Some terms you want to grep for while navigating the code are "national rules" and "rule set". You also want to look at the code in the core Kotlin SDK, which the Android SDK uses.

To use your own local version of the SDK you can use composite builds. Let's assume you have the SDK and the app checked out in parallel, i.e. within the same folder/directory. For development purposes, you can put something along the following lines in the app's settings.gradle to make Gradle replace the Maven version with the local version:

// Include the SDK repo in the build
includeBuild('../CovidCertificate-SDK-Android'){
    dependencySubstitution {
        // Tell gradle to replace the SDK from Maven with the 'sdk' module from the included repo
        substitute module('ch.admin.bag.covidcertificate:sdk-android') with project(':sdk')
    }
}

Hope that helps.

slamcoderpt commented 3 years ago

Thanks a lot with the build help. I was stuck with it. About the offset there is a function called getValidityRange where there is no offset offset for two dose vaccines. ` val offset = when { // Use the offset value from the acceptance criteria for single-dose vaccines ruleValueSets.oneDoseVaccinesWithOffset?.contains(vaccination.medicinialProduct) == true -> { ruleValueSets.acceptanceCriteria.singleVaccineValidityOffset } // Two-dose vaccines don't have an offset ruleValueSets.twoDoseVaccines?.contains(vaccination.medicinialProduct) == true -> 0 else -> null }

            offset?.let {
                ValidityRange(
                    vaccination.validFromDate(it.toLong()),
                    vaccination.validUntilDate(ruleValueSets.acceptanceCriteria)
                )
            }

` Can i just change it to hardcoded values or values comming from some custom json?

slamcoderpt commented 3 years ago

Another thing: After using dependencySubstitution for both sdk-android and sdk-core i tried to change some things in the core project but it seems it's not using the changes i made. Code used: includeBuild('../CovidCertificate-SDK-Android'){ dependencySubstitution { // Tell gradle to replace the SDK from Maven with the 'sdk' module from the included repo substitute module('ch.admin.bag.covidcertificate:sdk-android:1.2.0') with project(':sdk') } } includeBuild('../CovidCertificate-SDK-Kotlin-1.1.2'){ dependencySubstitution { // Tell gradle to replace the SDK from Maven with the 'sdk' module from the included repo substitute module('ch.admin.bag.covidcertificate:sdk-core:1.1.2') } }

goebelUB commented 3 years ago

The following works for me (e.g. checked by throwing in print statements in the local SDK):

includeBuild('../CovidCertificate-SDK-Android'){
    dependencySubstitution {
        substitute module('ch.admin.bag.covidcertificate:sdk-android') with project(':sdk')
    }
}

includeBuild('../CovidCertificate-SDK-Kotlin'){
    dependencySubstitution {
        substitute module('ch.admin.bag.covidcertificate:sdk-core') with project(':')
    }
}

Not specifying a version is just easier, eliminating the need to check if it changed in the build.gradle.

The crucial difference compared to yours seems to be the with project(':') - gradle needs something to replace it with! In case of the Kotlin SDK, the module name is just empty.

Can i just change it to hardcoded values or values comming from some custom json?

I think getValidityRange is only a helper whose result is used for visual display in the app. To see what the actual validation does, you can set a breakpoint in the NationalRulesVerifier.verify method to inspect the ruleSet. Or see the test resource here. The date offset for vaccines is currently checked by VR-CH-0004 (and subsequent ones).

slamcoderpt commented 3 years ago

Thank you! The problem was solved.