Skip to content

Commit

Permalink
Some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrivoruchko committed Jan 20, 2024
1 parent 767b583 commit ccfcd60
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 52 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import java.util.Properties

@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
Expand Down
4 changes: 1 addition & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ buildscript {
}
}

@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
Expand All @@ -15,5 +14,4 @@ plugins {
alias(libs.plugins.ksp) apply false
alias(libs.plugins.googleServices) apply false
alias(libs.plugins.firebaseCrashlytics) apply false
}
true // Needed to make the Suppress annotation work for the plugins block
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.app.Service
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ServiceInfo
import android.os.Build
import android.os.IBinder
import androidx.core.app.ServiceCompat
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -43,9 +42,6 @@ public abstract class AbstractModuleService : Service() {
else ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION

ServiceCompat.startForeground(this, notificationIdForeground, notification, serviceType)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && foregroundServiceType and ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION == 0)
throw IllegalStateException("MjpegService is not FOREGROUND")
}

public fun stopForeground() {
Expand All @@ -58,7 +54,7 @@ public abstract class AbstractModuleService : Service() {
hideErrorNotification()

if (notificationHelper.notificationPermissionGranted(this).not()) {
XLog.e(getLog("showErrorNotification"), IllegalStateException("showErrorNotification: No permission granted. Ignoring."))
XLog.e(getLog("showErrorNotification", "No permission granted. Ignoring."))
return
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
agp = "8.2.1"
kotlin = "1.9.22"
ksp = "1.9.22-1.0.16"
ksp = "1.9.22-1.0.17"
android-tools-r8 = "8.2.42"
android-tools-desugar = "2.0.4"
google-services = "4.4.0"
Expand Down Expand Up @@ -35,7 +35,7 @@ play-integrity = "1.3.0"
play-app-update = "2.1.0"

firebase-analytics = "21.5.0"
firebase-crashlytics = "18.6.0"
firebase-crashlytics = "18.6.1"

[libraries]
android-tools-r8 = { module = "com.android.tools:r8", version.ref = "android-tools-r8" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import kotlinx.coroutines.flow.*
import org.koin.core.annotation.InjectedParam
import org.koin.core.annotation.Scope
import org.koin.core.annotation.Scoped
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.random.Random

@Scope(MjpegKoinScope::class)
Expand Down Expand Up @@ -80,8 +79,6 @@ internal class MjpegStreamingService(
bitmap
}

private val monitorScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)

// All Volatiles vars must be write on this (WebRTC-HT) thread
@Volatile private var wakeLock: PowerManager.WakeLock? = null
// All Volatiles vars must be write on this (WebRTC-HT) thread
Expand Down Expand Up @@ -121,8 +118,6 @@ internal class MjpegStreamingService(
data class Traffic(val time: Long, val traffic: List<MjpegState.TrafficPoint>) : InternalEvent(Priority.DESTROY_IGNORE) {
override fun toString(): String = "Traffic(time=$time)"
}

data class Monitor(val counter: Int, val marker: AtomicBoolean) : InternalEvent(Priority.DESTROY_IGNORE)
}

internal sealed class RestartReason(private val msg: String) {
Expand Down Expand Up @@ -154,16 +149,6 @@ internal class MjpegStreamingService(
super.start()
XLog.d(getLog("start"))

monitorScope.launch {
repeat(Int.MAX_VALUE) { counter ->
val marker = AtomicBoolean(false)
sendEvent(InternalEvent.Monitor(counter, marker))
delay(5000)
if (isActive && marker.get().not())
XLog.e(this@MjpegStreamingService.getLog("LOCK @:$counter"), IllegalArgumentException("LOCK @:$counter"))
}
}

appStateFlowProvider.mutableAppStateFlow.value = AppState()
mutableMjpegStateFlow.value = MjpegState()
sendEvent(InternalEvent.InitState())
Expand Down Expand Up @@ -209,7 +194,6 @@ internal class MjpegStreamingService(
XLog.d(getLog("destroyService"))

wakeLock?.apply { if (isHeld) release() }
monitorScope.cancel()
supervisorJob.cancel()

val destroyJob = Job()
Expand Down Expand Up @@ -460,8 +444,6 @@ internal class MjpegStreamingService(
mjpegSettings.enablePinFlow.first() -> mjpegSettings.setPin(randomPin()) // will restart server
}

is InternalEvent.Monitor -> event.marker.set(true)

else -> throw IllegalArgumentException("Unknown MjpegEvent: ${event::class.java}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.android.asCoroutineDispatcher
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeoutOrNull
import okhttp3.ConnectionSpec
Expand All @@ -55,7 +52,6 @@ import org.koin.core.annotation.Scope
import org.koin.core.annotation.Scoped
import org.webrtc.IceCandidate
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
import kotlin.math.pow

Expand Down Expand Up @@ -89,7 +85,6 @@ internal class WebRtcStreamingService(
.build()

private val playIntegrity = PlayIntegrity(service, environment, okHttpClient)
private val monitorScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
private val currentError: AtomicReference<WebRtcError?> = AtomicReference(null)

// All Volatile vars must be write on this (WebRTC-HT) thread
Expand Down Expand Up @@ -136,8 +131,6 @@ internal class WebRtcStreamingService(
data class ConfigurationChange(val newConfig: Configuration) : InternalEvent(Priority.STOP_IGNORE)

data class Destroy(val destroyJob: CompletableJob) : InternalEvent(Priority.DESTROY_IGNORE)

data class Monitor(val counter: Int, val marker: AtomicBoolean) : InternalEvent(Priority.DESTROY_IGNORE)
}

private val passwordVerifier = SocketSignaling.PasswordVerifier { clientId, passwordHash ->
Expand Down Expand Up @@ -269,16 +262,6 @@ internal class WebRtcStreamingService(
super.start()
XLog.d(getLog("start"))

monitorScope.launch {
repeat(Int.MAX_VALUE) { counter ->
val marker = AtomicBoolean(false)
sendEvent(InternalEvent.Monitor(counter, marker))
delay(3000)
if (isActive && marker.get().not())
XLog.e(this@WebRtcStreamingService.getLog("LOCK @:$counter"), IllegalArgumentException("LOCK @:$counter"))
}
}

appStateFlowProvider.mutableAppStateFlow.value = AppState()
mutableWebRtcStateFlow.value = WebRtcState()
sendEvent(InternalEvent.InitState)
Expand Down Expand Up @@ -320,7 +303,6 @@ internal class WebRtcStreamingService(
runCatching { service.unregisterReceiver(broadcastReceiver) }
connectivityManager.unregisterNetworkCallback(networkCallback)
coroutineScope.cancel()
monitorScope.cancel()

val destroyJob = Job()
sendEvent(InternalEvent.Destroy(destroyJob))
Expand Down Expand Up @@ -393,8 +375,6 @@ internal class WebRtcStreamingService(
// On WebRTC-HT only
private suspend fun processEvent(event: WebRtcEvent) {
when (event) {
is InternalEvent.Monitor -> event.marker.set(true)

is InternalEvent.InitState -> {
if (destroyPending) {
XLog.i(getLog("InitState", "DestroyPending. Ignoring"), IllegalStateException("InitState: DestroyPending"))
Expand Down Expand Up @@ -501,7 +481,7 @@ internal class WebRtcStreamingService(

is InternalEvent.OpenSocket -> {
if (destroyPending) {
XLog.i(getLog("OpenSocket", "DestroyPending. Ignoring"), IllegalStateException("OpenSocket: DestroyPending"))
XLog.i(getLog("OpenSocket", "DestroyPending. Ignoring"))
return
}

Expand Down Expand Up @@ -768,7 +748,7 @@ internal class WebRtcStreamingService(

is InternalEvent.EnableMic -> {
if (destroyPending) {
XLog.i(getLog("EnableMic", "DestroyPending. Ignoring"), IllegalStateException("EnableMic: DestroyPending"))
XLog.i(getLog("EnableMic", "DestroyPending. Ignoring"))
return
}

Expand Down Expand Up @@ -846,7 +826,7 @@ internal class WebRtcStreamingService(
}

if (isStreaming()) {
XLog.i(getLog("CreateNewPassword", "Streaming. Ignoring."), IllegalStateException("CreateNewPassword: Streaming."))
XLog.i(getLog("CreateNewPassword", "Streaming. Ignoring."))
return
}

Expand Down

0 comments on commit ccfcd60

Please sign in to comment.