diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-01-24 11:15:52 +0100 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-01-28 10:35:15 +0100 |
| commit | 1fd061cc62fa0b3deb56302d8d74d513345c3037 (patch) | |
| tree | be88797d5613567c2e1806fbbf82d438bd720dc3 /android/service/src | |
| parent | 95e51f000f8259dfb3e5966831bd102937e6e935 (diff) | |
| download | mullvadvpn-1fd061cc62fa0b3deb56302d8d74d513345c3037.tar.xz mullvadvpn-1fd061cc62fa0b3deb56302d8d74d513345c3037.zip | |
Bundle a pre-generated relay list instead of generating one
The android app will try to bundle the relays.json
found under dist-assets/relays/ if it exists.
Otherwise it will rely on the relay list
downloaded by the api.
For alpha, beta and stable release builds it is required
to have a bundled relays.json file.
Diffstat (limited to 'android/service/src')
| -rw-r--r-- | android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt | 5 | ||||
| -rw-r--r-- | android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/util/ContextExtensions.kt | 20 |
2 files changed, 18 insertions, 7 deletions
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 e4c8eba3c6..3c26ad89de 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 @@ -220,7 +220,10 @@ class MullvadVpnService : TalpidVpnService() { } private fun Context.prepareFiles() { - extractAndOverwriteIfAssetMoreRecent(RELAY_LIST_ASSET_NAME) + extractAndOverwriteIfAssetMoreRecent( + RELAY_LIST_ASSET_NAME, + BuildConfig.REQUIRE_BUNDLED_RELAY_FILE, + ) } companion object { 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 index 51240fa16d..b4d50caa25 100644 --- 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 @@ -1,23 +1,31 @@ package net.mullvad.mullvadvpn.service.util import android.content.Context +import co.touchlab.kermit.Logger import java.io.File +import java.io.FileNotFoundException import java.io.FileOutputStream -fun Context.extractAndOverwriteIfAssetMoreRecent(assetName: String) { +fun Context.extractAndOverwriteIfAssetMoreRecent(assetName: String, requireAssetFile: Boolean) { val forceOverwriteIfMoreRecent = lastUpdatedTime() > File(filesDir, assetName).lastModified() val destination = File(filesDir, assetName) if (!destination.exists() || forceOverwriteIfMoreRecent) { - extractFile(assetName, destination) + extractFile(assetName, destination, requireAssetFile) } } 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() +private fun Context.extractFile(asset: String, destination: File, requireAssetFile: Boolean) { + if (assets.list("")?.contains(asset) == true) { + val destinationStream = FileOutputStream(destination) + assets.open(asset).copyTo(destinationStream) + destinationStream.close() + } else if (requireAssetFile) { + throw FileNotFoundException("Asset $asset not found") + } else { + Logger.i("Asset $asset not found") + } } |
