diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-22 11:04:00 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-22 11:04:00 -0300 |
| commit | b8b36573ed691c704044dff9f22774337a44879d (patch) | |
| tree | af6ce3d69f484426cfd4ac2cee2150c871b1036b /android | |
| parent | 106937e21d66b19a9a291e7014b9f81a412e9933 (diff) | |
| parent | b18ab26965d4b7cff95e950995bec53ebff5c47e (diff) | |
| download | mullvadvpn-b8b36573ed691c704044dff9f22774337a44879d.tar.xz mullvadvpn-b8b36573ed691c704044dff9f22774337a44879d.zip | |
Merge branch 'dynamic-app-path'
Diffstat (limited to 'android')
6 files changed, 67 insertions, 22 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 40e93ff882..66a55503d6 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt @@ -7,9 +7,11 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.async -const val PROBLEM_REPORT_PATH = "/data/data/net.mullvad.mullvadvpn/problem_report.txt" +const val PROBLEM_REPORT_FILE = "problem_report.txt" + +class MullvadProblemReport(val logDirectory: File) { + private val problemReportPath = File(logDirectory, PROBLEM_REPORT_FILE) -class MullvadProblemReport { private var collectJob: Deferred<Boolean>? = null private var sendJob: Deferred<Boolean>? = null @@ -38,7 +40,7 @@ class MullvadProblemReport { if (!isActive) { collectJob = GlobalScope.async(Dispatchers.Default) { deleteReportFile() - collectReport(PROBLEM_REPORT_PATH) + collectReport(logDirectory.absolutePath, problemReportPath.absolutePath) } } } @@ -51,7 +53,11 @@ class MullvadProblemReport { if (currentJob == null || currentJob.isCompleted) { currentJob = GlobalScope.async(Dispatchers.Default) { val result = (collectJob?.await() ?: false) && - sendProblemReport(userEmail, userMessage, PROBLEM_REPORT_PATH) + sendProblemReport( + userEmail, + userMessage, + problemReportPath.absolutePath + ) if (result) { deleteReportFile() @@ -68,10 +74,10 @@ class MullvadProblemReport { } fun deleteReportFile() { - File(PROBLEM_REPORT_PATH).delete() + problemReportPath.delete() } - private external fun collectReport(reportPath: String): Boolean + private external fun collectReport(logDirectory: String, reportPath: String): Boolean private external fun sendProblemReport( userEmail: String, userMessage: String, diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileMigrator.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileMigrator.kt new file mode 100644 index 0000000000..cd325d8a6f --- /dev/null +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileMigrator.kt @@ -0,0 +1,18 @@ +package net.mullvad.mullvadvpn.service + +import android.util.Log +import java.io.File + +class FileMigrator(val oldDirectory: File, val newDirectory: File) { + fun migrate(fileName: String) { + try { + val oldPath = File(oldDirectory, fileName) + + if (oldPath.exists()) { + oldPath.renameTo(File(newDirectory, fileName)) + } + } catch (exception: Exception) { + Log.w("mullvad", "Failed to migrate $fileName from $oldDirectory to $newDirectory") + } + } +} diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt index aac6175ec6..1ab65fa850 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt @@ -4,14 +4,16 @@ import android.content.Context import java.io.File import java.io.FileOutputStream -class FileResourceExtractor(val asset: String, val destination: String) { - fun extract(context: Context) { - if (!File(destination).exists()) { - extractFile(context) +class FileResourceExtractor(val context: Context) { + fun extract(asset: String) { + val destination = File(context.filesDir, asset) + + if (!destination.exists()) { + extractFile(asset, destination) } } - private fun extractFile(context: Context) { + private fun extractFile(asset: String, destination: File) { val destinationStream = FileOutputStream(destination) context diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt index 60dce6ff10..9c34ecb5d7 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt @@ -24,7 +24,7 @@ class MullvadDaemon(val vpnService: MullvadVpnService) { init { System.loadLibrary("mullvad_jni") - initialize(vpnService) + initialize(vpnService, vpnService.cacheDir.absolutePath, vpnService.filesDir.absolutePath) onSettingsChange.notify(getSettings()) } @@ -113,7 +113,11 @@ class MullvadDaemon(val vpnService: MullvadVpnService) { return verifyWireguardKey(daemonInterfaceAddress) } - private external fun initialize(vpnService: MullvadVpnService) + private external fun initialize( + vpnService: MullvadVpnService, + cacheDirectory: String, + resourceDirectory: String + ) private external fun deinitialize() private external fun connect(daemonInterfaceAddress: Long) diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt index 4df3ff6791..aba89e9e8a 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.VpnService import android.os.Binder import android.os.IBinder +import java.io.File import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job @@ -14,10 +15,7 @@ import net.mullvad.talpid.TalpidVpnService import net.mullvad.talpid.util.EventNotifier private const val API_ROOT_CA_FILE = "api_root_ca.pem" -private const val API_ROOT_CA_PATH = "/data/data/net.mullvad.mullvadvpn/api_root_ca.pem" - private const val RELAYS_FILE = "relays.json" -private const val RELAYS_PATH = "/data/data/net.mullvad.mullvadvpn/relays.json" class MullvadVpnService : TalpidVpnService() { private enum class PendingAction { @@ -144,11 +142,7 @@ class MullvadVpnService : TalpidVpnService() { } private fun startDaemon() = GlobalScope.launch(Dispatchers.Default) { - FileResourceExtractor(API_ROOT_CA_FILE, API_ROOT_CA_PATH) - .extract(application) - - FileResourceExtractor(RELAYS_FILE, RELAYS_PATH) - .extract(application) + prepareFiles() val newDaemon = MullvadDaemon(this@MullvadVpnService).apply { onSettingsChange.subscribe { settings -> @@ -191,6 +185,23 @@ class MullvadVpnService : TalpidVpnService() { )) } + private fun prepareFiles() { + FileMigrator(File("/data/data/net.mullvad.mullvadvpn"), filesDir).apply { + migrate(API_ROOT_CA_FILE) + migrate(RELAYS_FILE) + migrate("settings.json") + migrate("daemon.log") + migrate("daemon.old.log") + migrate("wireguard.log") + migrate("wireguard.old.log") + } + + FileResourceExtractor(this).apply { + extract(API_ROOT_CA_FILE) + extract(RELAYS_FILE) + } + } + private fun stop() { isStopping = true stopDaemon() 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 93b85c001b..524d4ab00d 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt @@ -19,9 +19,10 @@ 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 serviceConnectionSubscription: Int? = null @@ -64,6 +65,9 @@ class MainActivity : FragmentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + + problemReport = MullvadProblemReport(filesDir) + setContentView(R.layout.main) if (savedInstanceState == null) { |
