diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 07a00f8..c53e412 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -17,7 +17,7 @@ android { val versionMajor = 2 val versionMinor = 0 - val versionPatch = 1 + val versionPatch = 2 val versionBuild = 0 defaultConfig { diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/BootReceiver.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/BootReceiver.kt index cdfeb19..78c146b 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/BootReceiver.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/BootReceiver.kt @@ -36,7 +36,7 @@ class BootReceiver : BroadcastReceiver() { Action.START, context, WireGuardConnectivityWatcherService::class.java, mapOf(context.resources.getString(R.string.tunnel_extras_key) to - defaultTunnel.id.toString()) + defaultTunnel.toString()) ) } } diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/ServiceTracker.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/ServiceTracker.kt index 9309a8a..9c885ec 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/ServiceTracker.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/ServiceTracker.kt @@ -6,8 +6,8 @@ import android.app.Service import android.content.Context import android.content.Context.ACTIVITY_SERVICE import android.content.Intent -import android.content.SharedPreferences -import com.zaneschepke.wireguardautotunnel.R +import com.google.firebase.crashlytics.ktx.crashlytics +import com.google.firebase.ktx.Firebase object ServiceTracker { @Suppress("DEPRECATION") @@ -31,7 +31,11 @@ object ServiceTracker { } } intent.component?.javaClass - application.startService(intent) + try { + application.startService(intent) + } catch (e : Exception) { + e.message?.let { Firebase.crashlytics.log(it) } + } } fun actionOnService(action: Action, context: Context, cls : Class, extras : Map? = null) { @@ -43,6 +47,10 @@ object ServiceTracker { } } intent.component?.javaClass - context.startService(intent) + try { + context.startService(intent) + } catch (e : Exception) { + e.message?.let { Firebase.crashlytics.log(it) } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/WireGuardConnectivityWatcherService.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/WireGuardConnectivityWatcherService.kt index dcf6497..3463189 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/WireGuardConnectivityWatcherService.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/WireGuardConnectivityWatcherService.kt @@ -161,6 +161,7 @@ class WireGuardConnectivityWatcherService : ForegroundService() { if(!isWifiConnected && vpnService.getState() == Tunnel.State.UP) stopVPN() Timber.d("Lost mobile data connection") } + else -> {} } } } @@ -200,6 +201,7 @@ class WireGuardConnectivityWatcherService : ForegroundService() { startVPN() } } + else -> {} } } } diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainViewModel.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainViewModel.kt index 5867670..91ea6cf 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainViewModel.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainViewModel.kt @@ -7,6 +7,7 @@ import android.net.Uri import android.provider.OpenableColumns import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.wireguard.config.BadConfigException import com.wireguard.config.Config import com.zaneschepke.wireguardautotunnel.R import com.zaneschepke.wireguardautotunnel.repository.Repository @@ -122,12 +123,18 @@ class MainViewModel @Inject constructor(private val application : Application, val stream = application.applicationContext.contentResolver.openInputStream(uri) stream ?: return val bufferReader = stream.bufferedReader(charset = Charsets.UTF_8) - val config = Config.parse(bufferReader) - val tunnelName = getNameFromFileName(fileName) - viewModelScope.launch { - tunnelRepo.save(TunnelConfig(name = tunnelName, wgQuick = config.toWgQuickString())) + try { + val config = Config.parse(bufferReader) + val tunnelName = getNameFromFileName(fileName) + viewModelScope.launch { + tunnelRepo.save(TunnelConfig(name = tunnelName, wgQuick = config.toWgQuickString())) + } + stream.close() + } catch(_: BadConfigException) { + viewModelScope.launch { + showSnackBarMessage(application.applicationContext.getString(R.string.bad_config)) + } } - stream.close() } @SuppressLint("Range") diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 80624fd..1879d0b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -57,4 +57,5 @@ No thanks Turn on Map + Bad config. Please try again. \ No newline at end of file