From 8c22d96f7bc870e3c5a95ac1dfb1ad119a67cfac Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Thu, 18 Apr 2019 21:52:40 +0300 Subject: [PATCH] - moved acquiring of wakelock to baresip service on create method (previous commit was about main activity) --- .../com/tutpro/baresip/BaresipService.kt | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index ea7f5b79..750a4a53 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -33,7 +33,7 @@ class BaresipService: Service() { internal lateinit var rt: Ringtone internal lateinit var nm: NotificationManager internal lateinit var snb: NotificationCompat.Builder - internal lateinit var wl: PowerManager.WakeLock + internal lateinit var wakeLock: PowerManager.WakeLock internal lateinit var fl: WifiManager.WifiLock internal var rtTimer: Timer? = null @@ -80,15 +80,11 @@ class BaresipService: Service() { } ) - val pm = getSystemService(Context.POWER_SERVICE) as PowerManager - wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.tutpro.baresip:wakelog") - - /* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - val intent = Intent() - intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS - intent.data = Uri.parse("package:$packageName") - startActivity(intent) - } */ + wakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager).run { + newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.tutpro.baresip:wakelog").apply { + acquire() + } + } super.onCreate() } @@ -167,9 +163,8 @@ class BaresipService: Service() { } } ContactsActivity.restoreContacts(applicationContext.filesDir) - wl.acquire() Thread(Runnable { baresipStart(filesPath) }).start() - BaresipService.isServiceRunning = true + isServiceRunning = true showStatusNotification() } @@ -751,7 +746,7 @@ class BaresipService: Service() { history.clear() messages.clear() if (this::nm.isInitialized) nm.cancelAll() - if (this::wl.isInitialized && wl.isHeld) wl.release() + if (this::wakeLock.isInitialized && wakeLock.isHeld) wakeLock.release() if (this::fl.isInitialized && fl.isHeld) fl.release() isServiceClean = true }