|
@@ -1,8 +1,10 @@
|
|
|
package io.legado.app.service
|
|
package io.legado.app.service
|
|
|
|
|
|
|
|
|
|
+import android.annotation.SuppressLint
|
|
|
import android.content.Context
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
import android.content.Intent
|
|
|
import android.os.Build
|
|
import android.os.Build
|
|
|
|
|
+import android.os.PowerManager
|
|
|
import androidx.core.app.NotificationCompat
|
|
import androidx.core.app.NotificationCompat
|
|
|
import io.legado.app.R
|
|
import io.legado.app.R
|
|
|
import io.legado.app.base.BaseService
|
|
import io.legado.app.base.BaseService
|
|
@@ -14,6 +16,7 @@ import io.legado.app.receiver.NetworkChangedListener
|
|
|
import io.legado.app.utils.*
|
|
import io.legado.app.utils.*
|
|
|
import io.legado.app.web.HttpServer
|
|
import io.legado.app.web.HttpServer
|
|
|
import io.legado.app.web.WebSocketServer
|
|
import io.legado.app.web.WebSocketServer
|
|
|
|
|
+import splitties.systemservices.powerManager
|
|
|
|
|
|
|
|
import java.io.IOException
|
|
import java.io.IOException
|
|
|
|
|
|
|
@@ -33,6 +36,9 @@ class WebService : BaseService() {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private val wakeLock by lazy {
|
|
|
|
|
+ powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "legado:webService")
|
|
|
|
|
+ }
|
|
|
private var httpServer: HttpServer? = null
|
|
private var httpServer: HttpServer? = null
|
|
|
private var webSocketServer: WebSocketServer? = null
|
|
private var webSocketServer: WebSocketServer? = null
|
|
|
private var notificationContent = ""
|
|
private var notificationContent = ""
|
|
@@ -40,8 +46,10 @@ class WebService : BaseService() {
|
|
|
NetworkChangedListener(this)
|
|
NetworkChangedListener(this)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @SuppressLint("WakelockTimeout")
|
|
|
override fun onCreate() {
|
|
override fun onCreate() {
|
|
|
super.onCreate()
|
|
super.onCreate()
|
|
|
|
|
+ wakeLock.acquire()
|
|
|
isRun = true
|
|
isRun = true
|
|
|
notificationContent = getString(R.string.service_starting)
|
|
notificationContent = getString(R.string.service_starting)
|
|
|
upNotification()
|
|
upNotification()
|
|
@@ -73,6 +81,7 @@ class WebService : BaseService() {
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
override fun onDestroy() {
|
|
|
super.onDestroy()
|
|
super.onDestroy()
|
|
|
|
|
+ wakeLock.release()
|
|
|
networkChangedListener.unRegister()
|
|
networkChangedListener.unRegister()
|
|
|
isRun = false
|
|
isRun = false
|
|
|
if (httpServer?.isAlive == true) {
|
|
if (httpServer?.isAlive == true) {
|