Skip to content

refactor(monitor): Make notification builder stateless#398

Merged
d4rken merged 1 commit intomainfrom
refactor/monitor-notifications-stateless-builder
Feb 22, 2026
Merged

refactor(monitor): Make notification builder stateless#398
d4rken merged 1 commit intomainfrom
refactor/monitor-notifications-stateless-builder

Conversation

@d4rken
Copy link
Copy Markdown
Member

@d4rken d4rken commented Feb 22, 2026

Summary

Analysing an ANR trace revealed that MonitorNotifications held a single
shared mutable NotificationCompat.Builder object, protected by a
coroutine Mutex. This had two problems:

  • getStartupNotification() bypassed the lock entirely, silently violating
    the synchronization protocol
  • After a device-connected call, switching to a null-device call could leave
    stale CustomBigContentView content on the shared builder

Changes

  • Remove shared builder field and builderLock (Mutex) entirely
  • Add private val openPi: PendingIntent (promoted from init local)
  • Add private fun baseBuilder(channelId: String) helper for common setup
  • getBuilder() now takes channelId and returns a fresh builder each call
  • getNotification() and getNotificationConnected() are no longer suspend
    (Mutex removed, no coroutine context needed)
  • All three public methods produce functionally identical notifications

Test plan

  • Build passes: assembleFossDebug, assembleGplayDebug
  • Startup notification shows "no pods" title and taps open MainActivity
  • Device notification updates correctly as pods connect/disconnect

…tions

Replace shared NotificationCompat.Builder + Mutex with a stateless
design where each method builds a fresh notification. Introduces a
baseBuilder() helper to deduplicate common setup. Removes builderLock
and suspend modifiers from getNotification/getNotificationConnected.
@d4rken d4rken merged commit 9ad3f3c into main Feb 22, 2026
9 checks passed
@d4rken d4rken deleted the refactor/monitor-notifications-stateless-builder branch February 22, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant