Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-mullvad committed Aug 28, 2024
1 parent b5e5006 commit 0eaf1a6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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.AssetToFilesDirExtractor
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
Expand Down Expand Up @@ -231,10 +231,8 @@ class MullvadVpnService : TalpidVpnService() {
}

private fun Context.prepareFiles() {
AssetToFilesDirExtractor(this).apply {
extract(RELAY_LIST_ASSET_NAME, overwriteFileIfAssetMoreRecent = true)
extract(MAYBENOT_MACHINES_ASSET_NAME, overwriteFileIfAssetMoreRecent = true)
}
extractAndOverwriteIfAssetMoreRecent(RELAY_LIST_ASSET_NAME)
extractAndOverwriteIfAssetMoreRecent(MAYBENOT_MACHINES_ASSET_NAME)
}

companion object {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 0eaf1a6

Please sign in to comment.