summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
Diffstat (limited to 'android')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt35
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt5
2 files changed, 30 insertions, 10 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 66a55503d6..97e6559bd4 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt
@@ -5,15 +5,22 @@ import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.Job
import kotlinx.coroutines.async
+import kotlinx.coroutines.launch
const val PROBLEM_REPORT_FILE = "problem_report.txt"
-class MullvadProblemReport(val logDirectory: File) {
- private val problemReportPath = File(logDirectory, PROBLEM_REPORT_FILE)
+class MullvadProblemReport {
+ val logDirectory = CompletableDeferred<File>()
+
+ private val problemReportPath = GlobalScope.async(Dispatchers.Default) {
+ File(logDirectory.await(), PROBLEM_REPORT_FILE)
+ }
private var collectJob: Deferred<Boolean>? = null
private var sendJob: Deferred<Boolean>? = null
+ private var deleteJob: Job? = null
var confirmNoEmail: CompletableDeferred<Boolean>? = null
@@ -39,8 +46,11 @@ class MullvadProblemReport(val logDirectory: File) {
synchronized(this) {
if (!isActive) {
collectJob = GlobalScope.async(Dispatchers.Default) {
- deleteReportFile()
- collectReport(logDirectory.absolutePath, problemReportPath.absolutePath)
+ val logDirectoryPath = logDirectory.await().absolutePath
+ val reportPath = problemReportPath.await().absolutePath
+
+ deleteReportFile().join()
+ collectReport(logDirectoryPath, reportPath)
}
}
}
@@ -56,7 +66,7 @@ class MullvadProblemReport(val logDirectory: File) {
sendProblemReport(
userEmail,
userMessage,
- problemReportPath.absolutePath
+ problemReportPath.await().absolutePath
)
if (result) {
@@ -73,8 +83,19 @@ class MullvadProblemReport(val logDirectory: File) {
}
}
- fun deleteReportFile() {
- problemReportPath.delete()
+ fun deleteReportFile(): Job {
+ synchronized(this) {
+ val oldDeleteJob = deleteJob
+
+ val job = GlobalScope.launch(Dispatchers.Default) {
+ oldDeleteJob?.join()
+ problemReportPath.await().delete()
+ }
+
+ deleteJob = job
+
+ return job
+ }
}
private external fun collectReport(logDirectory: String, reportPath: String): Boolean
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt
index d3fca15be7..a4595a9a92 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt
@@ -20,10 +20,9 @@ class MainActivity : FragmentActivity() {
val KEY_SHOULD_CONNECT = "should_connect"
}
+ val problemReport = MullvadProblemReport()
val serviceNotifier = EventNotifier<ServiceConnection?>(null)
- lateinit var problemReport: MullvadProblemReport
-
private var service: MullvadVpnService.LocalBinder? = null
private var serviceConnection: ServiceConnection? = null
private var shouldConnect = false
@@ -60,7 +59,7 @@ class MainActivity : FragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- problemReport = MullvadProblemReport(filesDir)
+ problemReport.logDirectory.complete(filesDir)
setContentView(R.layout.main)