Repository navigation
Add opt-in Background Mode for Android BLE recording - #7577
Conversation
|
@greptile-apps review |
kodjima33
left a comment
There was a problem hiding this comment.
Android opt-in Background Mode for BLE recording (sticky foreground service + parked autoConnect) and removal of bonding requests against the new non-bonding Omi firmware (was causing reconnect loops). Approve only — mobile area.
Greptile SummaryThis PR adds an opt-in Background Mode feature for Android BLE recording that keeps the Omi device connected and transcribing when the app is fully closed, and removes the BLE bonding request for Omi devices that was causing an auth-failure reconnect loop.
Confidence Score: 4/5Safe to merge with the two minor issues addressed; neither blocks foreground operation or causes data loss. The background mode gating logic is well-structured and consistent across MainActivity, OmiBleForegroundService, BleCompanionService, and the Flutter preference layer. The bonding removal is clean. Two issues worth fixing: the settings search drawer exposes the Background Mode entry on iOS where it has no effect, and the START_STICKY decision in onStartCommand is baked in at service-start time, so toggling background mode ON after the service is already running as non-sticky leaves a gap where an OS process-kill won't trigger a service restart. app/lib/pages/settings/settings_drawer.dart (missing Android guard on search entry) and app/android/app/src/main/kotlin/com/friend/ios/OmiBleForegroundService.kt (sticky-flag lifecycle edge case) Important Files Changed
Sequence DiagramsequenceDiagram
participant U as User
participant FL as Flutter (profile.dart)
participant SP as SharedPreferences
participant MA as MainActivity (onDestroy)
participant SVC as OmiBleForegroundService
participant STR as OmiBackgroundAudioStreamer
U->>FL: Toggle Background Mode ON
FL->>SP: "backgroundModeEnabled = true"
FL->>SP: "nativeBleStreamingEnabled = true"
U->>U: Close app (task removed)
MA->>SP: isBackgroundModeEnabled? → true
MA-->>SVC: (does NOT stopService)
SVC->>SVC: onTaskRemoved → keep alive
Note over SVC,STR: Flutter dead, service alive
SVC->>STR: handleCharacteristic (BLE audio)
STR->>SP: "loadConfig() → nativeBleStreamingEnabled=true"
STR->>STR: stream audio to WebSocket
U->>U: Toggle Background Mode OFF
FL->>SP: "backgroundModeEnabled = false"
FL->>SP: "nativeBleStreamingEnabled = false"
U->>U: Close app
MA->>SP: isBackgroundModeEnabled? → false
MA->>SVC: stopService()
SVC->>STR: stop(service_destroyed)
Reviews (1): Last reviewed commit: "feat(app): translate Background Mode str..." | Re-trigger Greptile |
| _SearchableItem(title: context.l10n.speechProfile, icon: profileIcon, onTap: goToProfile), | ||
| _SearchableItem(title: context.l10n.identifyingOthers, icon: profileIcon, onTap: goToProfile), | ||
| _SearchableItem(title: context.l10n.voiceResponseMode, icon: profileIcon, onTap: goToProfile), | ||
| _SearchableItem(title: context.l10n.backgroundModeTitle, icon: profileIcon, onTap: goToProfile), |
There was a problem hiding this comment.
The Background Mode search entry is added unconditionally, but the setting itself is guarded by
PlatformService.isAndroid in profile.dart. iOS users who search for "Background Mode" will see the result, tap it, navigate to Profile, and find nothing — a confusing dead-end.
| _SearchableItem(title: context.l10n.backgroundModeTitle, icon: profileIcon, onTap: goToProfile), | |
| if (PlatformService.isAndroid) _SearchableItem(title: context.l10n.backgroundModeTitle, icon: profileIcon, onTap: goToProfile), |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| @@ -616,13 +625,22 @@ class OmiBleForegroundService : Service() { | |||
| Log.i(TAG, "onStartCommand: no device address or saved device, stopping") | |||
| stopSelf() | |||
| } | |||
| } else { | |||
| Log.i(TAG, "onStartCommand: background mode off and no device address, stopping") | |||
| stopSelf() | |||
| } | |||
|
|
|||
| return START_STICKY | |||
| // Background mode off ⇒ non-sticky, so the OS won't resurrect the service after the app is closed. | |||
| return if (backgroundMode) START_STICKY else START_NOT_STICKY | |||
There was a problem hiding this comment.
Sticky-flag not updated when background mode changes at runtime
backgroundMode is read once at the top of onStartCommand and the return value (START_STICKY / START_NOT_STICKY) is fixed for the lifetime of that service invocation. Because OmiBleForegroundService.startService short-circuits when instance != null, onStartCommand is never called again for an already-running service, so the flag never refreshes.
Concrete failure: user opens the app (background mode off → service starts as START_NOT_STICKY), then enables background mode while the app is open. onTaskRemoved will correctly keep the service alive on task removal, but if the OS subsequently kills the process due to memory pressure, it will not restart the service because START_NOT_STICKY was already committed. Background mode is silently broken until the user opens the app again.
closes #5898
Summary
Two related Android BLE changes:
Background Mode
A new Beta toggle in Settings → Profile → Voice & People (always accessible; Android-only). Tapping it opens a sheet with the toggle, a short description, and a note that it currently works with Omi devices only and is improving.
autoConnect— low power, and it auto-reconnects when the device returns (no reliance on OS presence events, which fire spuriously for a connected peripheral that has stopped advertising).backgroundModeEnabledpref read natively; no Pigeon changes.BLE bonding removal
The Omi firmware no longer uses bonding (no
CONFIG_BT_SMP), but the app still requested a bond for Omi devices on connect. Against the non-bonding firmware the bond request failed →status=5(authentication failure) → a connect/disconnect loop, so the device never stayed connected and wouldn't reconnect when the app was reopened.Fix: only Limitless devices request bonding now (
device_connection.dart).Notes