Commit 1cac3cd5 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Do not show bad/no connection notification when screen is off

When the screen is off some of the components get put into sleep and Nebulo might think it has a bad/no connection but this is instantly resolved when the screen is turned back on
parent 5634c39a
......@@ -2,6 +2,7 @@ package com.frostnerd.smokescreen
import android.app.*
import android.content.*
import android.hardware.display.DisplayManager
import android.hardware.fingerprint.FingerprintManager
import android.net.ConnectivityManager
import android.net.Network
......@@ -9,6 +10,7 @@ import android.net.NetworkCapabilities
import android.net.Uri
import android.os.Build
import android.os.PowerManager
import android.view.Display
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
......@@ -137,6 +139,13 @@ fun Context.registerLocalReceiver(
return actualReceiver
}
fun Context.isScreenOn():Boolean {
val mgr = getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
return mgr.displays.any {
it.state == Display.STATE_ON
}
}
fun AppCompatActivity.registerLocalReceiver(
filteredActions: List<String>,
unregisterOnDestroy: Boolean,
......
......@@ -28,7 +28,7 @@ class ConnectionWatchdog(private val trafficStats: TrafficStats,
private val debounceCallbackByMs:Long? = null,
private val badLatencyThresholdMs:Int = 750,
private val badPacketLossThresholdPercent:Int = 30,
private val onBadServerConnection:() -> Unit,
private val onBadServerConnection:() -> Boolean, // Returns whether state has been handled. Will be called until it returned true.
private val onBadConnectionResolved:() -> Unit,
private val logger:Logger?,
private val advancedLogging:Boolean = false
......@@ -160,9 +160,12 @@ class ConnectionWatchdog(private val trafficStats: TrafficStats,
private fun callCallback() {
if(!running) return
logFine("Calling callback.")
if(debounceCallbackByMs == null || lastCallbackCall == null) onBadServerConnection()
val handled = if(debounceCallbackByMs == null || lastCallbackCall == null) onBadServerConnection()
else if(System.currentTimeMillis() - lastCallbackCall!! > debounceCallbackByMs) onBadServerConnection()
lastCallbackCall = System.currentTimeMillis()
else false
if(handled) {
lastCallbackCall = System.currentTimeMillis()
}
}
fun stop() {
......
......@@ -1427,7 +1427,12 @@ class DnsVpnService : VpnService(), Runnable, CoroutineScope {
if (!watchdogDisabledForSession && getPreferences().enableConnectionWatchDog) connectionWatchDog =
currentTrafficStats?.let {
ConnectionWatchdog(it, 30 * 1000, 10 * 60 * 10000, onBadServerConnection = {
showBadConnectionNotification()
if (isScreenOn()) {
showBadConnectionNotification()
true
} else {
false
}
}, onBadConnectionResolved = {
hideBadConnectionNotification()
}, logger = this@DnsVpnService.logger, advancedLogging = getPreferences().advancedLogging)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment