diff --git a/azure-pipelines-integrationtests.yml b/azure-pipelines-integrationtests.yml index dec94a44d5..939d09c959 100644 --- a/azure-pipelines-integrationtests.yml +++ b/azure-pipelines-integrationtests.yml @@ -24,6 +24,7 @@ jobs: fi sudo xcode-select -s /Applications/Xcode.app/Contents/Developer pkill node + pkill testmanagerd appium > appium.out & pkill IntegrationTestApp ./build.sh CompileNative diff --git a/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs b/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs index 9d6dd46d0e..0a34e6077c 100644 --- a/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs +++ b/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs @@ -138,27 +138,43 @@ internal class AndroidStorageFolder : AndroidStorageItem, IStorageBookmarkFolder return Array.Empty(); } - using var javaFile = new JavaFile(Uri.Path!); + List files = new List(); - // Java file represents files AND directories. Don't be confused. - var files = await javaFile.ListFilesAsync().ConfigureAwait(false); - if (files is null) + var contentResolver = Activity.ContentResolver; + if (contentResolver == null) { - return Array.Empty(); + return files; } - return files - .Select(f => (file: f, uri: AndroidUri.FromFile(f))) - .Where(t => t.uri is not null) - .Select(t => t.file switch - { - { IsFile: true } => (IStorageItem)new AndroidStorageFile(Activity, t.uri!), - { IsDirectory: true } => new AndroidStorageFolder(Activity, t.uri!, false), - _ => null - }) - .Where(i => i is not null) - .ToArray()!; - } + var childrenUri = DocumentsContract.BuildChildDocumentsUriUsingTree(Uri!, DocumentsContract.GetTreeDocumentId(Uri)); + + var projection = new[] + { + DocumentsContract.Document.ColumnDocumentId, + DocumentsContract.Document.ColumnMimeType + }; + if (childrenUri != null) + { + using var cursor = contentResolver.Query(childrenUri, projection, null, null, null); + + if (cursor != null) + while (cursor.MoveToNext()) + { + var mime = cursor.GetString(1); + var id = cursor.GetString(0); + var uri = DocumentsContract.BuildDocumentUriUsingTree(Uri!, id); + if (uri == null) + { + continue; + } + + files.Add(mime == DocumentsContract.Document.MimeTypeDir ? new AndroidStorageFolder(Activity, uri, false) : + new AndroidStorageFile(Activity, uri)); + } + } + + return files; + } } internal sealed class WellKnownAndroidStorageFolder : AndroidStorageFolder