Skip to content

Commit 61c7c3c

Browse files
authored
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 <[email protected]>
1 parent 91a1316 commit 61c7c3c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

android/src/main/java/com/tailscale/ipn/ui/notifier/HealthNotifier.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,21 @@ class HealthNotifier(
6262
val warningsBeforeAdd = currentWarnings.value
6363
val currentWarnableCodes = warnings.map { it.WarnableCode }.toSet()
6464
val addedWarnings: MutableSet<UnhealthyState> = mutableSetOf()
65+
val removedByNewDependency: MutableSet<UnhealthyState> = mutableSetOf()
6566
val isWarmingUp = warnings.any { it.WarnableCode == "warming-up" }
6667

68+
/// Checks if there is any warning in `warningsBeforeAdd` that needs to be removed because the new warning `w`
69+
/// is listed as a dependency of a warning already in `warningsBeforeAdd`, and removes it.
70+
fun dropDependenciesForAddedWarning(w: UnhealthyState) {
71+
for (warning in warningsBeforeAdd) {
72+
warning.DependsOn?.let {
73+
if (it.contains(w.WarnableCode)) {
74+
removedByNewDependency.add(warning)
75+
}
76+
}
77+
}
78+
}
79+
6780
for (warning in warnings) {
6881
if (ignoredWarnableCodes.contains(warning.WarnableCode)) {
6982
continue
@@ -81,6 +94,7 @@ class HealthNotifier(
8194
} else if (!isWarmingUp) {
8295
TSLog.d(TAG, "Adding health warning: ${warning.WarnableCode}")
8396
this.currentWarnings.set(this.currentWarnings.value + warning)
97+
dropDependenciesForAddedWarning(warning)
8498
if (warning.Severity == Health.Severity.high) {
8599
this.sendNotification(warning.Title, warning.Text, warning.WarnableCode)
86100
}
@@ -89,7 +103,7 @@ class HealthNotifier(
89103
}
90104
}
91105

92-
val warningsToDrop = warningsBeforeAdd.minus(addedWarnings)
106+
val warningsToDrop = warningsBeforeAdd.minus(addedWarnings).union(removedByNewDependency)
93107
if (warningsToDrop.isNotEmpty()) {
94108
TSLog.d(TAG, "Dropping health warnings with codes $warningsToDrop")
95109
this.removeNotifications(warningsToDrop)

0 commit comments

Comments
 (0)