fix: airplane mode bug

This commit is contained in:
Zane Schepke 2023-12-09 09:45:54 -05:00
parent 16e65aec9f
commit 515e91d191
1 changed files with 40 additions and 28 deletions

View File

@ -245,36 +245,48 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
private suspend fun manageVpn() {
while (true) {
if (isEthernetConnected && setting.isTunnelOnEthernetEnabled && vpnService.getState() == Tunnel.State.DOWN) {
ServiceManager.startVpnService(this, tunnelConfig)
}
if (!isEthernetConnected && setting.isTunnelOnMobileDataEnabled &&
!isWifiConnected &&
isMobileDataConnected
&& vpnService.getState() == Tunnel.State.DOWN
) {
ServiceManager.startVpnService(this, tunnelConfig)
} else if (!isEthernetConnected && !setting.isTunnelOnMobileDataEnabled &&
!isWifiConnected &&
vpnService.getState() == Tunnel.State.UP
) {
ServiceManager.stopVpnService(this)
} else if (!isEthernetConnected && isWifiConnected &&
!setting.trustedNetworkSSIDs.contains(currentNetworkSSID) &&
setting.isTunnelOnWifiEnabled &&
(vpnService.getState() != Tunnel.State.UP)
) {
ServiceManager.startVpnService(this, tunnelConfig)
} else if (!isEthernetConnected && (isWifiConnected &&
when {
((isEthernetConnected &&
setting.isTunnelOnEthernetEnabled &&
vpnService.getState() == Tunnel.State.DOWN)) ->
ServiceManager.startVpnService(this, tunnelConfig)
(!isEthernetConnected &&
setting.isTunnelOnMobileDataEnabled &&
!isWifiConnected &&
isMobileDataConnected &&
vpnService.getState() == Tunnel.State.DOWN) ->
ServiceManager.startVpnService(this, tunnelConfig)
(!isEthernetConnected &&
!setting.isTunnelOnMobileDataEnabled &&
!isWifiConnected &&
vpnService.getState() == Tunnel.State.UP) ->
ServiceManager.stopVpnService(this)
(!isEthernetConnected && isWifiConnected &&
!setting.trustedNetworkSSIDs.contains(currentNetworkSSID) &&
setting.isTunnelOnWifiEnabled &&
(vpnService.getState() != Tunnel.State.UP)) ->
ServiceManager.startVpnService(this, tunnelConfig)
(!isEthernetConnected && (isWifiConnected &&
setting.trustedNetworkSSIDs.contains(currentNetworkSSID)) &&
(vpnService.getState() == Tunnel.State.UP)
) {
ServiceManager.stopVpnService(this)
} else if (!isEthernetConnected && (isWifiConnected &&
(vpnService.getState() == Tunnel.State.UP)) ->
ServiceManager.stopVpnService(this)
(!isEthernetConnected && (isWifiConnected &&
!setting.isTunnelOnWifiEnabled &&
(vpnService.getState() == Tunnel.State.UP)
)) {
ServiceManager.stopVpnService(this)
(vpnService.getState() == Tunnel.State.UP))) ->
ServiceManager.stopVpnService(this)
(!isEthernetConnected && !isWifiConnected &&
!isMobileDataConnected &&
(vpnService.getState() == Tunnel.State.UP)) ->
ServiceManager.stopVpnService(this)
else -> {
Timber.d("Unknown case")
}
}
delay(Constants.VPN_CONNECTIVITY_CHECK_INTERVAL)
}