Skip to content

fix: shutdown now stops foreground service (#455)#521

Merged
torlando-tech merged 1 commit intomainfrom
fix/shutdown-stops-service
Feb 22, 2026
Merged

fix: shutdown now stops foreground service (#455)#521
torlando-tech merged 1 commit intomainfrom
fix/shutdown-stops-service

Conversation

@torlando-tech
Copy link
Copy Markdown
Owner

Summary

  • Fixes Shutdown functionality inconsitently broken on version 0.8.3 #455: Shutdown button now properly stops the foreground service and removes the persistent notification
  • Previously, pressing Shutdown only called reticulumProtocol.shutdown() via IPC but never sent ACTION_STOP, so the service kept running
  • Adds is_user_shutdown SharedPreferences flag to prevent START_STICKY, scheduleServiceRestart(), and auto-rebind from restarting the service after user-initiated shutdown

Changes

  • SettingsViewModel/DebugViewModel: Set shutdown flag, unbind first (prevents auto-rebind race), send ACTION_STOP intent
  • ReticulumService: Check is_user_shutdown in onStartCommand (blocks START_STICKY), onDestroy (skips restart scheduling), and ACTION_START (clears flag)
  • InterfaceConfigManager: Clear is_user_shutdown flag before interface-change restart
  • DebugViewModel: Guard fetchDebugInfo against shutdown state, clear UI immediately to prevent "Unknown error"

Test plan

  • Unit tests pass (143 tests)
  • Shutdown: notification disappears and does not return
  • Restart then Shutdown: notification disappears after restart+shutdown
  • Normal restart still works
  • App relaunch after shutdown: service starts normally

🤖 Generated with Claude Code

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 22, 2026

Greptile Summary

This PR fixes issue #455 by implementing proper foreground service shutdown. The solution uses a SharedPreferences flag (is_user_shutdown) to coordinate shutdown behavior across the app and service processes.

Key changes:

  • SettingsViewModel and DebugViewModel now set the shutdown flag, unbind the service first (to prevent auto-rebind), and send ACTION_STOP intent to properly stop the foreground service and remove the notification
  • ReticulumService.onStartCommand() checks the shutdown flag and blocks START_STICKY restarts when set, but exempts ACTION_START (app relaunch) and ACTION_STOP from this check
  • ReticulumService.onDestroy() skips scheduling service restart when the shutdown flag is set
  • InterfaceConfigManager clears the shutdown flag before interface-change restarts to allow the service to start normally
  • All tests updated to accommodate new Context dependency

Previous reviewer concerns addressed:
The exemption of ACTION_START on line 141 is correct - it allows the service to bypass the shutdown check, proceed to the when statement, clear the flag, and start normally. The service does NOT stop itself before clearing the flag.

Confidence Score: 5/5

  • This PR is safe to merge - it properly implements user-initiated shutdown with correct flag management and all tests passing
  • The implementation correctly handles the shutdown flag lifecycle: sets it on user shutdown, exempts ACTION_START and ACTION_STOP from the shutdown check (allowing app relaunch and proper shutdown), clears it on intentional starts, and prevents all restart mechanisms when set. The previous reviewer's concern about ACTION_START was based on a misreading of the control flow - the exemption is necessary and correct.
  • No files require special attention

Important Files Changed

Filename Overview
app/src/main/java/com/lxmf/messenger/service/ReticulumService.kt Adds is_user_shutdown flag checks to prevent service restart after user shutdown; ACTION_START and ACTION_STOP exempted from shutdown check to allow normal app relaunch
app/src/main/java/com/lxmf/messenger/viewmodel/SettingsViewModel.kt Refactored shutdown to set flag, unbind service first, then send ACTION_STOP intent instead of calling shutdown() via IPC
app/src/main/java/com/lxmf/messenger/viewmodel/DebugViewModel.kt Same shutdown refactor as SettingsViewModel; added shutdown state guards to prevent IPC calls after shutdown
app/src/main/java/com/lxmf/messenger/service/InterfaceConfigManager.kt Clears shutdown flag before interface-change restart to allow service to start normally

Last reviewed commit: 0849910

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@sentry
Copy link
Copy Markdown
Contributor

sentry bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@torlando-tech
Copy link
Copy Markdown
Owner Author

@greptileai

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

…455)

Previously, pressing Shutdown only called reticulumProtocol.shutdown() via
IPC but never sent ACTION_STOP to the Android service, so the foreground
notification persisted and restart mechanisms brought the service back.

Changes:
- SettingsViewModel/DebugViewModel: set is_user_shutdown SharedPreferences
  flag, unbind first (prevents auto-rebind race), send ACTION_STOP intent
- ReticulumService: check is_user_shutdown flag in onStartCommand (blocks
  START_STICKY restart), onDestroy (skips scheduleServiceRestart), and
  ACTION_START (clears flag for normal launches)
- InterfaceConfigManager: clear is_user_shutdown flag before restart
- DebugViewModel: guard fetchDebugInfo against shutdown state, clear UI
  immediately on shutdown to prevent "Unknown error" display

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@torlando-tech torlando-tech force-pushed the fix/shutdown-stops-service branch from 9520030 to 0849910 Compare February 22, 2026 05:36
@torlando-tech
Copy link
Copy Markdown
Owner Author

@greptileai

@torlando-tech torlando-tech merged commit a5160ac into main Feb 22, 2026
13 checks passed
@torlando-tech torlando-tech deleted the fix/shutdown-stops-service branch February 22, 2026 05:55
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.

Shutdown functionality inconsitently broken on version 0.8.3

1 participant