diff options
| -rw-r--r-- | CHANGELOG.md | 4 | ||||
| -rw-r--r-- | android/build.gradle | 5 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt (renamed from android/src/main/kotlin/net/mullvad/mullvadvpn/service/ApiRootCaFile.kt) | 11 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt | 12 | ||||
| -rwxr-xr-x | build-apk.sh | 2 | ||||
| -rwxr-xr-x | build.sh | 22 | ||||
| -rwxr-xr-x | update-relays.sh | 23 |
7 files changed, 48 insertions, 31 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index c97c0c449e..527360851a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,10 @@ Line wrap the file at 100 chars. Th ### Removed - Remove city/country labels on map in the desktop app. +#### Android +- Include an initial relay list in the APK so that the app can connect to the VPN even if it fails + to connect to the API after it is installed. + ### Fixed - Fix app sometimes getting stuck in connecting state when using WireGuard. diff --git a/android/build.gradle b/android/build.gradle index 0e41b32f69..7648e212ab 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -59,7 +59,7 @@ android { applicationVariants.all { variant -> variant.mergeAssetsProvider.configure { - dependsOn copyApiRootCertificate + dependsOn copyExtraAssets } } } @@ -108,8 +108,9 @@ task format(type: FormatTask, group: 'formatting') { lint.dependsOn lintKotlin -task copyApiRootCertificate(type: Copy) { +task copyExtraAssets(type: Copy) { from "$repoRootPath/dist-assets" include "api_root_ca.pem" + include "relays.json" into extraAssetsDirectory } diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ApiRootCaFile.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt index 0322d767a0..aac6175ec6 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ApiRootCaFile.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt @@ -4,17 +4,14 @@ import android.content.Context import java.io.File import java.io.FileOutputStream -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" - -class ApiRootCaFile { +class FileResourceExtractor(val asset: String, val destination: String) { fun extract(context: Context) { - if (!File(API_ROOT_CA_PATH).exists()) { - extractFile(context, API_ROOT_CA_FILE, API_ROOT_CA_PATH) + if (!File(destination).exists()) { + extractFile(context) } } - private fun extractFile(context: Context, asset: String, destination: String) { + private fun extractFile(context: Context) { val destinationStream = FileOutputStream(destination) context 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 b903d35045..cdfdbac287 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt @@ -12,6 +12,12 @@ import net.mullvad.mullvadvpn.dataproxy.ConnectionProxy 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 val binder = LocalBinder() private val serviceNotifier = EventNotifier<ServiceInstance?>(null) @@ -110,7 +116,11 @@ class MullvadVpnService : TalpidVpnService() { } private fun startDaemon() = GlobalScope.launch(Dispatchers.Default) { - ApiRootCaFile().extract(application) + FileResourceExtractor(API_ROOT_CA_FILE, API_ROOT_CA_PATH) + .extract(application) + + FileResourceExtractor(RELAYS_FILE, RELAYS_PATH) + .extract(application) val newDaemon = MullvadDaemon(this@MullvadVpnService).apply { onSettingsChange.subscribe { settings -> diff --git a/build-apk.sh b/build-apk.sh index f0de050bc6..b8c9fa6f18 100755 --- a/build-apk.sh +++ b/build-apk.sh @@ -84,6 +84,8 @@ for ARCHITECTURE in $ARCHITECTURES; do cp "$SCRIPT_DIR/target/$TARGET/$BUILD_TYPE/libmullvad_jni.so" "$SCRIPT_DIR/android/build/extraJni/$ABI/" done +./update-relays.sh + cd "$SCRIPT_DIR/android" ./gradlew --console plain "$GRADLE_TASK" @@ -190,27 +190,7 @@ if [[ "$BUILD_MODE" == "release" && "$(uname -s)" == "MINGW"* ]]; then fi -echo "Updating relay list..." -set +e -read -d '' JSONRPC_CODE <<-JSONRPC_CODE -var buff = ""; -process.stdin.on('data', function (chunk) { - buff += chunk; -}) -process.stdin.on('end', function () { - var obj = JSON.parse(buff); - var output = JSON.stringify(obj.result, null, ' '); - process.stdout.write(output); -}) -JSONRPC_CODE -set -e - -JSONRPC_RESPONSE="$(curl -X POST \ - --fail \ - -H "Content-Type: application/json" \ - -d '{"jsonrpc": "2.0", "id": "0", "method": "relay_list_v3"}' \ - https://api.mullvad.net/rpc/)" -echo $JSONRPC_RESPONSE | node -e "$JSONRPC_CODE" > dist-assets/relays.json +./update-relays.sh pushd "$SCRIPT_DIR/gui" diff --git a/update-relays.sh b/update-relays.sh new file mode 100755 index 0000000000..711afe342a --- /dev/null +++ b/update-relays.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +echo "Updating relay list..." +set +e +read -d '' JSONRPC_CODE <<-JSONRPC_CODE +var buff = ""; +process.stdin.on('data', function (chunk) { + buff += chunk; +}) +process.stdin.on('end', function () { + var obj = JSON.parse(buff); + var output = JSON.stringify(obj.result, null, ' '); + process.stdout.write(output); +}) +JSONRPC_CODE +set -e + +JSONRPC_RESPONSE="$(curl -X POST \ + --fail \ + -H "Content-Type: application/json" \ + -d '{"jsonrpc": "2.0", "id": "0", "method": "relay_list_v3"}' \ + https://api.mullvad.net/rpc/)" +echo $JSONRPC_RESPONSE | node -e "$JSONRPC_CODE" > dist-assets/relays.json |
