diff options
| author | Albin <albin@mullvad.net> | 2023-03-16 14:17:41 +0100 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2023-03-16 14:17:41 +0100 |
| commit | 29bae837be48e317bb9bc0644f886feb01dab4be (patch) | |
| tree | 0704422d0edf8731c80b9881dfeb0ca336769cf8 /android | |
| parent | f5c0eca530eef397ec64736b13e1fed241813fe8 (diff) | |
| parent | d0dac0017275ee885efa89aa664aa73fa4c992df (diff) | |
| download | mullvadvpn-29bae837be48e317bb9bc0644f886feb01dab4be.tar.xz mullvadvpn-29bae837be48e317bb9bc0644f886feb01dab4be.zip | |
Merge branch 'remove-config-migration-droid-16'
Diffstat (limited to 'android')
4 files changed, 2 insertions, 86 deletions
diff --git a/android/app/lint-baseline.xml b/android/app/lint-baseline.xml index c0c2084b9d..2887f5fccb 100644 --- a/android/app/lint-baseline.xml +++ b/android/app/lint-baseline.xml @@ -178,17 +178,6 @@ </issue> <issue - id="SdCardPath" - message="Do not hardcode "`/data/`"; use `Context.getFilesDir().getPath()` instead" - errorLine1=" FileMigrator(File("/data/data/net.mullvad.mullvadvpn"), vpnService.filesDir).apply {" - errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> - <location - file="src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt" - line="77" - column="28"/> - </issue> - - <issue id="RedundantLabel" message="Redundant label can be removed" errorLine1=" android:label="@string/app_name"" diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt index 67ec721a52..7175765e9f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt @@ -1,6 +1,5 @@ package net.mullvad.mullvadvpn.service -import java.io.File import kotlin.properties.Delegates.observable import kotlin.reflect.KClass import kotlin.reflect.safeCast @@ -14,10 +13,8 @@ import kotlinx.coroutines.channels.trySendBlocking import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpointConfiguration import net.mullvad.mullvadvpn.util.Intermittent -private const val RELAYS_FILE = "relays.json" - class DaemonInstance( - val vpnService: MullvadVpnService + private val vpnService: MullvadVpnService ) { sealed class Command { data class Start(val apiEndpointConfiguration: ApiEndpointConfiguration) : Command() @@ -45,11 +42,9 @@ class DaemonInstance( intermittentDaemon.onDestroy() } - private fun spawnActor() = GlobalScope.actor<Command>(Dispatchers.Default, Channel.UNLIMITED) { + private fun spawnActor() = GlobalScope.actor(Dispatchers.Default, Channel.UNLIMITED) { var isRunning = true - prepareFiles() - while (isRunning) { val startCommand = waitForCommand(channel, Command.Start::class) ?: break startDaemon(startCommand.apiEndpointConfiguration) @@ -73,24 +68,6 @@ class DaemonInstance( } } - private fun prepareFiles() { - FileMigrator(File("/data/data/net.mullvad.mullvadvpn"), vpnService.filesDir).apply { - migrate(RELAYS_FILE) - migrate("settings.json") - migrate("daemon.log") - migrate("daemon.old.log") - migrate("wireguard.log") - migrate("wireguard.old.log") - } - - val shouldOverwriteRelayList = - lastUpdatedTime() > File(vpnService.filesDir, RELAYS_FILE).lastModified() - - FileResourceExtractor(vpnService).apply { - extract(RELAYS_FILE, shouldOverwriteRelayList) - } - } - private suspend fun startDaemon( apiEndpointConfiguration: ApiEndpointConfiguration ) { @@ -108,10 +85,4 @@ class DaemonInstance( private fun stopDaemon() { daemon?.shutdown() } - - private fun lastUpdatedTime(): Long { - return vpnService.run { - packageManager.getPackageInfo(packageName, 0).lastUpdateTime - } - } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/FileMigrator.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/FileMigrator.kt deleted file mode 100644 index cd325d8a6f..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/FileMigrator.kt +++ /dev/null @@ -1,18 +0,0 @@ -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/app/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt deleted file mode 100644 index 34ca0eaa89..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt +++ /dev/null @@ -1,26 +0,0 @@ -package net.mullvad.mullvadvpn.service - -import android.content.Context -import java.io.File -import java.io.FileOutputStream - -class FileResourceExtractor(val context: Context) { - fun extract(asset: String, force: Boolean = false) { - val destination = File(context.filesDir, asset) - - if (!destination.exists() || force) { - extractFile(asset, destination) - } - } - - private fun extractFile(asset: String, destination: File) { - val destinationStream = FileOutputStream(destination) - - context - .assets - .open(asset) - .copyTo(destinationStream) - - destinationStream.close() - } -} |
