summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-06-18 11:20:06 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-06-24 11:35:21 +0000
commit12810e18236d3a00b4f590394c5954d05b1c411f (patch)
tree9365b354c672d1f25c0236b07cbe48cc6b25abf4 /android/src
parent394ff5731596832362756a89325214ebd2115883 (diff)
downloadmullvadvpn-12810e18236d3a00b4f590394c5954d05b1c411f.tar.xz
mullvadvpn-12810e18236d3a00b4f590394c5954d05b1c411f.zip
Add `MullvadProblemReport::send` async method
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt39
1 files changed, 36 insertions, 3 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt
index fc3b45ee88..e886f6d237 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt
@@ -11,19 +11,29 @@ const val PROBLEM_REPORT_PATH = "/data/data/net.mullvad.mullvadvpn/problem_repor
class MullvadProblemReport {
private var collectJob: Deferred<Boolean>? = null
+ private var sendJob: Deferred<Boolean>? = null
var userEmail = ""
var userMessage = ""
+ val isActive: Boolean
+ get() {
+ synchronized(this) {
+ val collectJob = this.collectJob
+ val sendJob = this.sendJob
+
+ return (collectJob != null && collectJob.isActive) ||
+ (sendJob != null && sendJob.isActive)
+ }
+ }
+
init {
System.loadLibrary("mullvad_jni")
}
fun collect() {
synchronized(this) {
- val currentJob = collectJob
-
- if (currentJob == null || currentJob.isCompleted) {
+ if (!isActive) {
collectJob = GlobalScope.async(Dispatchers.Default) {
deleteReportFile()
collectReport(PROBLEM_REPORT_PATH)
@@ -32,6 +42,29 @@ class MullvadProblemReport {
}
}
+ fun send(): Deferred<Boolean> {
+ synchronized(this) {
+ var currentJob = sendJob
+
+ if (currentJob == null || currentJob.isCompleted) {
+ currentJob = GlobalScope.async(Dispatchers.Default) {
+ val result = (collectJob?.await() ?: false) &&
+ sendProblemReport(userEmail, userMessage, PROBLEM_REPORT_PATH)
+
+ if (result) {
+ deleteReportFile()
+ }
+
+ result
+ }
+
+ sendJob = currentJob
+ }
+
+ return currentJob
+ }
+ }
+
private fun deleteReportFile() {
File(PROBLEM_REPORT_PATH).delete()
}