From 61c7c3c8c1c279be76db0ee858399d59bfeca687 Mon Sep 17 00:00:00 2001 From: Andrea Gottardo Date: Tue, 26 Nov 2024 10:05:05 -0800 Subject: [PATCH] HealthNotifier: fix dependent messages handling (#573) Fixes tailscale/corp#24582 Android port of tailscale/corp#24719. We were not clearing dependency warnings when a new warning was added which was listed as a dependency of a pre-existing warning. For instance, if `dns-read-os-config-failed` is added to the warnings before `network-status` is added, we were ignoring the dependency by not removing `dns-read-os-config-failed` upon adding `network-status`. This PR addresses that. Signed-off-by: Andrea Gottardo --- .../tailscale/ipn/ui/notifier/HealthNotifier.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/tailscale/ipn/ui/notifier/HealthNotifier.kt b/android/src/main/java/com/tailscale/ipn/ui/notifier/HealthNotifier.kt index 5193328cfe..4ebac07e20 100644 --- a/android/src/main/java/com/tailscale/ipn/ui/notifier/HealthNotifier.kt +++ b/android/src/main/java/com/tailscale/ipn/ui/notifier/HealthNotifier.kt @@ -62,8 +62,21 @@ class HealthNotifier( val warningsBeforeAdd = currentWarnings.value val currentWarnableCodes = warnings.map { it.WarnableCode }.toSet() val addedWarnings: MutableSet = mutableSetOf() + val removedByNewDependency: MutableSet = mutableSetOf() val isWarmingUp = warnings.any { it.WarnableCode == "warming-up" } + /// Checks if there is any warning in `warningsBeforeAdd` that needs to be removed because the new warning `w` + /// is listed as a dependency of a warning already in `warningsBeforeAdd`, and removes it. + fun dropDependenciesForAddedWarning(w: UnhealthyState) { + for (warning in warningsBeforeAdd) { + warning.DependsOn?.let { + if (it.contains(w.WarnableCode)) { + removedByNewDependency.add(warning) + } + } + } + } + for (warning in warnings) { if (ignoredWarnableCodes.contains(warning.WarnableCode)) { continue @@ -81,6 +94,7 @@ class HealthNotifier( } else if (!isWarmingUp) { TSLog.d(TAG, "Adding health warning: ${warning.WarnableCode}") this.currentWarnings.set(this.currentWarnings.value + warning) + dropDependenciesForAddedWarning(warning) if (warning.Severity == Health.Severity.high) { this.sendNotification(warning.Title, warning.Text, warning.WarnableCode) } @@ -89,7 +103,7 @@ class HealthNotifier( } } - val warningsToDrop = warningsBeforeAdd.minus(addedWarnings) + val warningsToDrop = warningsBeforeAdd.minus(addedWarnings).union(removedByNewDependency) if (warningsToDrop.isNotEmpty()) { TSLog.d(TAG, "Dropping health warnings with codes $warningsToDrop") this.removeNotifications(warningsToDrop)