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() { private suspend fun manageVpn() {
while (true) { while (true) {
if (isEthernetConnected && setting.isTunnelOnEthernetEnabled && vpnService.getState() == Tunnel.State.DOWN) { when {
ServiceManager.startVpnService(this, tunnelConfig) ((isEthernetConnected &&
} setting.isTunnelOnEthernetEnabled &&
if (!isEthernetConnected && setting.isTunnelOnMobileDataEnabled && vpnService.getState() == Tunnel.State.DOWN)) ->
!isWifiConnected && ServiceManager.startVpnService(this, tunnelConfig)
isMobileDataConnected
&& vpnService.getState() == Tunnel.State.DOWN (!isEthernetConnected &&
) { setting.isTunnelOnMobileDataEnabled &&
ServiceManager.startVpnService(this, tunnelConfig) !isWifiConnected &&
} else if (!isEthernetConnected && !setting.isTunnelOnMobileDataEnabled && isMobileDataConnected &&
!isWifiConnected && vpnService.getState() == Tunnel.State.DOWN) ->
vpnService.getState() == Tunnel.State.UP ServiceManager.startVpnService(this, tunnelConfig)
) {
ServiceManager.stopVpnService(this) (!isEthernetConnected &&
} else if (!isEthernetConnected && isWifiConnected && !setting.isTunnelOnMobileDataEnabled &&
!setting.trustedNetworkSSIDs.contains(currentNetworkSSID) && !isWifiConnected &&
setting.isTunnelOnWifiEnabled && vpnService.getState() == Tunnel.State.UP) ->
(vpnService.getState() != Tunnel.State.UP) ServiceManager.stopVpnService(this)
) {
ServiceManager.startVpnService(this, tunnelConfig) (!isEthernetConnected && isWifiConnected &&
} else if (!isEthernetConnected && (isWifiConnected && !setting.trustedNetworkSSIDs.contains(currentNetworkSSID) &&
setting.isTunnelOnWifiEnabled &&
(vpnService.getState() != Tunnel.State.UP)) ->
ServiceManager.startVpnService(this, tunnelConfig)
(!isEthernetConnected && (isWifiConnected &&
setting.trustedNetworkSSIDs.contains(currentNetworkSSID)) && setting.trustedNetworkSSIDs.contains(currentNetworkSSID)) &&
(vpnService.getState() == Tunnel.State.UP) (vpnService.getState() == Tunnel.State.UP)) ->
) { ServiceManager.stopVpnService(this)
ServiceManager.stopVpnService(this)
} else if (!isEthernetConnected && (isWifiConnected && (!isEthernetConnected && (isWifiConnected &&
!setting.isTunnelOnWifiEnabled && !setting.isTunnelOnWifiEnabled &&
(vpnService.getState() == Tunnel.State.UP) (vpnService.getState() == Tunnel.State.UP))) ->
)) { ServiceManager.stopVpnService(this)
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) delay(Constants.VPN_CONNECTIVITY_CHECK_INTERVAL)
} }