|
|
|
|
@ -8,6 +8,8 @@ import android.content.Intent
|
|
|
|
|
import android.content.pm.ServiceInfo |
|
|
|
|
import android.os.Build |
|
|
|
|
import android.os.IBinder |
|
|
|
|
import android.os.Handler |
|
|
|
|
import android.os.Looper |
|
|
|
|
import android.os.PowerManager |
|
|
|
|
import androidx.core.app.NotificationCompat |
|
|
|
|
import androidx.core.app.ServiceCompat |
|
|
|
|
@ -95,6 +97,7 @@ class StreamService : Service() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun finish() { |
|
|
|
|
if (capture != null) { shutdown(abort = true); return } |
|
|
|
|
poll?.cancel(); poll = null |
|
|
|
|
lock?.let { if (it.isHeld) it.release() }; lock = null |
|
|
|
|
StreamController.ended(id, this) |
|
|
|
|
@ -103,9 +106,16 @@ class StreamService : Service() {
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
|
|
poll?.cancel() |
|
|
|
|
capture?.stop { NativeLib.streamStop(id) }; capture = null |
|
|
|
|
lock?.let { if (it.isHeld) it.release() }; lock = null |
|
|
|
|
StreamController.ended(id, this); scope.cancel() |
|
|
|
|
val engine = capture; capture = null |
|
|
|
|
val ownedLock = lock; lock = null |
|
|
|
|
val release = { |
|
|
|
|
NativeLib.streamStop(id) |
|
|
|
|
ownedLock?.let { if (it.isHeld) it.release() } |
|
|
|
|
Handler(Looper.getMainLooper()).post { StreamController.ended(id, this) } |
|
|
|
|
Unit |
|
|
|
|
} |
|
|
|
|
if (engine != null) engine.stop(release) else release() |
|
|
|
|
scope.cancel() |
|
|
|
|
LogManager.addLog("INFO", "stream", "foreground destroyed id=$id") |
|
|
|
|
super.onDestroy() |
|
|
|
|
} |
|
|
|
|
|