Skip to content

Commit

Permalink
Adjust JNI
Browse files Browse the repository at this point in the history
  • Loading branch information
ivnsch committed Jul 16, 2020
1 parent e7c205c commit a8049aa
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class JNIInterfaceTests {
runnyNose = true,
other = false,
noSymptoms = true
), 1592567315
), 1592567315, 1592567335, 1.2f
)
),
value
Expand All @@ -75,7 +75,7 @@ class JNIInterfaceTests {
runnyNose = true,
other = false,
noSymptoms = true
), 1592567315
), 1592567315, 1592567335, 1.2f
),
JniAlert(
"343356", JniPublicReport(
Expand All @@ -90,7 +90,7 @@ class JNIInterfaceTests {
runnyNose = true,
other = false,
noSymptoms = true
), 1592567315
), 1592567315, 1592567335, 1.2f
)
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ data class Alert(
val runnyNose: Boolean,
val other: Boolean,
val noSymptoms: Boolean, // https://github.com/Co-Epi/app-ios/issues/268#issuecomment-645583717
var contactTime: UnixTime
var contactStart: UnixTime,
var contactEnd: UnixTime,
var minDistance: Float
) : Parcelable

enum class FeverSeverity {
Expand Down
4 changes: 3 additions & 1 deletion android/core/core/src/main/java/org/coepi/core/jni/JniApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ data class JniAlertsArrayResult(
data class JniAlert(
var id: String,
var report: JniPublicReport,
var contactTime: Long
var contactStart: Long,
var contactEnd: Long,
var minDistance: Float
)

data class JniPublicReport(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,17 @@ class AlertsFetcherImpl(private val api: JniApi) :

private fun JniAlert.toAlert() = Alert(
id = id,
contactTime = when {
contactTime < 0 -> error("Invalid contact time: $contactTime")
else -> UnixTime.fromValue(contactTime)
contactStart = when {
contactStart < 0 -> error("Invalid contact start: $contactStart")
else -> UnixTime.fromValue(contactStart)
},
contactEnd = when {
contactEnd < 0 -> error("Invalid contact end: $contactEnd")
else -> UnixTime.fromValue(contactEnd)
},
minDistance = when {
minDistance < 0 -> error("Invalid min distance: $minDistance")
else -> minDistance
},
reportTime = when {
report.reportTime < 0 -> error("Invalid report time: ${report.reportTime}")
Expand Down
18 changes: 14 additions & 4 deletions src/android/android_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,9 @@ fn placeholder_alert() -> Alert {
Alert {
id: "0".to_owned(),
report,
contact_time: 0,
contact_start: 0,
contact_end: 0,
min_distance: 0.0,
}
}

Expand Down Expand Up @@ -630,16 +632,20 @@ pub fn alert_to_jobject(alert: Alert, env: &JNIEnv) -> Result<jobject, ServicesE
let id_j_string = env.new_string(alert.id)?;
let id_j_value = JValue::from(JObject::from(id_j_string));

let earliest_time_j_value = JValue::from(alert.contact_time as i64);
let contact_start_j_value = JValue::from(alert.contact_start as i64);
let contact_end_j_value = JValue::from(alert.contact_end as i64);
let min_distance_j_value = JValue::from(alert.min_distance);

let result: Result<jobject, jni::errors::Error> = env
.new_object(
jni_alert_class,
"(Ljava/lang/String;Lorg/coepi/core/jni/JniPublicReport;J)V",
"(Ljava/lang/String;Lorg/coepi/core/jni/JniPublicReport;JJF)V",
&[
id_j_value,
JValue::from(jni_public_report_obj),
earliest_time_j_value,
contact_start_j_value,
contact_end_j_value,
min_distance_j_value,
],
)
.map(|o| o.into_inner());
Expand Down Expand Up @@ -685,6 +691,10 @@ impl JniErrorMappable for ServicesError {
status: 5,
message: msg.to_owned(),
},
ServicesError::NotFound => JniError {
status: 6,
message: "Not found".to_owned(),
},
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/android/jni_domain_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ fn create_test_alert(id: &str, report_time: u64) -> Alert {
Alert {
id: id.to_owned(),
report,
contact_time: 1592567315,
contact_start: 1592567315,
contact_end: 1592567335,
min_distance: 1.2,
}
}

0 comments on commit a8049aa

Please sign in to comment.