fixed storage volume setup when launched right after device boot

This commit is contained in:
Thibault Deckers 2022-08-09 22:33:37 +02:00
parent a65cd84275
commit f356e1dba0
3 changed files with 18 additions and 4 deletions

View file

@ -15,7 +15,8 @@ All notable changes to this project will be documented in this file.
### Fixed
- app launch despite faulty storage volumes on Android <11
- storage volume setup despite faulty volume on Android <11
- storage volume setup when launched right after device boot
### Changed

View file

@ -82,7 +82,7 @@ object StorageUtils {
}
fun getVolumePaths(context: Context): Array<String> {
if (mStorageVolumePaths == null) {
if (mStorageVolumePaths == null || mStorageVolumePaths!!.isEmpty()) {
mStorageVolumePaths = findVolumePaths(context)
}
return mStorageVolumePaths!!

View file

@ -27,7 +27,7 @@ class AndroidFileUtils {
if (_initialized) return;
separator = pContext.separator;
storageVolumes = await storageService.getStorageVolumes();
await _initStorageVolumes();
primaryStorage = storageVolumes.firstWhereOrNull((volume) => volume.isPrimary)?.path ?? separator;
// standard
dcimPath = pContext.join(primaryStorage, 'DCIM');
@ -45,6 +45,16 @@ class AndroidFileUtils {
_initialized = true;
}
Future<void> _initStorageVolumes() async {
storageVolumes = await storageService.getStorageVolumes();
if (storageVolumes.isEmpty) {
// this can happen when the device is booting up
debugPrint('Storage volume list is empty. Retrying in a second...');
await Future.delayed(const Duration(seconds: 1));
await _initStorageVolumes();
}
}
Future<void> initAppNames() async {
if (_packages.isEmpty) {
debugPrint('Access installed app inventory');
@ -142,11 +152,14 @@ class Package {
}
@immutable
class StorageVolume {
class StorageVolume extends Equatable {
final String? _description;
final String path, state;
final bool isPrimary, isRemovable;
@override
List<Object?> get props => [_description, path, state, isPrimary, isRemovable];
const StorageVolume({
required String? description,
required this.isPrimary,