From 8ada76c1b651a7e885f3c8c059072bd6d77519be Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Sun, 5 Mar 2023 08:57:59 +0000 Subject: [PATCH 1/3] fix StorageFolder.GetItemsAsync on android --- .../Platform/Storage/AndroidStorageItem.cs | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs b/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs index 9d6dd46d0e..1baf7df4e3 100644 --- a/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs +++ b/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs @@ -138,7 +138,43 @@ internal class AndroidStorageFolder : AndroidStorageItem, IStorageBookmarkFolder return Array.Empty(); } - using var javaFile = new JavaFile(Uri.Path!); + List files = new List(); + + var contentResolver = Activity.ContentResolver; + if (contentResolver == null) + { + return files; + } + + 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; + } // Java file represents files AND directories. Don't be confused. var files = await javaFile.ListFilesAsync().ConfigureAwait(false); From 20746b3ee228ab102cf863d1ab8e114f50a60d11 Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Sun, 5 Mar 2023 10:01:50 +0000 Subject: [PATCH 2/3] fix build --- .../Platform/Storage/AndroidStorageItem.cs | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs b/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs index 1baf7df4e3..0a34e6077c 100644 --- a/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs +++ b/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs @@ -174,27 +174,7 @@ internal class AndroidStorageFolder : AndroidStorageItem, IStorageBookmarkFolder } return files; - } - - // Java file represents files AND directories. Don't be confused. - var files = await javaFile.ListFilesAsync().ConfigureAwait(false); - if (files is null) - { - return Array.Empty(); - } - - 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()!; - } + } } internal sealed class WellKnownAndroidStorageFolder : AndroidStorageFolder From 989e45428a9fd9443751dd59ca689b05729629cc Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 6 Mar 2023 18:34:04 +0000 Subject: [PATCH 3/3] always kill testmanagerd --- azure-pipelines-integrationtests.yml | 1 + 1 file changed, 1 insertion(+) 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