|
|
|
@ -1,8 +1,10 @@ |
|
|
|
|
package io.legado.app.service |
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
|
import android.content.Context |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.os.Build |
|
|
|
|
import android.os.PowerManager |
|
|
|
|
import androidx.core.app.NotificationCompat |
|
|
|
|
import io.legado.app.R |
|
|
|
|
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.web.HttpServer |
|
|
|
|
import io.legado.app.web.WebSocketServer |
|
|
|
|
import splitties.systemservices.powerManager |
|
|
|
|
|
|
|
|
|
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 webSocketServer: WebSocketServer? = null |
|
|
|
|
private var notificationContent = "" |
|
|
|
@ -40,8 +46,10 @@ class WebService : BaseService() { |
|
|
|
|
NetworkChangedListener(this) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressLint("WakelockTimeout") |
|
|
|
|
override fun onCreate() { |
|
|
|
|
super.onCreate() |
|
|
|
|
wakeLock.acquire() |
|
|
|
|
isRun = true |
|
|
|
|
notificationContent = getString(R.string.service_starting) |
|
|
|
|
upNotification() |
|
|
|
@ -73,6 +81,7 @@ class WebService : BaseService() { |
|
|
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
|
|
super.onDestroy() |
|
|
|
|
wakeLock.release() |
|
|
|
|
networkChangedListener.unRegister() |
|
|
|
|
isRun = false |
|
|
|
|
if (httpServer?.isAlive == true) { |
|
|
|
|