Skip to content

Commit

Permalink
Add report id to android alerts (#141)
Browse files Browse the repository at this point in the history
* Add report id to Android alert

* Add jarRepositories.xml to gitignore
  • Loading branch information
ivnsch authored Jul 30, 2020
1 parent d474cc9 commit 2c58dcc
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions android/core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ captures/
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/jarRepositories.xml
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class JNIInterfaceTests {
assertEquals(
JniOneAlertResult(
1, "", JniAlert(
"123", JniPublicSymptoms(
"123", "224", JniPublicSymptoms(
reportTime = 234324,
earliestSymptomTime = 1590356601,
feverSeverity = 1,
Expand All @@ -63,7 +63,7 @@ class JNIInterfaceTests {
JniAlertsArrayResult(
1, "", arrayOf(
JniAlert(
"123", JniPublicSymptoms(
"123", "224", JniPublicSymptoms(
reportTime = 131321,
earliestSymptomTime = 1590356601,
feverSeverity = 1,
Expand All @@ -78,7 +78,7 @@ class JNIInterfaceTests {
), 1592567315, 1592567335, 1.2f, 2.1f, false
),
JniAlert(
"343356", JniPublicSymptoms(
"343356", "224", JniPublicSymptoms(
reportTime = 32516899200,
earliestSymptomTime = 1590356601,
feverSeverity = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.android.parcel.Parcelize
@Parcelize
data class Alert(
var id: String,
var reportId: String,
val reportTime: UnixTime,
val earliestSymptomTime: UserInput<UnixTime>,
val feverSeverity: FeverSeverity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ data class JniAlertsArrayResult(

data class JniAlert(
var id: String,
var reportId: String,
var symptoms: JniPublicSymptoms,
var contactStart: Long,
var contactEnd: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class AlertsFetcherImpl(private val api: JniApi) :

private fun JniAlert.toAlert() = Alert(
id = id,
reportId = reportId,
contactStart = when {
contactStart < 0 -> error("Invalid contact start: $contactStart")
else -> UnixTime.fromValue(contactStart)
Expand Down
5 changes: 4 additions & 1 deletion src/android/android_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,8 @@ 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 report_id_j_string = env.new_string(alert.report_id)?;
let report_id_j_value = JValue::from(JObject::from(report_id_j_string));

let contact_start_j_value = JValue::from(alert.contact_start as i64);
let contact_end_j_value = JValue::from(alert.contact_end as i64);
Expand All @@ -676,9 +678,10 @@ pub fn alert_to_jobject(alert: Alert, env: &JNIEnv) -> Result<jobject, ServicesE
let result: Result<jobject, jni::errors::Error> = env
.new_object(
jni_alert_class,
"(Ljava/lang/String;Lorg/coepi/core/jni/JniPublicSymptoms;JJFFZ)V",
"(Ljava/lang/String;Ljava/lang/String;Lorg/coepi/core/jni/JniPublicSymptoms;JJFFZ)V",
&[
id_j_value,
report_id_j_value,
JValue::from(jni_public_symptoms_obj),
contact_start_j_value,
contact_end_j_value,
Expand Down
2 changes: 1 addition & 1 deletion src/android/jni_domain_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn create_test_alert(id: &str, report_time: u64) -> Alert {

Alert {
id: id.to_owned(),
report_id: id.to_owned(), // re-use alert id, not particular reason other than we don't need separate id for now
report_id: "224".to_owned(),
symptoms,
contact_start: 1592567315,
contact_end: 1592567335,
Expand Down

0 comments on commit 2c58dcc

Please sign in to comment.