feat: enhance background streaming service with foreground handling
- Improved BackgroundStreamingService to manage foreground service notifications more effectively, ensuring compliance with Android requirements. - Implemented dynamic foreground service type resolution based on microphone permission, enhancing service behavior based on app state. - Added checks for app foreground status in connectivity management, improving responsiveness to network changes. - Refactored notification handling to streamline service lifecycle management and improve code maintainability.
This commit is contained in:
@@ -58,13 +58,18 @@ void _scheduleConversationWarmup(Ref ref, {bool force = false}) {
|
||||
return;
|
||||
}
|
||||
|
||||
final connectivity = ref.read(connectivityServiceProvider);
|
||||
if (!connectivity.isAppForeground) {
|
||||
return;
|
||||
}
|
||||
|
||||
final isOnline = ref.read(isOnlineProvider);
|
||||
if (!isOnline) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If network latency is high, delay warmup further to reduce contention
|
||||
final latency = ref.read(connectivityServiceProvider).lastLatencyMs;
|
||||
final latency = connectivity.lastLatencyMs;
|
||||
final extraDelay = latency > 800
|
||||
? 400
|
||||
: latency > 400
|
||||
@@ -99,6 +104,11 @@ void _scheduleConversationWarmup(Ref ref, {bool force = false}) {
|
||||
await Future.delayed(Duration(milliseconds: extraDelay));
|
||||
}
|
||||
try {
|
||||
if (!ref.read(connectivityServiceProvider).isAppForeground) {
|
||||
statusController.set(_ConversationWarmupStatus.idle);
|
||||
return;
|
||||
}
|
||||
|
||||
final existing = ref.read(conversationsProvider);
|
||||
if (existing.hasValue) {
|
||||
statusController.set(_ConversationWarmupStatus.complete);
|
||||
|
||||
Reference in New Issue
Block a user