fixed storage volume setup when launched right after device boot
This commit is contained in:
parent
a65cd84275
commit
f356e1dba0
3 changed files with 18 additions and 4 deletions
|
@ -15,7 +15,8 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
### Fixed
|
### 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
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ object StorageUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getVolumePaths(context: Context): Array<String> {
|
fun getVolumePaths(context: Context): Array<String> {
|
||||||
if (mStorageVolumePaths == null) {
|
if (mStorageVolumePaths == null || mStorageVolumePaths!!.isEmpty()) {
|
||||||
mStorageVolumePaths = findVolumePaths(context)
|
mStorageVolumePaths = findVolumePaths(context)
|
||||||
}
|
}
|
||||||
return mStorageVolumePaths!!
|
return mStorageVolumePaths!!
|
||||||
|
|
|
@ -27,7 +27,7 @@ class AndroidFileUtils {
|
||||||
if (_initialized) return;
|
if (_initialized) return;
|
||||||
|
|
||||||
separator = pContext.separator;
|
separator = pContext.separator;
|
||||||
storageVolumes = await storageService.getStorageVolumes();
|
await _initStorageVolumes();
|
||||||
primaryStorage = storageVolumes.firstWhereOrNull((volume) => volume.isPrimary)?.path ?? separator;
|
primaryStorage = storageVolumes.firstWhereOrNull((volume) => volume.isPrimary)?.path ?? separator;
|
||||||
// standard
|
// standard
|
||||||
dcimPath = pContext.join(primaryStorage, 'DCIM');
|
dcimPath = pContext.join(primaryStorage, 'DCIM');
|
||||||
|
@ -45,6 +45,16 @@ class AndroidFileUtils {
|
||||||
_initialized = true;
|
_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 {
|
Future<void> initAppNames() async {
|
||||||
if (_packages.isEmpty) {
|
if (_packages.isEmpty) {
|
||||||
debugPrint('Access installed app inventory');
|
debugPrint('Access installed app inventory');
|
||||||
|
@ -142,11 +152,14 @@ class Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class StorageVolume {
|
class StorageVolume extends Equatable {
|
||||||
final String? _description;
|
final String? _description;
|
||||||
final String path, state;
|
final String path, state;
|
||||||
final bool isPrimary, isRemovable;
|
final bool isPrimary, isRemovable;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [_description, path, state, isPrimary, isRemovable];
|
||||||
|
|
||||||
const StorageVolume({
|
const StorageVolume({
|
||||||
required String? description,
|
required String? description,
|
||||||
required this.isPrimary,
|
required this.isPrimary,
|
||||||
|
|
Loading…
Reference in a new issue