fix(mobile-app): App进入后台时立即上传遥测队列

问题:TelemetryService.dispose()从未被调用,导致forceUploadAll()
永远不执行;uploadIfNeeded()有10条最小阈值,单次会话只有2-3条
事件无法触发上传,设备信息永远留在本地队列。

修复:进入后台(paused)结束session后,立即调用uploadBatch()
绕过10条阈值,确保每次App切换到后台时都能上报事件。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-05 19:11:25 -08:00
parent 2c312a850b
commit 9e90294d0e
2 changed files with 9 additions and 0 deletions

View File

@ -95,6 +95,9 @@ class SessionManager with WidgetsBindingObserver {
_state = SessionState.background;
_endCurrentSession();
// session_end 10
_telemetryService?.flushOnBackground();
}
///

View File

@ -373,6 +373,12 @@ class TelemetryService {
///
DeviceContext? get deviceContext => _deviceContext;
/// App进入后台时调用10
Future<void> flushOnBackground() async {
await _uploader.uploadBatch(batchSize: 50);
debugPrint('📊 [Telemetry] Flushed on background');
}
/// App退出前调用
Future<void> dispose() async {
_configSyncTimer?.cancel();