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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:2.0.10"
implementation 'androidx.activity:activity-ktx:1.9.1'

testImplementation "junit:junit:4.13.2"
testImplementation "androidx.test.ext:junit:1.2.1"
Expand Down
168 changes: 89 additions & 79 deletions src/main/java/com/simprints/libsimprints/Constants.kt
Original file line number Diff line number Diff line change
@@ -1,105 +1,115 @@
package com.simprints.libsimprints;
package com.simprints.libsimprints

import android.app.Activity;
import android.app.Activity

@SuppressWarnings("unused", "WeakerAccess")
object Constants {

// Intents
const val SIMPRINTS_REGISTER_INTENT = "com.simprints.id.REGISTER";
const val SIMPRINTS_IDENTIFY_INTENT = "com.simprints.id.IDENTIFY";
const val SIMPRINTS_VERIFY_INTENT = "com.simprints.id.VERIFY";
const val SIMPRINTS_SELECT_GUID_INTENT = "com.simprints.id.CONFIRM_IDENTITY";
const val SIMPRINTS_REGISTER_LAST_BIOMETRICS_INTENT = "com.simprints.id.REGISTER_LAST_BIOMETRICS";
const val SIMPRINTS_ENROL_INTENT = "com.simprints.id.REGISTER"
const val SIMPRINTS_IDENTIFY_INTENT = "com.simprints.id.IDENTIFY"
const val SIMPRINTS_VERIFY_INTENT = "com.simprints.id.VERIFY"
const val SIMPRINTS_CONFIRM_IDENTITY_INTENT = "com.simprints.id.CONFIRM_IDENTITY"
const val SIMPRINTS_ENROL_LAST_BIOMETRICS_INTENT = "com.simprints.id.REGISTER_LAST_BIOMETRICS"

// Mandatory extras
const val SIMPRINTS_PROJECT_ID = "projectId";
const val SIMPRINTS_USER_ID = "userId";
const val SIMPRINTS_MODULE_ID = "moduleId";
const val SIMPRINTS_PROJECT_ID = "projectId"
const val SIMPRINTS_USER_ID = "userId"
const val SIMPRINTS_MODULE_ID = "moduleId"

// Mandatory for SIMPRINTS_VERIFY_INTENT
const val SIMPRINTS_VERIFY_GUID = "verifyGuid";
const val SIMPRINTS_VERIFY_GUID = "verifyGuid"

// Mandatory for SIMPRINTS_SELECT_GUID_INTENT
const val SIMPRINTS_SELECTED_GUID = "selectedGuid";
const val SIMPRINTS_SESSION_ID = "sessionId";
// Mandatory for SIMPRINTS_CONFIRM_IDENTITY_INTENT
const val SIMPRINTS_SELECTED_GUID = "selectedGuid"
const val SIMPRINTS_SESSION_ID = "sessionId"

// Special case value for SIMPRINTS_CONFIRM_IDENTITY_INTENT when none of the guids are selected
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";
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";
const val SIMPRINTS_SUBJECT_AGE = "subjectAge"

// 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";
const val SIMPRINTS_ODK_RESULT_FORMAT_V01_SEPARATOR = " ";
const val SIMPRINTS_RESULT_FORMAT = "resultFormat"
const val SIMPRINTS_ODK_RESULT_FORMAT_V01 = "ODKv01"
const val SIMPRINTS_ODK_RESULT_FORMAT_V01_SEPARATOR = " "

// Result codes
const val SIMPRINTS_OK = Activity.RESULT_OK;
const val SIMPRINTS_CANCELLED = Activity.RESULT_CANCELED;
const val SIMPRINTS_MISSING_USER_ID = Activity.RESULT_FIRST_USER + 2;
const val SIMPRINTS_MISSING_MODULE_ID = Activity.RESULT_FIRST_USER + 4;
const val SIMPRINTS_INVALID_INTENT_ACTION = Activity.RESULT_FIRST_USER + 6;
const val SIMPRINTS_INVALID_UPDATE_GUID = Activity.RESULT_FIRST_USER + 7;
const val SIMPRINTS_MISSING_UPDATE_GUID = Activity.RESULT_FIRST_USER + 8;
const val SIMPRINTS_MISSING_VERIFY_GUID = Activity.RESULT_FIRST_USER + 9;
const val SIMPRINTS_INVALID_METADATA = Activity.RESULT_FIRST_USER + 10;
const val SIMPRINTS_VERIFY_GUID_NOT_FOUND_ONLINE = Activity.RESULT_FIRST_USER + 11;
const val SIMPRINTS_VERIFY_GUID_NOT_FOUND_OFFLINE = Activity.RESULT_FIRST_USER + 12;
const val SIMPRINTS_INVALID_VERIFY_GUID = Activity.RESULT_FIRST_USER + 13;
const val SIMPRINTS_INVALID_RESULT_FORMAT = Activity.RESULT_FIRST_USER + 14;
const val SIMPRINTS_INVALID_MODULE_ID = Activity.RESULT_FIRST_USER + 15;
const val SIMPRINTS_INVALID_USER_ID = Activity.RESULT_FIRST_USER + 16;
const val SIMPRINTS_INVALID_CALLING_PACKAGE = Activity.RESULT_FIRST_USER + 17;
const val SIMPRINTS_MISSING_PROJECT_ID = Activity.RESULT_FIRST_USER + 18;
const val SIMPRINTS_INVALID_PROJECT_ID = Activity.RESULT_FIRST_USER + 19;
const val SIMPRINTS_DIFFERENT_PROJECT_ID = Activity.RESULT_FIRST_USER + 20;
const val SIMPRINTS_DIFFERENT_USER_ID = Activity.RESULT_FIRST_USER + 21;
const val SIMPRINTS_ROOTED_DEVICE = Activity.RESULT_FIRST_USER + 22;
const val SIMPRINTS_UNEXPECTED_ERROR = Activity.RESULT_FIRST_USER + 23;
const val SIMPRINTS_BLUETOOTH_NOT_SUPPORTED = Activity.RESULT_FIRST_USER + 24;
const val SIMPRINTS_INVALID_SELECTED_ID = Activity.RESULT_FIRST_USER + 25;
const val SIMPRINTS_INVALID_SESSION_ID = Activity.RESULT_FIRST_USER + 26;
const val SIMPRINTS_LOGIN_NOT_COMPLETE = Activity.RESULT_FIRST_USER + 27;
const val SIMPRINTS_INVALID_STATE_FOR_INTENT_ACTION = Activity.RESULT_FIRST_USER + 28;
const val SIMPRINTS_ENROLMENT_LAST_BIOMETRICS_FAILED = Activity.RESULT_FIRST_USER + 29;
const val SIMPRINTS_LICENSE_MISSING = Activity.RESULT_FIRST_USER + 30;
const val SIMPRINTS_LICENSE_INVALID = Activity.RESULT_FIRST_USER + 31;
const val SIMPRINTS_SETUP_OFFLINE_DURING_MODALITY_DOWNLOAD = Activity.RESULT_FIRST_USER + 32;
const val SIMPRINTS_SETUP_MODALITY_DOWNLOAD_CANCELLED = Activity.RESULT_FIRST_USER + 33;
const val SIMPRINTS_FINGERPRINT_CONFIGURATION_ERROR = Activity.RESULT_FIRST_USER + 34;
const val SIMPRINTS_FACE_CONFIGURATION_ERROR = Activity.RESULT_FIRST_USER + 35;
const val SIMPRINTS_BACKEND_MAINTENANCE_ERROR = Activity.RESULT_FIRST_USER + 36;
const val SIMPRINTS_PROJECT_PAUSED = Activity.RESULT_FIRST_USER + 37;
const val SIMPRINTS_PROJECT_ENDING = Activity.RESULT_FIRST_USER + 38;
const val SIMPRINTS_BLUETOOTH_NO_PERMISSION = Activity.RESULT_FIRST_USER + 39;
const val SIMPRINTS_AGE_GROUP_NOT_SUPPORTED = Activity.RESULT_FIRST_USER + 40;
const val SIMPRINTS_OK = Activity.RESULT_OK
const val SIMPRINTS_CANCELLED = Activity.RESULT_CANCELED
const val SIMPRINTS_MISSING_USER_ID = Activity.RESULT_FIRST_USER + 2
const val SIMPRINTS_MISSING_MODULE_ID = Activity.RESULT_FIRST_USER + 4
const val SIMPRINTS_INVALID_INTENT_ACTION = Activity.RESULT_FIRST_USER + 6
const val SIMPRINTS_INVALID_UPDATE_GUID = Activity.RESULT_FIRST_USER + 7
const val SIMPRINTS_MISSING_UPDATE_GUID = Activity.RESULT_FIRST_USER + 8
const val SIMPRINTS_MISSING_VERIFY_GUID = Activity.RESULT_FIRST_USER + 9
const val SIMPRINTS_INVALID_METADATA = Activity.RESULT_FIRST_USER + 10
const val SIMPRINTS_VERIFY_GUID_NOT_FOUND_ONLINE = Activity.RESULT_FIRST_USER + 11
const val SIMPRINTS_VERIFY_GUID_NOT_FOUND_OFFLINE = Activity.RESULT_FIRST_USER + 12
const val SIMPRINTS_INVALID_VERIFY_GUID = Activity.RESULT_FIRST_USER + 13
const val SIMPRINTS_INVALID_RESULT_FORMAT = Activity.RESULT_FIRST_USER + 14
const val SIMPRINTS_INVALID_MODULE_ID = Activity.RESULT_FIRST_USER + 15
const val SIMPRINTS_INVALID_USER_ID = Activity.RESULT_FIRST_USER + 16
const val SIMPRINTS_INVALID_CALLING_PACKAGE = Activity.RESULT_FIRST_USER + 17
const val SIMPRINTS_MISSING_PROJECT_ID = Activity.RESULT_FIRST_USER + 18
const val SIMPRINTS_INVALID_PROJECT_ID = Activity.RESULT_FIRST_USER + 19
const val SIMPRINTS_DIFFERENT_PROJECT_ID = Activity.RESULT_FIRST_USER + 20
const val SIMPRINTS_DIFFERENT_USER_ID = Activity.RESULT_FIRST_USER + 21
const val SIMPRINTS_ROOTED_DEVICE = Activity.RESULT_FIRST_USER + 22
const val SIMPRINTS_UNEXPECTED_ERROR = Activity.RESULT_FIRST_USER + 23
const val SIMPRINTS_BLUETOOTH_NOT_SUPPORTED = Activity.RESULT_FIRST_USER + 24
const val SIMPRINTS_INVALID_SELECTED_ID = Activity.RESULT_FIRST_USER + 25
const val SIMPRINTS_INVALID_SESSION_ID = Activity.RESULT_FIRST_USER + 26
const val SIMPRINTS_LOGIN_NOT_COMPLETE = Activity.RESULT_FIRST_USER + 27
const val SIMPRINTS_INVALID_STATE_FOR_INTENT_ACTION = Activity.RESULT_FIRST_USER + 28
const val SIMPRINTS_ENROLMENT_LAST_BIOMETRICS_FAILED = Activity.RESULT_FIRST_USER + 29
const val SIMPRINTS_LICENSE_MISSING = Activity.RESULT_FIRST_USER + 30
const val SIMPRINTS_LICENSE_INVALID = Activity.RESULT_FIRST_USER + 31
const val SIMPRINTS_SETUP_OFFLINE_DURING_MODALITY_DOWNLOAD = Activity.RESULT_FIRST_USER + 32
const val SIMPRINTS_SETUP_MODALITY_DOWNLOAD_CANCELLED = Activity.RESULT_FIRST_USER + 33
const val SIMPRINTS_FINGERPRINT_CONFIGURATION_ERROR = Activity.RESULT_FIRST_USER + 34
const val SIMPRINTS_FACE_CONFIGURATION_ERROR = Activity.RESULT_FIRST_USER + 35
const val SIMPRINTS_BACKEND_MAINTENANCE_ERROR = Activity.RESULT_FIRST_USER + 36
const val SIMPRINTS_PROJECT_PAUSED = Activity.RESULT_FIRST_USER + 37
const val SIMPRINTS_PROJECT_ENDING = Activity.RESULT_FIRST_USER + 38
const val SIMPRINTS_BLUETOOTH_NO_PERMISSION = Activity.RESULT_FIRST_USER + 39
const val SIMPRINTS_AGE_GROUP_NOT_SUPPORTED = Activity.RESULT_FIRST_USER + 40

// Result extras
const val SIMPRINTS_REGISTRATION = "registration";
const val SIMPRINTS_IDENTIFICATIONS = "identification";
const val SIMPRINTS_VERIFICATION = "verification";
const val SIMPRINTS_VERIFICATION_SUCCESS = "verificationSuccess";
const val SIMPRINTS_REFUSAL_FORM = "refusalForm";
const val SIMPRINTS_REGISTRATION = "registration"
const val SIMPRINTS_IDENTIFICATIONS = "identification"
const val SIMPRINTS_VERIFICATION = "verification"
const val SIMPRINTS_VERIFICATION_SUCCESS = "verificationSuccess"
const val SIMPRINTS_REFUSAL_FORM = "refusalForm"

// When SIMPRINTS_BIOMETRICS_COMPLETE_CHECK is true, the user has completed the Simprints flow
const val SIMPRINTS_BIOMETRICS_COMPLETE_CHECK = "biometricsComplete";
const val SIMPRINTS_BIOMETRICS_COMPLETE_CHECK = "biometricsComplete"

// These two values represent data that could be null. They only apply to projects using cosync
const val SIMPRINTS_COSYNC_EVENT = "events";
const val SIMPRINTS_COSYNC_SUBJECT_ACTIONS = "subjectActions";

// Deprecated extras
@Deprecated("Use {@link #SIMPRINTS_PROJECT_ID} instead.")
const val SIMPRINTS_API_KEY = "apiKey";

// Deprecated result codes
@Deprecated("Use {@link #SIMPRINTS_MISSING_PROJECT_ID} instead.")
const val SIMPRINTS_MISSING_API_KEY = Activity.RESULT_FIRST_USER;

@Deprecated("Use {@link #SIMPRINTS_INVALID_PROJECT_ID} instead.")
const val SIMPRINTS_INVALID_API_KEY = Activity.RESULT_FIRST_USER + 1;
const val SIMPRINTS_COSYNC_EVENT = "events"
const val SIMPRINTS_COSYNC_SUBJECT_ACTIONS = "subjectActions"

@Deprecated(
"Use SIMPRINTS_ENROL_INTENT instead",
replaceWith = ReplaceWith("SIMPRINTS_ENROL_INTENT")
)
const val SIMPRINTS_REGISTER_INTENT = SIMPRINTS_ENROL_INTENT

@Deprecated(
"Use SIMPRINTS_CONFIRM_IDENTITY_INTENT instead",
replaceWith = ReplaceWith("SIMPRINTS_CONFIRM_IDENTITY_INTENT")
)
const val SIMPRINTS_SELECT_GUID_INTENT = SIMPRINTS_CONFIRM_IDENTITY_INTENT

@Deprecated(
"Use SIMPRINTS_ENROL_LAST_BIOMETRICS_INTENT instead",
replaceWith = ReplaceWith("SIMPRINTS_ENROL_LAST_BIOMETRICS_INTENT")
)
const val SIMPRINTS_REGISTER_LAST_BIOMETRICS_INTENT = SIMPRINTS_ENROL_LAST_BIOMETRICS_INTENT
}
3 changes: 1 addition & 2 deletions src/main/java/com/simprints/libsimprints/FingerIdentifier.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.simprints.libsimprints;
package com.simprints.libsimprints

