From 323a9a21a7c3c38f60f083cebeb6424d9c4aabff Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Sat, 23 Jun 2018 15:31:46 +0300 Subject: [PATCH] acquire and release partial wake lock --- app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 67f4f380..2d92841d 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -10,8 +10,8 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.net.NetworkInfo -import android.os.Handler import android.os.IBinder +import android.os.PowerManager import android.support.annotation.Keep import android.support.v4.app.NotificationCompat import android.util.Log @@ -31,6 +31,7 @@ class BaresipService: Service() { internal lateinit var ni: Intent internal lateinit var npi: PendingIntent internal lateinit var nr: BroadcastReceiver + internal lateinit var wl: PowerManager.WakeLock override fun onCreate() { @@ -63,6 +64,10 @@ class BaresipService: Service() { } } + val pm = getSystemService(Context.POWER_SERVICE) as PowerManager + wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Baresip") + wl.acquire() + super.onCreate() } @@ -133,6 +138,8 @@ class BaresipService: Service() { baresipStop() BaresipService.IS_SERVICE_RUNNING = false unregisterReceiver(nr) + nm.cancelAll() + wl.release() stopForeground(true) stopSelf() }