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
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ buildscript {

apply plugin: "com.android.library"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "kotlin-parcelize"

repositories {
google()
mavenCentral()
}

project.version = "2024.8.1"
ext {
VERSION_CODE = 20240801
}

android {
namespace = "com.simprints.libsimprints"
Expand All @@ -30,8 +32,10 @@ android {
minSdkVersion 23
targetSdkVersion 35

versionCode 2
versionName project.version
// Version code should match the name as it is used in SID
// to determine the most appropriate response data format
versionCode project.property("VERSION_CODE")

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -53,11 +57,14 @@ android {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"

buildConfigField("Integer", "LIBRARY_VERSION_CODE", "${project.property("VERSION_CODE")}")
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
buildConfigField("String", "LIBRARY_PACKAGE_VERSION", "\"${project.version}\"")
buildConfigField("Integer", "LIBRARY_VERSION_CODE", "${project.property("VERSION_CODE")}")
}
staging {
initWith release
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/simprints/libsimprints/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ object Constants {
const val SIMPRINTS_SELECTED_GUID_NONE = "none_selected"

// Optional extras
const val SIMPRINTS_CALLING_PACKAGE = "packageName"
const val SIMPRINTS_BIOMETRIC_DATA_SOURCE = "biometricDataSource"
const val SIMPRINTS_METADATA = "metadata"

// Optional keys in SIMPRINTS_METADATA
const val SIMPRINTS_SUBJECT_AGE = "subjectAge"

// Request meta data added to the intent
const val SIMPRINTS_LIB_VERSION = "versionCode"

// Custom callout parameters for particular integrations: Don't include if not needed
const val SIMPRINTS_RESULT_FORMAT = "resultFormat"
const val SIMPRINTS_ODK_RESULT_FORMAT_V01 = "ODKv01"
Expand Down Expand Up @@ -83,6 +85,7 @@ object Constants {

// Result extras
const val SIMPRINTS_REGISTRATION = "registration"
const val SIMPRINTS_ENROLMENT = "enrolment"
const val SIMPRINTS_IDENTIFICATIONS = "identification"
const val SIMPRINTS_VERIFICATION = "verification"
const val SIMPRINTS_VERIFICATION_SUCCESS = "verificationSuccess"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.simprints.libsimprints

@Deprecated("Used only in a deprecated data class")
enum class FingerIdentifier {
RIGHT_5TH_FINGER,
RIGHT_4TH_FINGER,
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/com/simprints/libsimprints/Identification.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.simprints.libsimprints
package com.simprints.libsimprints;

import android.os.Parcel
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import android.os.Parcelable.Creator

/**
* This constructor creates a new identification
Expand All @@ -10,7 +11,7 @@ import kotlinx.parcelize.Parcelize
* @param confidence An int containing the (matching) confidence
* @param tier The tier score derived from the confidence
*/
@Parcelize
@Deprecated("Use contracts.data.Identification instead")
data class Identification(
val guid: String,
private val confidence: Int,
Expand All @@ -24,4 +25,28 @@ data class Identification(
confidence < other.confidence -> 1
else -> -1
}

override fun describeContents(): Int = 0

override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeString(guid)
dest.writeInt(this.confidence)
dest.writeInt(this.tier.ordinal)
}

companion object {
@JvmField
val CREATOR = object : Creator<Identification> {

override fun createFromParcel(parcel: Parcel): Identification? {
val guid = parcel.readString().orEmpty()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you confirmed that createFromParcel is working as expected? I remember having fun with it back in the days

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per slack conversation - I have integrated this version in SID and then tried calling from the current "main" version of Intent Launcher (it still uses java version of LibSimprints). So I am fairly confident that it works correctly.

val confidence = parcel.readInt()
val tier = Tier.entries[parcel.readInt()]

return Identification(guid, confidence, tier)
}

override fun newArray(p0: Int): Array<out Identification?> = arrayOfNulls(p0)
}
}
}
38 changes: 33 additions & 5 deletions src/main/java/com/simprints/libsimprints/RefusalForm.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
package com.simprints.libsimprints
package com.simprints.libsimprints;

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator

@Parcelize
@Deprecated("Use contracts.data.RefusalForm instead")
data class RefusalForm(
val reason: String,
val extra: String,
) : Parcelable
) : Parcelable {

override fun describeContents(): Int {
return 0
}

override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeString(reason)
dest.writeString(extra)
}

companion object {
@JvmField
val CREATOR = object : Creator<RefusalForm> {

override fun createFromParcel(parcel: Parcel): RefusalForm? {
val reason = parcel.readString().orEmpty()
val extra = parcel.readString().orEmpty()

return RefusalForm(reason, extra)
}

override fun newArray(p0: Int): Array<out RefusalForm?> {
return arrayOfNulls(p0)
}
}
}
}
69 changes: 65 additions & 4 deletions src/main/java/com/simprints/libsimprints/Registration.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,70 @@
package com.simprints.libsimprints

import android.os.Parcel
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import android.os.Parcelable.Creator

@Parcelize
data class Registration(
@Deprecated("Use contracts.data.Enrolment instead")
data class Registration @JvmOverloads constructor(
val guid: String,
) : Parcelable
private val templates: MutableMap<FingerIdentifier, ByteArray> = mutableMapOf()
) : Parcelable {

fun setTemplate(fingerId: FingerIdentifier, fingerTemplate: ByteArray) {
templates[fingerId] = fingerTemplate
}

fun getTemplate(fingerId: FingerIdentifier): ByteArray = templates[fingerId] ?: byteArrayOf()

override fun describeContents(): Int = 0

override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeString(guid)
dest.writeInt(templates.size)

for ((fingerId, fingerTemplate) in templates) {
dest.writeInt(fingerId.ordinal)
dest.writeInt(fingerTemplate.size)
dest.writeByteArray(fingerTemplate)
}
}

override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + guid.hashCode()
result = 31 * result + templates.hashCode()
return result
}

override fun equals(other: Any?): Boolean {
if (other === this) return true
if (other !is Registration) return false
if (guid != other.guid) return false
for (fingerId in FingerIdentifier.entries) {
if (!templates[fingerId].contentEquals(other.templates[fingerId])) return false
}
return true;
}

companion object {
@JvmField
val CREATOR = object : Creator<Registration> {

override fun createFromParcel(parcel: Parcel): Registration? {
val guid = parcel.readString().orEmpty()
val nbOfTemplates = parcel.readInt()

val templates = mutableMapOf<FingerIdentifier, ByteArray>()
for (i in 0 until nbOfTemplates) {
val fingerId = FingerIdentifier.entries[parcel.readInt()]
val fingerTemplate = ByteArray(parcel.readInt())
parcel.readByteArray(fingerTemplate)
templates[fingerId] = fingerTemplate
}
return Registration(guid, templates)
}

override fun newArray(p0: Int): Array<out Registration?> = arrayOfNulls(p0)
}
}
}
1 change: 1 addition & 0 deletions src/main/java/com/simprints/libsimprints/Tier.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.simprints.libsimprints

@Deprecated("Use contracts.data.Tier instead")
enum class Tier {
TIER_1,
TIER_2,
Expand Down
41 changes: 29 additions & 12 deletions src/main/java/com/simprints/libsimprints/Verification.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
package com.simprints.libsimprints

import android.os.Parcel
import android.os.Parcelable
import kotlinx.parcelize.Parcelize

/**
* This constructor creates a new verification
*
* @param confidence An int containing the (matching) confidence
* @param tier The tier score derived from the confidence
* @param guid Global unique id of the verified person
*/
@Parcelize
import android.os.Parcelable.Creator

@SuppressWarnings("unused", "WeakerAccess")
@Deprecated("Use contracts.data.Verification instead")
data class Verification @JvmOverloads constructor(
private val confidence: Int,
val tier: Tier,
val guid: String,
// TODO change to val once it is correctly returned from SID
var isSuccess: Boolean = false,
) : Parcelable {

fun getConfidence(): Float = confidence.toFloat()

override fun describeContents(): Int = 0

override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeInt(this.confidence)
dest.writeInt(this.tier.ordinal)
dest.writeString(this.guid)
}

companion object {
@JvmField
val CREATOR = object : Creator<Verification> {

override fun createFromParcel(parcel: Parcel): Verification? {
val confidence = parcel.readInt()
val tier = Tier.entries[parcel.readInt()]
val guid = parcel.readString().orEmpty()

return Verification(confidence, tier, guid)
}

override fun newArray(p0: Int): Array<out Verification?> = arrayOfNulls(p0)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.simprints.libsimprints.contracts

import android.content.Intent
import com.simprints.libsimprints.BuildConfig
import com.simprints.libsimprints.Constants
import com.simprints.libsimprints.Metadata

Expand Down Expand Up @@ -47,6 +48,7 @@ sealed class SimprintsRequest {

override fun toIntent() = Intent(Constants.SIMPRINTS_ENROL_INTENT)
.appendAuthFields(projectId, userId)
.appendRequestMetaInformation()
.putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId)
.appendOptionalMetadata(metadata)
}
Expand All @@ -71,6 +73,7 @@ sealed class SimprintsRequest {
) : SimprintsRequest() {
override fun toIntent() = Intent(Constants.SIMPRINTS_IDENTIFY_INTENT)
.appendAuthFields(projectId, userId)
.appendRequestMetaInformation()
.putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId)
.appendOptionalMetadata(metadata)
}
Expand All @@ -97,6 +100,7 @@ sealed class SimprintsRequest {
) : SimprintsRequest() {
override fun toIntent() = Intent(Constants.SIMPRINTS_VERIFY_INTENT)
.appendAuthFields(projectId, userId)
.appendRequestMetaInformation()
.putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId)
.putExtra(Constants.SIMPRINTS_VERIFY_GUID, verifyId)
.appendOptionalMetadata(metadata)
Expand All @@ -120,6 +124,7 @@ sealed class SimprintsRequest {
) : SimprintsRequest() {
override fun toIntent() = Intent(Constants.SIMPRINTS_CONFIRM_IDENTITY_INTENT)
.appendAuthFields(projectId, userId)
.appendRequestMetaInformation()
.putExtra(Constants.SIMPRINTS_SESSION_ID, sessionId)
.putExtra(Constants.SIMPRINTS_SELECTED_GUID, selectedGuid)
}
Expand All @@ -146,15 +151,19 @@ sealed class SimprintsRequest {
) : SimprintsRequest() {
override fun toIntent() = Intent(Constants.SIMPRINTS_ENROL_LAST_BIOMETRICS_INTENT)
.appendAuthFields(projectId, userId)
.appendRequestMetaInformation()
.putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId)
.putExtra(Constants.SIMPRINTS_SESSION_ID, sessionId)
.appendOptionalMetadata(metadata)
}

protected fun Intent.appendAuthFields(projectId: String, userId: String) = this
protected fun Intent.appendAuthFields(projectId: String, userId: String): Intent = this
.putExtra(Constants.SIMPRINTS_PROJECT_ID, projectId)
.putExtra(Constants.SIMPRINTS_USER_ID, userId)

protected fun Intent.appendRequestMetaInformation() = this
.putExtra(Constants.SIMPRINTS_LIB_VERSION, BuildConfig.LIBRARY_VERSION_CODE)

protected fun Intent.appendOptionalMetadata(metadata: Metadata?) =
if (metadata == null) this
else putExtra(Constants.SIMPRINTS_METADATA, metadata.toString())
Expand Down
Loading