diff options
| author | Albin <albin@mullvad.net> | 2024-08-26 15:48:37 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2024-09-06 14:59:55 +0200 |
| commit | 3847c1eb82a324a4b5fff2a5e076750ebf4449c4 (patch) | |
| tree | 55c45a4a75e56503e675fdad5418cbeafb850854 /android/service/src | |
| parent | d464325f98bc488f091ef18b4ba04e0d7dbe2605 (diff) | |
| download | mullvadvpn-3847c1eb82a324a4b5fff2a5e076750ebf4449c4.tar.xz mullvadvpn-3847c1eb82a324a4b5fff2a5e076750ebf4449c4.zip | |
Add daita grpc and ui
Diffstat (limited to 'android/service/src')
3 files changed, 30 insertions, 34 deletions
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt deleted file mode 100644 index 71a05e6743..0000000000 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt +++ /dev/null @@ -1,23 +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() - } -} diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt index 2db5a00fdb..ebdcbec780 100644 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt @@ -10,7 +10,6 @@ import androidx.core.content.getSystemService import androidx.lifecycle.lifecycleScope import arrow.atomic.AtomicInt import co.touchlab.kermit.Logger -import java.io.File import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.launch @@ -27,11 +26,13 @@ import net.mullvad.mullvadvpn.service.migration.MigrateSplitTunneling import net.mullvad.mullvadvpn.service.notifications.ForegroundNotificationManager import net.mullvad.mullvadvpn.service.notifications.NotificationChannelFactory import net.mullvad.mullvadvpn.service.notifications.NotificationManager +import net.mullvad.mullvadvpn.service.util.extractAndOverwriteIfAssetMoreRecent import net.mullvad.talpid.TalpidVpnService import org.koin.android.ext.android.getKoin import org.koin.core.context.loadKoinModules -private const val RELAYS_FILE = "relays.json" +private const val RELAY_LIST_ASSET_NAME = "relays.json" +private const val MAYBENOT_MACHINES_ASSET_NAME = "maybenot_machines" class MullvadVpnService : TalpidVpnService() { @@ -72,7 +73,7 @@ class MullvadVpnService : TalpidVpnService() { keyguardManager = getSystemService<KeyguardManager>()!! - prepareFiles(this@MullvadVpnService) + prepareFiles() migrateSplitTunneling.migrate() // If it is a debug build and we have an api override in the intent, use it @@ -221,16 +222,11 @@ class MullvadVpnService : TalpidVpnService() { return this?.action == SERVICE_INTERFACE } - private fun prepareFiles(context: Context) { - val shouldOverwriteRelayList = - lastUpdatedTime(context) > File(context.filesDir, RELAYS_FILE).lastModified() - - FileResourceExtractor(context).apply { extract(RELAYS_FILE, shouldOverwriteRelayList) } + private fun Context.prepareFiles() { + extractAndOverwriteIfAssetMoreRecent(RELAY_LIST_ASSET_NAME) + extractAndOverwriteIfAssetMoreRecent(MAYBENOT_MACHINES_ASSET_NAME) } - private fun lastUpdatedTime(context: Context): Long = - context.packageManager.getPackageInfo(context.packageName, 0).lastUpdateTime - companion object { init { System.loadLibrary("mullvad_jni") diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/util/ContextExtensions.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/util/ContextExtensions.kt new file mode 100644 index 0000000000..51240fa16d --- /dev/null +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/util/ContextExtensions.kt @@ -0,0 +1,23 @@ +package net.mullvad.mullvadvpn.service.util + +import android.content.Context +import java.io.File +import java.io.FileOutputStream + +fun Context.extractAndOverwriteIfAssetMoreRecent(assetName: String) { + val forceOverwriteIfMoreRecent = lastUpdatedTime() > File(filesDir, assetName).lastModified() + val destination = File(filesDir, assetName) + + if (!destination.exists() || forceOverwriteIfMoreRecent) { + extractFile(assetName, destination) + } +} + +private fun Context.lastUpdatedTime(): Long = + packageManager.getPackageInfo(packageName, 0).lastUpdateTime + +private fun Context.extractFile(asset: String, destination: File) { + val destinationStream = FileOutputStream(destination) + assets.open(asset).copyTo(destinationStream) + destinationStream.close() +} |
