fix(download): preserve SAF and defer background starts

This commit is contained in:
zarzet
2026-08-09 05:23:47 +07:00
parent 2612da81c3
commit a59c749089
9 changed files with 271 additions and 33 deletions
+54
View File
@@ -0,0 +1,54 @@
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:spotiflac_android/providers/download_queue_provider.dart';
import 'package:spotiflac_android/services/platform_bridge.dart';
void main() {
group('download storage recovery', () {
test('requires reauthorization instead of redirecting SAF downloads', () {
expect(
storageWriteRecoveryFor(useSaf: true),
StorageWriteRecovery.requestSafAccess,
);
});
test('keeps automatic fallback for app-managed folders', () {
expect(
storageWriteRecoveryFor(useSaf: false),
StorageWriteRecovery.useAppFolderFallback,
);
});
});
group('foreground download start policy', () {
test('allows service launch only while the app is resumed', () {
expect(
canStartForegroundDownloadForLifecycle(AppLifecycleState.resumed),
isTrue,
);
expect(
canStartForegroundDownloadForLifecycle(AppLifecycleState.inactive),
isFalse,
);
expect(
canStartForegroundDownloadForLifecycle(AppLifecycleState.paused),
isFalse,
);
expect(canStartForegroundDownloadForLifecycle(null), isFalse);
});
test('recognizes the typed platform denial', () {
expect(
isForegroundServiceStartNotAllowed(
PlatformException(code: foregroundServiceStartNotAllowedCode),
),
isTrue,
);
expect(
isForegroundServiceStartNotAllowed(PlatformException(code: 'ERROR')),
isFalse,
);
});
});
}