Skip to content

Refactor: split NotificationService (channels / quiet-hours policy / dispatch / sound) and dedupe its repeated blocks #166

Description

@almothafar

Problem

NotificationService.java`` is ~1,200 lines doing four jobs (SRP): channel registry, notification building/dispatch, quiet-hours + silent-mode policy, and sound/vibration playback — plus static lifecycle state (soundExecutor, `cachedLauncherIcon`).

Suggested split (seams already exist in the code)

DRY items to fold in (all in this file)

(permalinks pinned at f4460ac; grep the method names if lines have moved)

  1. The builder chain is written three times: configureNotificationContent (760-768), `sendQuietHoursAwareAlert` ([430-439](https://github.com/almothafar/SimpleBatteryNotifier/blob/f4460acc3ba99320c3efe310fb51456af0939ab0/app/src/main/java/com/almothafar/simplebatterynotifier/service/NotificationService.java#L430-L439)),`` postChargeNotification (297-307)`` — same setTicker/setContentTitle/setContentText/setWhen/setLargeIcon/setContentIntent/setVisibility/BigTextStyle sequence. `AlertSpec` is already the right abstraction; route the level alerts and the charge notification through it too.
  2. Charge-style resolution duplicated: notifyChargeConnected (173-186) vs `sendSlowChargeWarning` ([381-393](https://github.com/almothafar/SimpleBatteryNotifier/blob/f4460acc3ba99320c3efe310fb51456af0939ab0/app/src/main/java/com/almothafar/simplebatterynotifier/service/NotificationService.java#L381-L393))`` — extract one "deliver per the user's charge style" helper (read pref → resolve → none/toast/notification branch).
  3. Vibration pattern duplicated: VIBRATION_PATTERN (line 78) vs the inline copy in `SystemService.vibratePhone` ([SystemService.java:510](https://github.com/almothafar/SimpleBatteryNotifier/blob/f4460acc3ba99320c3efe310fb51456af0939ab0/app/src/main/java/com/almothafar/simplebatterynotifier/service/SystemService.java#L510))`` — one constant, so channel vibration and manual silent-mode vibration can't drift.
  4. Dead lifecycle API: shutdown() (565-575) and `releaseCachedBitmap()` ([583-588](https://github.com/almothafar/SimpleBatteryNotifier/blob/f4460acc3ba99320c3efe310fb51456af0939ab0/app/src/main/java/com/almothafar/simplebatterynotifier/service/NotificationService.java#L583-L588))`` are never called from anywhere (there is no Application class). Either add the Application hook their javadoc promises, or delete them — record the decision.

Sequencing

Land the small targeted fixes first so this refactor is a pure move: #153 (channel versioning), #154 (time parse), #155 (charge notification ID), #160 (type enum), #165 (channel name strings). This issue then reshapes without changing behavior.

Acceptance criteria

  • No behavior change: full test suite green + manual smoke of each alert type (critical/warning/full/temperature/fast-drain/slow-charge/charge-connected, quiet hours on/off)
  • One builder chain, one charge-style resolver, one vibration pattern
  • shutdown/releaseCachedBitmap wired to a real lifecycle or removed
  • No resulting class above ~400 lines (soft target)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions