Skip to content

Commit

Permalink
fix: allow removing configs
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Bretting <[email protected]>
  • Loading branch information
luca-dot-sh committed Dec 10, 2024
1 parent 57fee11 commit 281699c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ConfigurationManager(val clientFactory: ClientFactory) :
) {
_localConfiguration.update { prev ->
Timber.e("changeFeatureConfigurationForPIDs.prev $prev")
Timber.e("changeFeatureConfigurationForPIDs() $vfsWriteFeature, $sendMessageFeature")
Timber.e("changeFeatureConfigurationForPIDs() $vfsWriteFeature, $sendMessageFeature, $uprobesFeature, $jniReferencesFeature")
// the configuration shall not be changed from the UI if there is none received from
// backend
if (prev != null && prev is ConfigurationUpdate.Valid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import de.amosproj3.ziofa.api.configuration.BackendConfigurationAccess
import de.amosproj3.ziofa.api.configuration.ConfigurationUpdate
import de.amosproj3.ziofa.api.configuration.LocalConfigurationAccess
import de.amosproj3.ziofa.client.SysSendmsgConfig
import de.amosproj3.ziofa.client.UprobeConfig
import de.amosproj3.ziofa.client.VfsWriteConfig
import de.amosproj3.ziofa.ui.configuration.data.BackendFeatureOptions
import de.amosproj3.ziofa.ui.configuration.data.ConfigurationScreenState
Expand Down Expand Up @@ -38,11 +39,11 @@ class ConfigurationViewModel(

val changed =
combine(
localConfigurationAccess.localConfiguration,
backendConfigurationAccess.backendConfiguration,
) { local, backend ->
local != backend
}
localConfigurationAccess.localConfiguration,
backendConfigurationAccess.backendConfiguration,
) { local, backend ->
local != backend
}
.stateIn(viewModelScope, SharingStarted.Lazily, false)

fun optionChanged(option: BackendFeatureOptions, active: Boolean) {
Expand All @@ -59,10 +60,24 @@ class ConfigurationViewModel(
localConfigurationAccess.changeFeatureConfiguration(
enable = active,
sendMessageFeature =
SysSendmsgConfig(
pids.associateWith { DURATION_THRESHOLD }
// TODO this is not a duration
),
SysSendmsgConfig(
pids.associateWith { DURATION_THRESHOLD }
// TODO this is not a duration
),
)
}

is BackendFeatureOptions.UprobeOption -> {
localConfigurationAccess.changeFeatureConfiguration(
enable = active,
uprobesFeature = pids.map {
UprobeConfig(
fnName = option.method,
target = option.odexFilePath,
offset = option.offset,
pid = it.toInt()
)
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ sealed class BackendFeatureOptions(val featureName: String, val active: Boolean)
BackendFeatureOptions("Unix Domain Socket Analysis", enabled)

data class UprobeOption(
val displayName: String,
val id: String,
val method: String,
val enabled: Boolean,
val pids: Set<UInt>,
) : BackendFeatureOptions(id, enabled)
val offset: ULong,
val odexFilePath: String
) : BackendFeatureOptions(method, enabled)
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ fun ConfigurationUpdate.Valid.toUIOptionsForPids(
options.add(
BackendFeatureOptions.UprobeOption(
enabled = true, // uprobe options are either active or not visible
displayName =
"UProbe for Symbol ${uprobeConfig.fnName} in ${uprobeConfig.target}",
id = uprobeConfig.fnName,
pids =
uprobeConfig.pid?.let { setOf(it.toUInt()) }
?: setOf(), // TODO This should not be null asserted
method = uprobeConfig.fnName,
pids = uprobeConfig.pid?.let { setOf(it.toUInt()) } ?: setOf(),
odexFilePath = uprobeConfig.target,
offset = uprobeConfig.offset
)
)
}
Expand Down

0 comments on commit 281699c

Please sign in to comment.