diff --git a/app-common-io/src/main/java/eu/darken/sdmse/common/root/service/RootHost.kt b/app-common-io/src/main/java/eu/darken/sdmse/common/root/service/RootHost.kt index 154d6ec81..32f136013 100644 --- a/app-common-io/src/main/java/eu/darken/sdmse/common/root/service/RootHost.kt +++ b/app-common-io/src/main/java/eu/darken/sdmse/common/root/service/RootHost.kt @@ -30,7 +30,7 @@ import javax.inject.Inject */ @Keep @SuppressLint("UnsafeDynamicallyLoadedCode") -class RootHost constructor(_args: List) : HasSharedResource, BaseRootHost("$TAG#${hashCode()}", _args) { +class RootHost(_args: List) : HasSharedResource, BaseRootHost("$TAG#${hashCode()}", _args) { override val sharedResource = SharedResource.createKeepAlive(iTag, hostScope) @@ -58,6 +58,7 @@ class RootHost constructor(_args: List) : HasSharedResource, BaseRo ipc.hostOptions .onEach { options -> + log(TAG) { "New options: $options" } if (options.isDebug && Logging.loggers.none { it == logCatLogger }) { Logging.install(logCatLogger) log(TAG) { "Logger installed!" } diff --git a/app-common-io/src/main/java/eu/darken/sdmse/common/root/service/RootServiceClient.kt b/app-common-io/src/main/java/eu/darken/sdmse/common/root/service/RootServiceClient.kt index 9628513bb..03b5be2b3 100644 --- a/app-common-io/src/main/java/eu/darken/sdmse/common/root/service/RootServiceClient.kt +++ b/app-common-io/src/main/java/eu/darken/sdmse/common/root/service/RootServiceClient.kt @@ -8,6 +8,7 @@ import eu.darken.sdmse.common.debug.logging.asLog import eu.darken.sdmse.common.debug.logging.log import eu.darken.sdmse.common.debug.logging.logTag import eu.darken.sdmse.common.files.local.ipc.FileOpsClient +import eu.darken.sdmse.common.flow.setupCommonEventHandlers import eu.darken.sdmse.common.ipc.IpcClientModule import eu.darken.sdmse.common.pkgs.pkgops.ipc.PkgOpsClient import eu.darken.sdmse.common.root.RootSettings @@ -19,9 +20,11 @@ import eu.darken.sdmse.common.sharedresource.SharedResource import eu.darken.sdmse.common.shell.ipc.ShellOpsClient import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onCompletion @@ -53,11 +56,11 @@ class RootServiceClient @Inject constructor( recorderPath = debugSettings.recorderPath.value(), ) - var lastInternal: RootConnection? = null + val lastInternal = MutableStateFlow(null) rootHostLauncher .createHostConnection(options = initialOptions) .onEach { wrapper -> - lastInternal = wrapper.host + lastInternal.value = wrapper.host send(wrapper.service) } .launchIn(this) @@ -66,19 +69,20 @@ class RootServiceClient @Inject constructor( debugSettings.isDebugMode.flow, debugSettings.isTraceMode.flow, debugSettings.isDryRunMode.flow, - debugSettings.recorderPath.flow - ) { isDebug, isTrace, isDryRun, recorderPath -> - lastInternal?.let { - val dynamicOptions = RootHostOptions( - isDebug = isDebug, - isTrace = isTrace, - isDryRun = isDryRun, - recorderPath = recorderPath, - ) - log(TAG) { "Updating debug settings: $dynamicOptions" } - it.updateHostOptions(dynamicOptions) - } - }.launchIn(this) + debugSettings.recorderPath.flow, + lastInternal.filterNotNull(), + ) { isDebug, isTrace, isDryRun, recorderPath, lastConnection -> + val dynamicOptions = RootHostOptions( + isDebug = isDebug, + isTrace = isTrace, + isDryRun = isDryRun, + recorderPath = recorderPath, + ) + log(TAG) { "Updating debug settings: $dynamicOptions" } + lastConnection.updateHostOptions(dynamicOptions) + } + .setupCommonEventHandlers(TAG) { "dynamic-debug-settings" } + .launchIn(this) log(TAG) { "awaitClose()..." } awaitClose { diff --git a/app-common-io/src/main/java/eu/darken/sdmse/common/shizuku/service/ShizukuHost.kt b/app-common-io/src/main/java/eu/darken/sdmse/common/shizuku/service/ShizukuHost.kt index e956fd9aa..0bb3b99e6 100644 --- a/app-common-io/src/main/java/eu/darken/sdmse/common/shizuku/service/ShizukuHost.kt +++ b/app-common-io/src/main/java/eu/darken/sdmse/common/shizuku/service/ShizukuHost.kt @@ -63,6 +63,7 @@ class ShizukuHost( currentOptions .onEach { options -> + log(TAG) { "New options: $options" } if (options.isDebug && Logging.loggers.none { it == logCatLogger }) { Logging.install(logCatLogger) log(TAG) { "Logger installed!" } diff --git a/app-common-io/src/main/java/eu/darken/sdmse/common/shizuku/service/ShizukuServiceClient.kt b/app-common-io/src/main/java/eu/darken/sdmse/common/shizuku/service/ShizukuServiceClient.kt index 396b3e13d..4c3bf9b4f 100644 --- a/app-common-io/src/main/java/eu/darken/sdmse/common/shizuku/service/ShizukuServiceClient.kt +++ b/app-common-io/src/main/java/eu/darken/sdmse/common/shizuku/service/ShizukuServiceClient.kt @@ -8,6 +8,7 @@ import eu.darken.sdmse.common.debug.logging.asLog import eu.darken.sdmse.common.debug.logging.log import eu.darken.sdmse.common.debug.logging.logTag import eu.darken.sdmse.common.files.local.ipc.FileOpsClient +import eu.darken.sdmse.common.flow.setupCommonEventHandlers import eu.darken.sdmse.common.ipc.IpcClientModule import eu.darken.sdmse.common.pkgs.pkgops.ipc.PkgOpsClient import eu.darken.sdmse.common.sharedresource.SharedResource @@ -20,9 +21,11 @@ import eu.darken.sdmse.common.shizuku.service.internal.ShizukuHostLauncher import eu.darken.sdmse.common.shizuku.service.internal.ShizukuHostOptions import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onCompletion @@ -55,11 +58,11 @@ class ShizukuServiceClient @Inject constructor( recorderPath = debugSettings.recorderPath.value(), ) - var lastInternal: ShizukuConnection? = null + val lastInternal = MutableStateFlow(null) serviceLauncher .createServiceHostConnection(optionsInitial) .onEach { wrapper -> - lastInternal = wrapper.host + lastInternal.value = wrapper.host send(wrapper.service) } .launchIn(this) @@ -69,18 +72,19 @@ class ShizukuServiceClient @Inject constructor( debugSettings.isTraceMode.flow, debugSettings.isDryRunMode.flow, debugSettings.recorderPath.flow, - ) { isDebug, isTrace, isDryRun, recorderPath -> - lastInternal?.let { - val optionsDynamic = ShizukuHostOptions( - isDebug = isDebug, - isTrace = isTrace, - isDryRun = isDryRun, - recorderPath = recorderPath, - ) - log(TAG) { "Updating debug settings: $optionsDynamic" } - it.updateHostOptions(optionsDynamic) - } - }.launchIn(this) + lastInternal.filterNotNull(), + ) { isDebug, isTrace, isDryRun, recorderPath, lastConnection -> + val optionsDynamic = ShizukuHostOptions( + isDebug = isDebug, + isTrace = isTrace, + isDryRun = isDryRun, + recorderPath = recorderPath, + ) + log(TAG) { "Updating debug settings: $optionsDynamic" } + lastConnection.updateHostOptions(optionsDynamic) + } + .setupCommonEventHandlers(TAG) { "dynamic-debug-settings" } + .launchIn(this) log(TAG) { "awaitClose()..." } awaitClose { diff --git a/app/src/main/java/eu/darken/sdmse/common/debug/recorder/ui/RecorderViewModel.kt b/app/src/main/java/eu/darken/sdmse/common/debug/recorder/ui/RecorderViewModel.kt index 1641e0169..5f3e38d3a 100644 --- a/app/src/main/java/eu/darken/sdmse/common/debug/recorder/ui/RecorderViewModel.kt +++ b/app/src/main/java/eu/darken/sdmse/common/debug/recorder/ui/RecorderViewModel.kt @@ -51,18 +51,21 @@ class RecorderViewModel @Inject constructor( private val logObsDefault = pathCache .map { File(it) } .map { LogData(it, it.length()) } + .onEach { log(TAG) { "Base log: $it" } } .catch { log(TAG, ERROR) { "Failed to get default log size: ${it.asLog()}" } } .replayingShare(vmScope) private val logObsShizuku = pathCache .map { File(it.replace(".log", "_shizuku.log")) } .map { if (it.exists()) LogData(it, it.length()) else null } + .onEach { log(TAG) { "Shizuku log: $it" } } .catch { log(TAG, ERROR) { "Failed to get Shizuku log size: ${it.asLog()}" } } .replayingShare(vmScope) private val logObsRoot = pathCache .map { File(it.replace(".log", "_root.log")) } .map { if (it.exists()) LogData(it, it.length()) else null } + .onEach { log(TAG) { "Root log: $it" } } .catch { log(TAG, ERROR) { "Failed to get root log size: ${it.asLog()}" } } .replayingShare(vmScope) @@ -76,6 +79,7 @@ class RecorderViewModel @Inject constructor( shizuku?.file?.path, root?.file?.path ) + log(TAG) { "Compressing files: $zipContent" } val zipFile = File("${default.file.path.dropLast(4)}.zip") Zipper().zip(zipContent, zipFile.path) zipFile to zipFile.length()