diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 6b7ee60d..649ea078 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -82,6 +82,18 @@ class BaresipService: Service() { createNotificationChannels() snb = NotificationCompat.Builder(this, DEFAULT_CHANNEL_ID) + pm = getSystemService(Context.POWER_SERVICE) as PowerManager + + // This is needed to keep service running also in Doze Mode + partialWakeLock = pm.run { + newWakeLock( + PowerManager.PARTIAL_WAKE_LOCK, + "com.tutpro.baresip:partial_wakelog" + ).apply { + acquire() + } + } + cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val builder = NetworkRequest.Builder() .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN) @@ -116,22 +128,12 @@ class BaresipService: Service() { } ) - pm = getSystemService(Context.POWER_SERVICE) as PowerManager + wm = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager tm = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager - // This is needed to keep service running also in Doze Mode - partialWakeLock = pm.run { - newWakeLock( - PowerManager.PARTIAL_WAKE_LOCK, - "com.tutpro.baresip:partial_wakelog" - ).apply { - acquire() - } - } - proximityWakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "com.tutpro.baresip:proximity_wakelog")