Skip to content

Fix foreground service start-timeout crash path#677

Open
callebtc wants to merge 2 commits intomainfrom
codex/fix-fgs-start-timeout
Open

Fix foreground service start-timeout crash path#677
callebtc wants to merge 2 commits intomainfrom
codex/fix-fgs-start-timeout

Conversation

@callebtc
Copy link
Collaborator

@callebtc callebtc commented Mar 4, 2026

Summary

  • call startForegroundService only when background mode plus Bluetooth/location and notification permissions allow immediate foreground promotion
  • promote service to foreground before mesh startup work in onStartCommand to avoid timeout windows
  • remove eager mesh holder initialization from onCreate to reduce startup latency before foreground promotion

Testing

  • ./gradlew :app:compileDebugKotlin -q

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f40f27ddf5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +46 to 50
val canStartAsForeground = bgEnabled && hasBtPerms && hasNotifPerm

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (bgEnabled && hasNotifPerm) {
if (canStartAsForeground) {
context.startForegroundService(intent)

Choose a reason for hiding this comment

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

P2 Badge Re-trigger foreground start after runtime Bluetooth grant

This new guard skips startForegroundService whenever Bluetooth/location permissions are not already granted, but there is no automatic retry path once those permissions are granted later in the same app session (the existing call sites invoke MeshForegroundService.start(...) only during startup/toggle flows). On first-launch permission onboarding for API 26+ devices, users can complete grants and still never get the foreground service/notification until they relaunch or manually toggle background mode, which leaves background mesh behavior unexpectedly disabled.

Useful? React with 👍 / 👎.

@callebtc callebtc marked this pull request as draft March 6, 2026 12:08
@callebtc callebtc marked this pull request as ready for review March 6, 2026 12:08
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