acquire and release partial wake lock

This commit is contained in:
Juha Heinanen
2018-06-23 15:31:46 +03:00
parent 92c13cce4f
commit 323a9a21a7
@@ -10,8 +10,8 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.net.NetworkInfo import android.net.NetworkInfo
import android.os.Handler
import android.os.IBinder import android.os.IBinder
import android.os.PowerManager
import android.support.annotation.Keep import android.support.annotation.Keep
import android.support.v4.app.NotificationCompat import android.support.v4.app.NotificationCompat
import android.util.Log import android.util.Log
@@ -31,6 +31,7 @@ class BaresipService: Service() {
internal lateinit var ni: Intent internal lateinit var ni: Intent
internal lateinit var npi: PendingIntent internal lateinit var npi: PendingIntent
internal lateinit var nr: BroadcastReceiver internal lateinit var nr: BroadcastReceiver
internal lateinit var wl: PowerManager.WakeLock
override fun onCreate() { 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() super.onCreate()
} }
@@ -133,6 +138,8 @@ class BaresipService: Service() {
baresipStop() baresipStop()
BaresipService.IS_SERVICE_RUNNING = false BaresipService.IS_SERVICE_RUNNING = false
unregisterReceiver(nr) unregisterReceiver(nr)
nm.cancelAll()
wl.release()
stopForeground(true) stopForeground(true)
stopSelf() stopSelf()
} }