@SuppressWarnings("unused")
enum class FingerIdentifier {
RIGHT_5TH_FINGER,
RIGHT_4TH_FINGER,
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/simprints/libsimprints/Identification.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.libsimprints;
package com.simprints.libsimprints

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
Expand All @@ -10,7 +10,6 @@ import kotlinx.parcelize.Parcelize
* @param confidence An int containing the (matching) confidence
* @param tier The tier score derived from the confidence
*/
@SuppressWarnings("unused")
@Parcelize
data class Identification(
val guid: String,
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/simprints/libsimprints/Metadata.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ data class Metadata(
* or it contains nested arrays or key/value mappings.
*/
constructor(jsonString: String) : this() {
if (jsonString.isBlank()) return

// Parse the JSON-encoded string
try {
json = JSONObject(jsonString)
} catch (e: JSONException) {
throw InvalidMetadataException("The metadata string is not a valid JSON object string.")
}
// Make sure the metadata string does not contain nested arrays or key-value mappings
val keys = json.keys();
val keys = json.keys()
while (keys.hasNext()) {
val key = keys.next();
val key = keys.next()
if (json.optJSONArray(key) != null || json.optJSONObject(key) != null)
throw InvalidMetadataException("Only boolean, string, integer and floating point values are allowed.");
throw InvalidMetadataException("Only boolean, string, integer and floating point values are allowed.")
}
}

Expand Down Expand Up @@ -81,9 +83,9 @@ data class Metadata(

private fun putObject(key: String, value: Any): Metadata {
try {
json.put(key, value);
json.put(key, value)
} catch (e: JSONException) {
throw RuntimeException(e);
throw RuntimeException(e)
}
return this
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/simprints/libsimprints/RefusalForm.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.simprints.libsimprints;
package com.simprints.libsimprints

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

@SuppressWarnings("WeakerAccess", "unused")
@Parcelize
data class RefusalForm(
val reason: String,
Expand Down
32 changes: 3 additions & 29 deletions src/main/java/com/simprints/libsimprints/Registration.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
package com.simprints.libsimprints;
package com.simprints.libsimprints

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

@SuppressWarnings("unused", "WeakerAccess")
@Parcelize
data class Registration @JvmOverloads constructor(
data class Registration(
val guid: String,
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 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) {
templates[fingerId] == (other.templates[fingerId] ?: return false)
}
return true;
}
}
) : Parcelable
8 changes: 7 additions & 1 deletion src/main/java/com/simprints/libsimprints/SimHelper.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.libsimprints;
package com.simprints.libsimprints

import android.content.Intent

Expand All @@ -18,6 +18,7 @@ import android.content.Intent
* @param userId identifies which user is making a request to Simprints ID. Can be any arbitrary String.
*/
@SuppressWarnings("unused", "WeakerAccess")
@Deprecated("Use SimprintsContract instead")
data class SimHelper(
private val projectId: String,
private val userId: String
Expand All @@ -31,6 +32,7 @@ data class SimHelper(
* @param metadata optional metadata to attach to the registration if provided.
* @return a new registration {@link Intent}.
*/
@Deprecated("Use SimprintsContract and SimprintsRequest.Enrol instead")
@JvmOverloads
fun register(
moduleId: String,
Expand All @@ -47,6 +49,7 @@ data class SimHelper(
* @param metadata optional metadata to attach to the identification if provided.
* @return a new identification {@link Intent}.
*/
@Deprecated("Use SimprintsContract and SimprintsRequest.Identify instead")
@JvmOverloads
fun identify(
moduleId: String,
Expand All @@ -64,6 +67,7 @@ data class SimHelper(
* @param metadata optional metadata to attach to the verification if provided.
* @return a new verification {@link Intent}.
*/
@Deprecated("Use SimprintsContract and SimprintsRequest.Verify instead")
@JvmOverloads
fun verify(
moduleId: String,
Expand All @@ -81,6 +85,7 @@ data class SimHelper(
* @param selectedGuid the GUID that was confirmed in the host app.
* @return a new confirm indentity {@link Intent}.
*/
@Deprecated("Use SimprintsContract and SimprintsRequest.ConfirmIdentity instead")
fun confirmIdentity(
sessionId: String,
selectedGuid: String,
Expand All @@ -99,6 +104,7 @@ data class SimHelper(
* @param metadata metadata to attach to the registration if provided.
* @return a new registration for last biometrics {@link Intent}.
*/
@Deprecated("Use SimprintsContract and SimprintsRequest.EnrolLastBiometric instead")
@JvmOverloads
fun registerLastBiometrics(
moduleId: String,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/simprints/libsimprints/Tier.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.libsimprints;
package com.simprints.libsimprints

enum class Tier {
TIER_1,
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/simprints/libsimprints/Verification.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import kotlinx.parcelize.Parcelize
* @param tier The tier score derived from the confidence
* @param guid Global unique id of the verified person
*/
@SuppressWarnings("unused", "WeakerAccess")
@Parcelize
data class Verification(
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()
Expand Down
Loading