Reaction: Fix Extra notification not hiding when disabled#592
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Fixed an issue where toggling the Extra notification setting in General Settings didn't take effect immediately. After turning the option off, the extra notification could remain visible until AirPods state changed enough to cause a refresh, or until the monitor service was restarted.
Also fixed a related case in Always-on monitor mode: the extra notification kept updating with cached battery data after AirPods disconnected — even when "Keep notification after disconnect" was off.
Technical Context
MonitorServicereaduseExtraMonitorNotificationandkeepConnectedNotificationAfterDisconnectsynchronously via DataStore'svalueBlockinginside the device-update flow but never subscribed to the setting flows. Setting changes only took effect on the next device emission, and even then there was no cancel branch —NOTIFICATION_ID_CONNECTEDwas never explicitly cancelled untilonDestroy().currentDevice != nulltoPodDevice.isLiveso the connected notification reflects actual BLE/AAP liveness rather than cached profile data. AddedisLivetoNotificationDeviceKeyso live↔cached transitions emit through the distinct filter.decideExtraNotificationAction(...)helper, unit-tested across all 9 input combinations of (extra on/off) × (live / cached / null) × (keepAfter on/off).onDestroy()now reads a cachedNotificationSettingssnapshot (atomic@Volatile) rather than callingvalueBlockingon a cancelled scope. The snapshot is seeded at the top ofdoMonitor()before the permission early-return so it's always valid.DataStoreValue.flownow appliesdistinctUntilChanged()on the raw preference value beforereader()runs (matches the SD MAID SE pattern). Eliminates spurious re-emissions when any key in the samesettings_generalDataStore is written — previously every unrelated write caused extra notification updates and unnecessary deserializer work for every consumer.Behavior change:
keepConnectedNotificationAfterDisconnect = falsenow actually hides the extra notification when AirPods disconnect (previously it kept updating with cached data until the service died). WithkeepAfter = truethe notification persists with the last live snapshot.Review checklist
decideExtraNotificationActiontable covers all live/cached/null × extra-on/off × keepAfter combinationsonDestroy()reads the cached snapshot — verify the snapshot is seeded before anyreturnpaths indoMonitor()DataStoreValue.flowsource-level filter — quick scan of other consumers for code that relied on duplicate emissions