diff --git a/CHANGELOG.md b/CHANGELOG.md index 94212c02b..ee8f20c5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/utils/StorageUtils.kt b/android/app/src/main/kotlin/deckers/thibault/aves/utils/StorageUtils.kt index f61aa79d1..33db8d6f6 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/utils/StorageUtils.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/utils/StorageUtils.kt @@ -82,7 +82,7 @@ object StorageUtils { } fun getVolumePaths(context: Context): Array { - if (mStorageVolumePaths == null) { + if (mStorageVolumePaths == null || mStorageVolumePaths!!.isEmpty()) { mStorageVolumePaths = findVolumePaths(context) } return mStorageVolumePaths!! diff --git a/lib/utils/android_file_utils.dart b/lib/utils/android_file_utils.dart index cc6fff4ea..df8162f12 100644 --- a/lib/utils/android_file_utils.dart +++ b/lib/utils/android_file_utils.dart @@ -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 _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 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 get props => [_description, path, state, isPrimary, isRemovable]; + const StorageVolume({ required String? description, required this.isPrimary,