Compare commits

..

16 Commits

Author SHA1 Message Date
dependabot[bot] 756d7cbea0 chore(deps): bump actions/setup-java from 4 to 5
Bumps [actions/setup-java](https://github.com/actions/setup-java) from 4 to 5.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](https://github.com/actions/setup-java/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-21 13:17:07 +00:00
Zane Schepke 8a3d781bb3 fix: standalone can accidentally install fdroid version, progress indicator bug 2025-08-14 02:06:00 -04:00
Zane Schepke 99cd1d917a chore: bump version with notes 2025-08-14 01:10:58 -04:00
Zane Schepke 7940b97329 fix: edit tunnel save config name append bug 2025-08-14 00:31:44 -04:00
Zane Schepke 99419ebe9f fix: allow ping target to override all defaults 2025-08-12 21:57:58 -04:00
Zane Schepke 3e2ffc1b64 fix: tunnel re-establish bug
closes #881
2025-08-12 16:01:43 -04:00
Zane Schepke 5d8fb38906 fix: uapi socket connection with support for dynamic packages 2025-08-09 19:21:40 -04:00
Zane Schepke 6d100a2f46 fix: kill switch stuck on bug 2025-08-09 02:19:30 -04:00
Zane Schepke 5feb2827fd refactor: share import save logic 2025-08-08 19:37:01 -04:00
Zane Schepke 0336c2ac9f fix: duplicate tunnel names overwrite bug
closes #886
2025-08-08 19:33:49 -04:00
Zane Schepke 96d8114d37 fix: split tunneling for AndroidTV only apps typo
#805
2025-08-08 17:20:53 -04:00
Zane Schepke e78469c730 fix: split tunneling for AndroidTV only apps
closes #805
2025-08-08 16:46:58 -04:00
dependabot[bot] 6f365a4490 chore(deps): bump actions/download-artifact from 4 to 5 (#884)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-08 16:20:16 -04:00
Zane Schepke 2885d1a539 fix: ping target empty bug 2025-08-08 16:03:19 -04:00
Zane Schepke c56b11599f ci: fix debug build path 2025-08-08 15:28:51 -04:00
Zane Schepke 753575c50d chore: gradle checksum 2025-08-08 15:12:15 -04:00
30 changed files with 232 additions and 205 deletions
+7 -2
View File
@@ -76,7 +76,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '17'
@@ -118,6 +118,11 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: android_artifacts_${{ inputs.flavor }}
path: app/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/wgtunnel-${{ inputs.flavor }}${{ inputs.flavor == 'fdroid' && '-release' || '' }}-*.apk
path: >-
app/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/${{
inputs.flavor == 'fdroid' && inputs.build_type == 'release'
&& 'wgtunnel-fdroid-release-*.apk'
|| format('wgtunnel-{0}-v*.apk', inputs.flavor)
}}
retention-days: 1
if-no-files-found: warn
+1 -1
View File
@@ -69,7 +69,7 @@ jobs:
run: mkdir ${{ github.workspace }}/temp
- name: Download artifacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@v5
with:
pattern: android_artifacts_*
path: ${{ github.workspace }}/temp
+1 -1
View File
@@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '17'
+2 -2
View File
@@ -108,7 +108,7 @@ jobs:
run: mkdir ${{ github.workspace }}/temp
- name: Download artifacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@v5
with:
pattern: android_artifacts_*
path: ${{ github.workspace }}/temp
@@ -191,7 +191,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '17'
+4
View File
@@ -47,6 +47,10 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent>
<intent>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent>
</queries>
<application
android:name=".WireGuardAutoTunnel"
@@ -301,7 +301,7 @@ class MainActivity : AppCompatActivity() {
val args = backStack.toRoute<Route.Config>()
val config =
appUiState.tunnels.firstOrNull { it.id == args.id }
ConfigScreen(config, viewModel)
ConfigScreen(config, appUiState, viewModel)
}
composable<Route.TunnelOptions> { backStack ->
val args = backStack.toRoute<Route.TunnelOptions>()
@@ -13,7 +13,7 @@ import com.zaneschepke.wireguardautotunnel.core.worker.ServiceWorker
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
@@ -91,7 +91,7 @@ class WireGuardAutoTunnel : Application(), Configuration.Provider {
override fun onTerminate() {
applicationScope.cancel()
tunnelManager.setBackendState(BackendState.INACTIVE, emptyList())
tunnelManager.setBackendStatus(BackendStatus.Inactive)
super.onTerminate()
}
@@ -16,7 +16,7 @@ import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelMonitor
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus.StopReason.Ping
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
@@ -109,13 +109,13 @@ class AutoTunnelService : LifecycleService() {
with(autoTunnelStateFlow.value) {
if (
settings.isVpnKillSwitchEnabled &&
tunnelManager.getBackendState() != BackendState.KILL_SWITCH_ACTIVE
tunnelManager.getBackendStatus() !is BackendStatus.KillSwitch
) {
eventHandlerJob?.cancel()
val allowedIps =
if (settings.isLanOnKillSwitchEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS
else emptyList()
tunnelManager.setBackendState(BackendState.KILL_SWITCH_ACTIVE, allowedIps)
tunnelManager.setBackendStatus(BackendStatus.KillSwitch(allowedIps))
}
}
}
@@ -402,11 +402,11 @@ class AutoTunnelService : LifecycleService() {
handleBounceWithBackoff(event.configsPeerKeyResolvedMap)
is AutoTunnelEvent.StartKillSwitch -> {
Timber.d("Starting kill switch")
tunnelManager.setBackendState(BackendState.KILL_SWITCH_ACTIVE, event.allowedIps)
tunnelManager.setBackendStatus(BackendStatus.KillSwitch(event.allowedIps))
}
AutoTunnelEvent.StopKillSwitch -> {
Timber.d("Stopping kill switch")
tunnelManager.setBackendState(BackendState.SERVICE_ACTIVE, emptySet())
tunnelManager.setBackendStatus(BackendStatus.Active)
}
}
}
@@ -5,7 +5,7 @@ import com.wireguard.android.backend.BackendException
import com.wireguard.android.backend.Tunnel
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
@@ -59,12 +59,12 @@ constructor(
}
}
override fun setBackendState(backendState: BackendState, allowedIps: Collection<String>) {
override fun setBackendStatus(backendStatus: BackendStatus) {
Timber.w("Not yet implemented for kernel")
}
override fun getBackendState(): BackendState {
return BackendState.INACTIVE
override fun getBackendStatus(): BackendStatus {
return BackendStatus.Inactive
}
override suspend fun runningTunnelNames(): Set<String> {
@@ -1,6 +1,6 @@
package com.zaneschepke.wireguardautotunnel.core.tunnel
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
@@ -34,7 +34,8 @@ constructor(
appDataRepository.settings.flow
.filterNotNull()
.flatMapLatest { settings ->
MutableStateFlow(if (settings.isKernelEnabled) kernelTunnel else userspaceTunnel)
val backend = if (settings.isKernelEnabled) kernelTunnel else userspaceTunnel
MutableStateFlow(backend)
}
.stateIn(
scope = applicationScope.plus(ioDispatcher),
@@ -89,12 +90,12 @@ constructor(
tunnelProviderFlow.value.bounceTunnel(tunnelConf, reason)
}
override fun setBackendState(backendState: BackendState, allowedIps: Collection<String>) {
tunnelProviderFlow.value.setBackendState(backendState, allowedIps)
override fun setBackendStatus(backendStatus: BackendStatus) {
tunnelProviderFlow.value.setBackendStatus(backendStatus)
}
override fun getBackendState(): BackendState {
return tunnelProviderFlow.value.getBackendState()
override fun getBackendStatus(): BackendStatus {
return tunnelProviderFlow.value.getBackendStatus()
}
override suspend fun runningTunnelNames(): Set<String> {
@@ -138,19 +138,22 @@ constructor(
}
val host =
{
val parts = allowedIpStr.split("/")
val internalIp = if (parts.size == 2) parts[0] else allowedIpStr
tunnelConf.pingTarget
?: {
val parts = allowedIpStr.split("/")
val internalIp =
if (parts.size == 2) parts[0] else allowedIpStr
val prefix =
if (parts.size == 2) parts[1].toIntOrNull() ?: 32 else 32
if (prefix <= 1) {
tunnelConf.pingTarget ?: CLOUDFLARE_IPV4_IP
} else {
internalIp.removeSurrounding("[", "]")
val prefix =
if (parts.size == 2) parts[1].toIntOrNull() ?: 32
else 32
if (prefix <= 1) {
CLOUDFLARE_IPV4_IP
} else {
internalIp.removeSurrounding("[", "]")
}
}
}
.invoke()
.invoke()
val attemptTime = System.currentTimeMillis()
runCatching {
@@ -1,6 +1,6 @@
package com.zaneschepke.wireguardautotunnel.core.tunnel
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
@@ -41,9 +41,9 @@ interface TunnelProvider {
reason: TunnelStatus.StopReason = TunnelStatus.StopReason.User,
)
fun setBackendState(backendState: BackendState, allowedIps: Collection<String>)
fun setBackendStatus(backendStatus: BackendStatus)
fun getBackendState(): BackendState
fun getBackendStatus(): BackendStatus
suspend fun runningTunnelNames(): Set<String>
@@ -1,15 +1,15 @@
package com.zaneschepke.wireguardautotunnel.core.tunnel
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
import com.zaneschepke.wireguardautotunnel.domain.state.AmneziaStatistics
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
import com.zaneschepke.wireguardautotunnel.util.extensions.asAmBackendState
import com.zaneschepke.wireguardautotunnel.util.extensions.asBackendState
import com.zaneschepke.wireguardautotunnel.util.extensions.asAmBackendStatus
import com.zaneschepke.wireguardautotunnel.util.extensions.asBackendStatus
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
import javax.inject.Inject
import kotlin.jvm.optionals.getOrNull
@@ -17,7 +17,6 @@ import kotlinx.coroutines.CoroutineScope
import org.amnezia.awg.backend.Backend
import org.amnezia.awg.backend.BackendException
import org.amnezia.awg.backend.Tunnel
import org.amnezia.awg.config.Config
import timber.log.Timber
class UserspaceTunnel
@@ -29,14 +28,21 @@ constructor(
private val backend: Backend,
) : BaseTunnel(applicationScope, appDataRepository, serviceManager) {
private var previousBackendState: Pair<BackendState, Boolean>? = null
override suspend fun startBackend(tunnel: TunnelConf) {
try {
updateTunnelStatus(tunnel, TunnelStatus.Starting)
val amConfig = tunnel.toAmConfig()
handleVpnKillSwitchWithDomainEndpoints(amConfig)
var previousKillSwitch: Backend.BackendStatus? = null
// prevent dns failures from bringing tuns up when vpn kill switch active
if (
amConfig.peers.any { it.endpoint.getOrNull()?.toString()?.isUrl() == true } &&
backend.backendStatus is Backend.BackendStatus.KillSwitchActive
) {
previousKillSwitch = backend.backendStatus
setBackendStatus(BackendStatus.Active)
}
backend.setState(tunnel, Tunnel.State.UP, amConfig)
previousKillSwitch?.let { backend.backendStatus = it }
} catch (e: BackendException) {
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
throw e.toBackendError()
@@ -53,47 +59,20 @@ constructor(
} catch (e: BackendException) {
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
throw e.toBackendError()
} finally {
handlePreviouslyEnabledVpnKillSwitch()
}
}
// stop vpn kill switch if we need to resolve DNS for peer endpoints
private suspend fun handleVpnKillSwitchWithDomainEndpoints(config: Config) {
if (
config.peers.any { it.endpoint.getOrNull()?.toString()?.isUrl() == true } &&
backend.backendState.asBackendState() == BackendState.KILL_SWITCH_ACTIVE
) {
val bypassLan = appDataRepository.settings.get().isLanOnKillSwitchEnabled
previousBackendState = Pair(BackendState.KILL_SWITCH_ACTIVE, bypassLan)
setBackendState(BackendState.SERVICE_ACTIVE, emptyList())
}
}
// restore vpn kill switch if needed
private fun handlePreviouslyEnabledVpnKillSwitch() {
// let auto tunnel handle this if it is active
if (serviceManager.autoTunnelService.value == null) {
previousBackendState?.let { (state, lanEnabled) ->
Timber.d("Restoring kill switch configuration")
val lan = if (lanEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS else emptyList()
backend.setBackendState(state.asAmBackendState(), lan)
}
}
previousBackendState = null
}
override fun setBackendState(backendState: BackendState, allowedIps: Collection<String>) {
Timber.d("Setting backend state: $backendState with allowedIps: $allowedIps")
override fun setBackendStatus(backendStatus: BackendStatus) {
Timber.d("Setting backend state: $backendStatus")
try {
backend.setBackendState(backendState.asAmBackendState(), allowedIps)
backend.backendStatus = backendStatus.asAmBackendStatus()
} catch (e: BackendException) {
throw e.toBackendError()
}
}
override fun getBackendState(): BackendState {
return backend.backendState.asBackendState()
override fun getBackendStatus(): BackendStatus {
return backend.backendStatus.asBackendStatus()
}
override suspend fun runningTunnelNames(): Set<String> {
@@ -38,13 +38,13 @@ class GitHubUpdateRepository(
gitHubApi.getLatestRelease(githubOwner, githubRepo).onFailure(Timber::e)
}
release.map { release ->
val apkAsset =
val standaloneApkAsset =
release.assets.find { asset ->
asset.name.startsWith("wgtunnel-${Constants.STANDALONE_FLAVOR}-v") &&
asset.name.endsWith(".apk")
asset.name.endsWith(".apk")
}
val newVersion =
apkAsset
standaloneApkAsset
?.name
?.removePrefix("wgtunnel-${Constants.STANDALONE_FLAVOR}-v")
?.removeSuffix(".apk") ?: return@map null
@@ -53,7 +53,9 @@ class GitHubUpdateRepository(
if (isNightly && newVersion != currentVersion)
return@map GitHubReleaseMapper.toAppUpdate(release, newVersion)
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
GitHubReleaseMapper.toAppUpdate(release, newVersion)
GitHubReleaseMapper.toAppUpdate(release.copy(
assets = listOf(standaloneApkAsset)
), newVersion)
} else {
null
}
@@ -63,7 +65,7 @@ class GitHubUpdateRepository(
override suspend fun downloadApk(
apkUrl: String,
fileName: String,
onProgress: (Float) -> Unit,
onProgress: suspend (Float) -> Unit,
): Result<File> =
withContext(ioDispatcher) {
try {
@@ -101,4 +103,4 @@ class GitHubUpdateRepository(
Result.failure(e)
}
}
}
}
@@ -1,7 +1,9 @@
package com.zaneschepke.wireguardautotunnel.domain.enums
enum class BackendState {
KILL_SWITCH_ACTIVE,
SERVICE_ACTIVE,
INACTIVE,
sealed class BackendStatus {
data object Inactive : BackendStatus()
data object Active : BackendStatus()
data class KillSwitch(val allowedIps: List<String>) : BackendStatus()
}
@@ -9,6 +9,6 @@ interface UpdateRepository {
suspend fun downloadApk(
apkUrl: String,
fileName: String,
onProgress: (Float) -> Unit,
onProgress: suspend (Float) -> Unit,
): Result<File>
}
@@ -1,12 +1,12 @@
package com.zaneschepke.wireguardautotunnel.domain.state
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
import org.amnezia.awg.crypto.Key
data class TunnelState(
val status: TunnelStatus = TunnelStatus.Down,
val backendState: BackendState = BackendState.INACTIVE,
val backendState: BackendStatus = BackendStatus.Inactive,
val statistics: TunnelStatistics? = null,
val pingStates: Map<Key, PingState>? = null,
val handshakeSuccessLogs: Boolean? = null,
@@ -7,10 +7,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
@@ -25,6 +22,7 @@ import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.components.AddPeerButton
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.components.InterfaceSection
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.components.PeersSection
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
import com.zaneschepke.wireguardautotunnel.util.StringValue
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
@@ -32,6 +30,7 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
@Composable
fun ConfigScreen(
tunnelConf: TunnelConf?,
appUiState: AppUiState,
appViewModel: AppViewModel,
viewModel: ConfigViewModel = hiltViewModel(),
) {
@@ -42,6 +41,17 @@ fun ConfigScreen(
val activity = context as? MainActivity
var save by remember { mutableStateOf(false) }
val isTunnelNameTaken by
remember(uiState.tunnelName, appUiState.tunnels) {
derivedStateOf {
appUiState.tunnels
.filter { it.id != tunnelConf?.id }
.any { it.name == uiState.tunnelName }
}
}
// Secure screen due to sensitive information
DisposableEffect(Unit) {
activity
@@ -58,26 +68,34 @@ fun ConfigScreen(
appViewModel.handleEvent(
AppEvent.SetScreenAction {
keyboardController?.hide()
viewModel.save(tunnelConf)
if (!isTunnelNameTaken) {
save = true
}
}
)
}
LaunchedEffect(tunnelConf) { viewModel.initFromTunnel(tunnelConf) }
LaunchedEffect(uiState.success) {
if (uiState.success == true) {
appViewModel.handleEvent(
AppEvent.ShowMessage(StringValue.StringResource(R.string.config_changes_saved))
)
appViewModel.handleEvent(AppEvent.PopBackStack(true))
}
}
LaunchedEffect(uiState.message) {
uiState.message?.let { message ->
appViewModel.handleEvent(AppEvent.ShowMessage(message))
viewModel.setMessage(null)
// TODO improve error messages
LaunchedEffect(save) {
if (save) {
try {
appViewModel.handleEvent(
AppEvent.SaveTunnel(
uiState.configProxy.buildTunnelConfFromState(uiState.tunnelName, tunnelConf)
)
)
appViewModel.handleEvent(
AppEvent.ShowMessage(StringValue.StringResource(R.string.config_changes_saved))
)
appViewModel.handleEvent(AppEvent.PopBackStack(true))
} catch (e: Exception) {
val message = e.message ?: context.resources.getString(R.string.unknown_error)
appViewModel.handleEvent(AppEvent.ShowMessage(StringValue.DynamicString(message)))
} finally {
save = false
}
}
}
@@ -111,7 +129,7 @@ fun ConfigScreen(
modifier =
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 24.dp),
) {
InterfaceSection(uiState, viewModel)
InterfaceSection(isTunnelNameTaken, uiState, viewModel)
PeersSection(uiState, viewModel)
AddPeerButton(viewModel)
}
@@ -1,32 +1,20 @@
package com.zaneschepke.wireguardautotunnel.ui.screens.main.config
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.zaneschepke.wireguardautotunnel.R
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.state.ConfigUiState
import com.zaneschepke.wireguardautotunnel.ui.state.ConfigProxy
import com.zaneschepke.wireguardautotunnel.ui.state.InterfaceProxy
import com.zaneschepke.wireguardautotunnel.ui.state.PeerProxy
import com.zaneschepke.wireguardautotunnel.util.StringValue
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
@HiltViewModel
class ConfigViewModel
@Inject
constructor(
private val tunnelRepository: TunnelRepository,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
) : ViewModel() {
class ConfigViewModel @Inject constructor() : ViewModel() {
private val _uiState = MutableStateFlow(ConfigUiState())
val uiState: StateFlow<ConfigUiState> = _uiState.asStateFlow()
@@ -121,41 +109,6 @@ constructor(
updatePeer(index, updated)
}
fun setMessage(message: StringValue?) {
_uiState.update { it.copy(message = message) }
}
// TODO improve error messaging
fun save(tunnelConf: TunnelConf?) =
viewModelScope.launch(ioDispatcher) {
val message =
try {
val saveConfig = buildTunnelConfFromState(tunnelConf)
tunnelRepository.save(saveConfig)
_uiState.update { it.copy(success = true) }
} catch (e: Exception) {
setMessage(
e.message?.let { message -> (StringValue.DynamicString(message)) }
?: StringValue.StringResource(R.string.unknown_error)
)
}
}
private fun buildTunnelConfFromState(tunnelConf: TunnelConf?): TunnelConf {
val (wg, am) = _uiState.value.configProxy.buildConfigs()
val name = _uiState.value.tunnelName
return tunnelConf?.copyWithCallback(
tunName = name,
amQuick = am.toAwgQuickString(true),
wgQuick = wg.toWgQuickString(true),
)
?: TunnelConf(
tunName = name,
amQuick = am.toAwgQuickString(true),
wgQuick = wg.toWgQuickString(true),
)
}
fun onAuthenticated() {
_uiState.update { it.copy(isAuthenticated = true) }
}
@@ -17,7 +17,11 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.ConfigViewMode
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.state.ConfigUiState
@Composable
fun InterfaceSection(uiState: ConfigUiState, viewModel: ConfigViewModel) {
fun InterfaceSection(
isTunnelNameTaken: Boolean,
uiState: ConfigUiState,
viewModel: ConfigViewModel,
) {
var isDropDownExpanded by remember { mutableStateOf(false) }
val isAmneziaCompatibilitySet =
remember(uiState.configProxy.`interface`) {
@@ -50,6 +54,7 @@ fun InterfaceSection(uiState: ConfigUiState, viewModel: ConfigViewModel) {
value = uiState.tunnelName,
onValueChange = viewModel::updateTunnelName,
label = stringResource(R.string.name),
isError = isTunnelNameTaken,
hint = stringResource(R.string.tunnel_name).lowercase(),
modifier = Modifier.fillMaxWidth(),
)
@@ -3,7 +3,6 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.main.config.state
import com.zaneschepke.wireguardautotunnel.ui.state.ConfigProxy
import com.zaneschepke.wireguardautotunnel.ui.state.InterfaceProxy
import com.zaneschepke.wireguardautotunnel.ui.state.PeerProxy
import com.zaneschepke.wireguardautotunnel.util.StringValue
data class ConfigUiState(
val tunnelName: String = "",
@@ -13,6 +12,5 @@ data class ConfigUiState(
val showScripts: Boolean = false,
val isAuthenticated: Boolean = true,
val showAuthPrompt: Boolean = false,
val message: StringValue? = null,
val success: Boolean? = null,
val saveChanges: Boolean = false,
)
@@ -4,21 +4,25 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.zaneschepke.wireguardautotunnel.BuildConfig
import com.zaneschepke.wireguardautotunnel.R
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
import com.zaneschepke.wireguardautotunnel.domain.model.AppUpdate
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
import com.zaneschepke.wireguardautotunnel.util.FileUtils
import com.zaneschepke.wireguardautotunnel.util.StringValue
import dagger.hilt.android.lifecycle.HiltViewModel
import jakarta.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@HiltViewModel
class SupportViewModel
@Inject
constructor(private val updateRepository: UpdateRepository, private val fileUtils: FileUtils) :
constructor(private val updateRepository: UpdateRepository, private val fileUtils: FileUtils,
@MainDispatcher private val mainDispatcher: CoroutineDispatcher) :
ViewModel() {
private val _uiState = MutableStateFlow(SupportUiState())
@@ -62,7 +66,9 @@ constructor(private val updateRepository: UpdateRepository, private val fileUtil
_uiState.update { it.copy(isLoading = true) }
updateRepository
.downloadApk(appUpdate.apkUrl, appUpdate.apkFileName) { progress ->
_uiState.update { it.copy(downloadProgress = progress) }
withContext(mainDispatcher) {
_uiState.update { it.copy(downloadProgress = progress) }
}
}
.onSuccess { apk ->
_uiState.update { it.copy(isLoading = false) }
@@ -1,5 +1,6 @@
package com.zaneschepke.wireguardautotunnel.ui.state
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
import org.amnezia.awg.config.Config
data class ConfigProxy(val peers: List<PeerProxy>, val `interface`: InterfaceProxy) {
@@ -28,6 +29,20 @@ data class ConfigProxy(val peers: List<PeerProxy>, val `interface`: InterfacePro
)
}
fun buildTunnelConfFromState(name: String, tunnelConf: TunnelConf?): TunnelConf {
val (wg, am) = buildConfigs()
return tunnelConf?.copyWithCallback(
tunName = name,
amQuick = am.toAwgQuickString(true),
wgQuick = wg.toWgQuickString(true),
)
?: TunnelConf(
tunName = name,
amQuick = am.toAwgQuickString(true),
wgQuick = wg.toWgQuickString(true),
)
}
companion object {
fun from(amConfig: Config): ConfigProxy {
return ConfigProxy(
@@ -21,10 +21,10 @@ import com.zaneschepke.wireguardautotunnel.R
import com.zaneschepke.wireguardautotunnel.core.service.tile.AutoTunnelControlTile
import com.zaneschepke.wireguardautotunnel.core.service.tile.TunnelControlTile
import com.zaneschepke.wireguardautotunnel.util.Constants
import timber.log.Timber
import java.io.File
import java.io.InputStream
import kotlin.system.exitProcess
import timber.log.Timber
fun Context.openWebUrl(url: String): Result<Unit> {
return kotlin
@@ -2,7 +2,7 @@ package com.zaneschepke.wireguardautotunnel.util.extensions
import androidx.compose.ui.graphics.Color
import com.wireguard.android.backend.BackendException
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
import com.zaneschepke.wireguardautotunnel.domain.enums.HandshakeStatus
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
@@ -75,12 +75,21 @@ fun Config.defaultName(): String {
}
}
fun Backend.BackendState.asBackendState(): BackendState {
return BackendState.valueOf(this.name)
fun Backend.BackendStatus.asBackendStatus(): BackendStatus {
return when (val status = this) {
is Backend.BackendStatus.KillSwitchActive ->
BackendStatus.KillSwitch(status.allowedIps.toList())
is Backend.BackendStatus.ServiceActive -> BackendStatus.Active
else -> BackendStatus.Inactive
}
}
fun BackendState.asAmBackendState(): Backend.BackendState {
return Backend.BackendState.valueOf(this.name)
fun BackendStatus.asAmBackendStatus(): Backend.BackendStatus {
return when (val status = this) {
is BackendStatus.Active -> Backend.BackendStatus.ServiceActive.INSTANCE
is BackendStatus.Inactive -> Backend.BackendStatus.Inactive.INSTANCE
is BackendStatus.KillSwitch -> Backend.BackendStatus.KillSwitchActive(status.allowedIps)
}
}
fun Tunnel.State.asTunnelState(): TunnelStatus {
@@ -19,7 +19,7 @@ import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
import com.zaneschepke.wireguardautotunnel.di.AppShell
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
import com.zaneschepke.wireguardautotunnel.domain.enums.ConfigType
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
@@ -35,6 +35,12 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.withFirstState
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
import com.zaneschepke.wireguardautotunnel.viewmodel.event.UiEvent
import dagger.hilt.android.lifecycle.HiltViewModel
import java.io.IOException
import java.net.URL
import java.time.Instant
import java.util.*
import javax.inject.Inject
import javax.inject.Provider
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
@@ -45,12 +51,6 @@ import org.amnezia.awg.config.Config
import rikka.shizuku.Shizuku
import timber.log.Timber
import xyz.teamgravity.pin_lock_compose.PinManager
import java.io.IOException
import java.net.URL
import java.time.Instant
import java.util.*
import javax.inject.Inject
import javax.inject.Provider
@HiltViewModel
class AppViewModel
@@ -148,8 +148,7 @@ constructor(
is AppEvent.ImportTunnelFromClipboard ->
handleClipboardImport(event.text, state.tunnels)
is AppEvent.ImportTunnelFromFile ->
handleImportTunnelFromFile(event.data, state.tunnels)
is AppEvent.ImportTunnelFromFile -> handleImportTunnelFromFile(event.data)
is AppEvent.ImportTunnelFromUrl ->
handleImportTunnelFromUrl(event.url, state.tunnels)
@@ -264,11 +263,45 @@ constructor(
saveSettings(
state.appSettings.copy(tunnelPingTimeoutSeconds = event.timeout)
)
is AppEvent.SaveTunnel -> saveTunnel(event.tunnel)
}
}
}
}
private suspend fun saveTunnelsUniquely(tunnels: List<TunnelConf>) {
withContext(ioDispatcher) {
tunnelMutex.withLock {
val existingTunnels = appDataRepository.tunnels.getAll()
val uniqueTuns = generateUniquelyNamedConfigs(tunnels, existingTunnels)
appDataRepository.tunnels.saveAll(uniqueTuns)
}
}
}
private fun generateUniquelyNamedConfigs(
incoming: List<TunnelConf>,
existing: List<TunnelConf>,
): List<TunnelConf> {
val usedNames = existing.map { it.tunName }.toMutableSet()
val result = mutableListOf<TunnelConf>()
for (tun in incoming) {
var uniqueName = tun.tunName
var counter = 1
while (uniqueName in usedNames) {
uniqueName = "${tun.tunName} ($counter)"
counter++
}
usedNames.add(uniqueName)
result.add(tun.copy(tunName = uniqueName))
}
return result
}
fun handleUiEvent(event: UiEvent): Job =
viewModelScope.launch(mainDispatcher) { _uiEvent.emit(event) }
@@ -419,7 +452,7 @@ constructor(
_appViewState.update { it.copy(bottomSheet = bottomSheet) }
private suspend fun handleTunnelPingTargetChange(tunnelConf: TunnelConf, target: String) =
saveTunnel(tunnelConf.copy(pingTarget = target))
saveTunnel(tunnelConf.copy(pingTarget = target.ifBlank { null }))
private suspend fun handleTogglePingTunnel(tunnel: TunnelConf) =
saveTunnel(tunnel.copy(restartOnPingFailure = !tunnel.restartOnPingFailure))
@@ -515,17 +548,10 @@ constructor(
_appViewState.update { it.copy(popBackStack = true) }
}
private suspend fun handleImportTunnelFromFile(uri: Uri, tunnels: List<TunnelConf>) {
private suspend fun handleImportTunnelFromFile(uri: Uri) {
runCatching {
val tunnelConfigs = fileUtils.buildTunnelsFromUri(uri)
val existingNames = tunnels.map { it.tunName }.toMutableList()
val uniqueTunnelConfigs =
tunnelConfigs.map { config ->
val uniqueName = config.generateUniqueName(existingNames)
existingNames.add(uniqueName)
config.copy(tunName = uniqueName)
}
appDataRepository.tunnels.saveAll(uniqueTunnelConfigs)
saveTunnelsUniquely(tunnelConfigs)
}
.onFailure {
when (it) {
@@ -544,11 +570,7 @@ constructor(
runCatching {
val amConfig = TunnelConf.configFromAmQuick(config)
val tunnelConf = TunnelConf.tunnelConfigFromAmConfig(amConfig)
saveTunnel(
tunnelConf.copy(
tunName = tunnelConf.generateUniqueName(tunnels.map { it.tunName })
)
)
saveTunnelsUniquely(listOf(tunnelConf))
}
.onFailure {
Timber.e(it)
@@ -566,11 +588,7 @@ constructor(
url.openStream().use { stream ->
val amConfig = Config.parse(stream)
val tunnelConf = TunnelConf.tunnelConfigFromAmConfig(amConfig)
saveTunnel(
tunnelConf.copy(
tunName = tunnelConf.generateUniqueName(tunnels.map { it.tunName })
)
)
saveTunnelsUniquely(listOf(tunnelConf))
}
}
.onFailure {
@@ -648,19 +666,19 @@ constructor(
val updatedSettings =
appSettings.copy(isLanOnKillSwitchEnabled = !appSettings.isLanOnKillSwitchEnabled)
saveSettings(updatedSettings)
handleKillSwitchChange(appSettings)
handleKillSwitchChange(updatedSettings)
}
private fun handleKillSwitchChange(appSettings: AppSettings) {
// let auto tunnel handle kill switch changes if running
if (uiState.value.isAutoTunnelActive) return
if (!appSettings.isVpnKillSwitchEnabled)
return tunnelManager.setBackendState(BackendState.SERVICE_ACTIVE, emptyList())
return tunnelManager.setBackendStatus(BackendStatus.Active)
Timber.d("Starting kill switch")
val allowedIps =
if (appSettings.isLanOnKillSwitchEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS
else emptyList()
tunnelManager.setBackendState(BackendState.KILL_SWITCH_ACTIVE, allowedIps)
tunnelManager.setBackendStatus(BackendStatus.KillSwitch(allowedIps))
}
private suspend fun handleToggleAppShortcuts(appSettings: AppSettings) {
@@ -695,7 +713,7 @@ constructor(
}
if (enabled && !requestRoot()) return
// disable kill switch feature in kernel mode
tunnelManager.setBackendState(BackendState.INACTIVE, emptyList())
tunnelManager.setBackendStatus(BackendStatus.Inactive)
saveSettings(
appSettings.copy(
isKernelEnabled = enabled,
@@ -77,6 +77,8 @@ sealed class AppEvent {
data class SetTheme(val theme: Theme) : AppEvent()
data class SaveTunnel(val tunnel: TunnelConf) : AppEvent()
data class SaveMonitoringSettings(
val pingInterval: Int,
val tunnelPingAttempts: Int,
+2 -2
View File
@@ -1,6 +1,6 @@
object Constants {
const val VERSION_NAME = "3.9.4"
const val VERSION_CODE = 39400
const val VERSION_NAME = "3.9.5"
const val VERSION_CODE = 39500
const val TARGET_SDK = 35
const val MIN_SDK = 26
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
@@ -0,0 +1,7 @@
What's new:
- Fix for tunnel sort bug
- Improved location permissions flow
- Location permission detection and notifications
- Fix for AndroidTV apps detection for split tunneling
- Improved tunnel monitoring and reboot recovery
- Fix tunnel slow reconnect from sleep
+1 -1
View File
@@ -1,7 +1,7 @@
[versions]
accompanist = "0.37.3"
activityCompose = "1.10.1"
amneziawgAndroid = "1.4.0"
amneziawgAndroid = "1.6.2"
androidx-junit = "1.3.0"
icmp4a = "1.0.0"
roomdatabasebackup = "1.1.0"