Fix PathAccessException on secondary profiles (#1754)

This commit is contained in:
Imran Remtulla
2024-11-01 13:28:10 -04:00
parent b1f9375bb1
commit 2ad88bf3ca

View File

@@ -743,6 +743,10 @@ class AppsProvider with ChangeNotifier {
return installed;
}
Future<String> getStorageRootPath() async {
return '/${(await getExternalStorageDirectory())!.uri.pathSegments.sublist(0, 3).join('/')}';
}
Future<void> moveObbFile(File file, String appId) async {
if (!file.path.toLowerCase().endsWith('.obb')) return;
@@ -751,7 +755,7 @@ class AppsProvider with ChangeNotifier {
await Permission.storage.request();
}
String obbDirPath = "/storage/emulated/0/Android/obb/$appId";
String obbDirPath = "${await getStorageRootPath()}/Android/obb/$appId";
Directory(obbDirPath).createSync(recursive: true);
String obbFileName = file.path.split("/").last;
@@ -1045,10 +1049,11 @@ class AppsProvider with ChangeNotifier {
Future<void> downloadFn(MapEntry<String, String> fileUrl, App app) async {
try {
var exportDir = await settingsProvider.getExportDir();
String downloadPath = '/storage/emulated/0/Download';
String downloadPath = '${await getStorageRootPath()}/Download';
bool downloadsAccessible = false;
try {
downloadsAccessible = Directory(downloadPath).existsSync();
Directory(downloadPath).listSync();
downloadsAccessible = true;
} catch (e) {
//
}