Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact duration and distance #123

Merged
merged 25 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions android/core/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
consumerProguardFiles 'consumer-rules.pro'
}

testOptions {
execution 'androidx_test_orchestrator'
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -42,6 +47,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestUtil 'androidx.test:orchestrator:1.2.0'

androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class JNIInterfaceBootstrappedTests {

@Test
fun recordTcn() {
val value = JniApi().recordTcn("2485a64b57addcaea3ed1b538d07dbce")
val value = JniApi().recordTcn("2485a64b57addcaea3ed1b538d07dbce", 34.03f)
assertEquals(JniVoidResult(1, ""), value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class JniApi {

external fun generateTcn(): String

external fun recordTcn(tcn: String): JniVoidResult
external fun recordTcn(tcn: String, distance: Float): JniVoidResult

// TODO test:
external fun setBreathlessnessCause(cause: String): JniVoidResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import org.coepi.core.domain.model.Tcn
import org.coepi.core.domain.common.Result

interface ObservedTcnsRecorder {
fun recordTcn(tcn: Tcn): Result<Unit, Throwable>
fun recordTcn(tcn: Tcn, distance: Float): Result<Unit, Throwable>
}

class ObservedTcnsRecorderImpl(private val api: JniApi) :
ObservedTcnsRecorder {
override fun recordTcn(tcn: Tcn): Result<Unit, Throwable> =
api.recordTcn(tcn.toHex()).asResult()
override fun recordTcn(tcn: Tcn, distance: Float): Result<Unit, Throwable> =
api.recordTcn(tcn.toHex(), distance).asResult()
}
13 changes: 8 additions & 5 deletions src/android/android_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ pub unsafe extern "C" fn Java_org_coepi_core_jni_JniApi_recordTcn(
env: JNIEnv,
_: JClass,
tcn: JString,
distance: jfloat,
) -> jobject {
recordTcn(&env, tcn).to_void_jni(&env)
recordTcn(&env, tcn, distance).to_void_jni(&env)
}

// NOTE: Returns directly success string
Expand Down Expand Up @@ -262,11 +263,13 @@ fn fetch_new_reports(env: &JNIEnv) -> Result<jobjectArray, ServicesError> {
alerts_to_jobject_array(result, &env)
}

fn recordTcn(env: &JNIEnv, tcn: JString) -> Result<(), ServicesError> {
fn recordTcn(env: &JNIEnv, tcn: JString, distance: jfloat) -> Result<(), ServicesError> {
let tcn_java_str = env.get_string(tcn)?;
let tcn_str = tcn_java_str.to_str()?;

let result = dependencies().observed_tcn_processor.save(tcn_str);
let result = dependencies()
.observed_tcn_processor
.save(tcn_str, distance as f32);
info!("Recording TCN result {:?}", result);

result
Expand Down Expand Up @@ -485,8 +488,8 @@ impl LogCallbackWrapper for LogCallbackWrapperImpl {
// Note that if we panic, LogCat will also not show a message, or location.
// TODO consider writing to file. Otherwise it's impossible to notice this.
Err(e) => println!(
"Couldn't get env: Can't send log: level: {}, text: {}",
level, text,
"Couldn't get env: Can't send log: level: {}, text: {}, e: {}",
level, text, e
),
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/ios/ios_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ pub unsafe extern "C" fn fetch_new_reports() -> CFStringRef {
}

#[no_mangle]
pub unsafe extern "C" fn record_tcn(c_tcn: *const c_char) -> CFStringRef {
pub unsafe extern "C" fn record_tcn(c_tcn: *const c_char, distance: f32) -> CFStringRef {
let tcn_str = cstring_to_str(&c_tcn);
let result = tcn_str.and_then(|tcn_str| dependencies().observed_tcn_processor.save(tcn_str));
let result = tcn_str.and_then(|tcn_str| {
dependencies()
.observed_tcn_processor
.save(tcn_str, distance)
});
info!("Recording TCN result {:?}", result);
return to_result_str(result);
}
Expand Down
Loading