From 3862f5b44500a55e0a4a2969d1c7f9750dcca935 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Thu, 2 Sep 2021 11:31:56 +0300 Subject: [PATCH] Earlier acquire of partial wake lock --- .../com/tutpro/baresip/BaresipService.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) 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")