From 4ae3e5e7c676c6b166ea7df1af16238d7f5fd95b Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Mon, 23 Jan 2023 21:46:50 +0200 Subject: [PATCH 1/5] Fix MediaPicker capture methods in Android 13+ Thanks to @Ghostbird in https://github.com/dotnet/maui/pull/12766 --- Xamarin.Essentials/MediaPicker/MediaPicker.android.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs b/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs index 261aa9880..6086c8c5e 100644 --- a/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs +++ b/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs @@ -56,7 +56,9 @@ static Task PlatformCaptureVideoAsync(MediaPickerOptions options) static async Task PlatformCaptureAsync(MediaPickerOptions options, bool photo) { await Permissions.EnsureGrantedAsync(); - await Permissions.EnsureGrantedAsync(); + // StorageWrite no longer exists starting from Android API 33 + if (!OperatingSystem.IsAndroidVersionAtLeast(33)) + await Permissions.EnsureGrantedAsync(); var capturePhotoIntent = new Intent(photo ? MediaStore.ActionImageCapture : MediaStore.ActionVideoCapture); From 232cc1f19d4b961333eaff2ab5520ab13c6d5fa0 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 24 Jan 2023 21:13:14 +0200 Subject: [PATCH 2/5] Update MediaPicker.android.cs --- Xamarin.Essentials/MediaPicker/MediaPicker.android.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs b/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs index 6086c8c5e..857821758 100644 --- a/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs +++ b/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs @@ -56,9 +56,9 @@ static Task PlatformCaptureVideoAsync(MediaPickerOptions options) static async Task PlatformCaptureAsync(MediaPickerOptions options, bool photo) { await Permissions.EnsureGrantedAsync(); - // StorageWrite no longer exists starting from Android API 33 - if (!OperatingSystem.IsAndroidVersionAtLeast(33)) - await Permissions.EnsureGrantedAsync(); + // StorageWrite no longer exists starting from Android API 33 + if (!OperatingSystem.IsAndroidVersionAtLeast(33)) + await Permissions.EnsureGrantedAsync(); var capturePhotoIntent = new Intent(photo ? MediaStore.ActionImageCapture : MediaStore.ActionVideoCapture); From 19e3f5c3520926a9179134cc27ccb842befd11b6 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 24 Jan 2023 21:23:13 +0200 Subject: [PATCH 3/5] Update MediaPicker.android.cs --- Xamarin.Essentials/MediaPicker/MediaPicker.android.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs b/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs index 857821758..12a31f1b7 100644 --- a/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs +++ b/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs @@ -57,7 +57,7 @@ static async Task PlatformCaptureAsync(MediaPickerOptions options, b { await Permissions.EnsureGrantedAsync(); // StorageWrite no longer exists starting from Android API 33 - if (!OperatingSystem.IsAndroidVersionAtLeast(33)) + if (!Platform.HasApiLevel(33)) await Permissions.EnsureGrantedAsync(); var capturePhotoIntent = new Intent(photo ? MediaStore.ActionImageCapture : MediaStore.ActionVideoCapture); From f654de5f6bc65aa8343751751d9d9827460e3036 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 24 Jan 2023 21:30:19 +0200 Subject: [PATCH 4/5] Update MediaPicker.android.cs --- Xamarin.Essentials/MediaPicker/MediaPicker.android.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs b/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs index 12a31f1b7..e75cbe059 100644 --- a/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs +++ b/Xamarin.Essentials/MediaPicker/MediaPicker.android.cs @@ -56,6 +56,7 @@ static Task PlatformCaptureVideoAsync(MediaPickerOptions options) static async Task PlatformCaptureAsync(MediaPickerOptions options, bool photo) { await Permissions.EnsureGrantedAsync(); + // StorageWrite no longer exists starting from Android API 33 if (!Platform.HasApiLevel(33)) await Permissions.EnsureGrantedAsync(); From 66042ed8982f5c6173df3d79e3e0cec39a6b1eae Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 24 Jan 2023 21:31:39 +0200 Subject: [PATCH 5/5] error SA1027: Tabs and spaces should be used correctly --- .../SecureStorage/SecureStorage.android.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Xamarin.Essentials/SecureStorage/SecureStorage.android.cs b/Xamarin.Essentials/SecureStorage/SecureStorage.android.cs index e8c4f2eb2..1724df206 100644 --- a/Xamarin.Essentials/SecureStorage/SecureStorage.android.cs +++ b/Xamarin.Essentials/SecureStorage/SecureStorage.android.cs @@ -128,11 +128,11 @@ static void PlatformRemoveAll() => internal static bool AlwaysUseAsymmetricKeyStorage { get; set; } = false; - // While MD5 is deemed to be not secure anymore, it is not used in a security context here. - // Here we hash a key value to ensure compatibility with the underlying platform's preferences storage (so the key was a determinate length and didn't exceed platform limits). - // As part as Microsofts ongoing efforts to secure the .NET ecosystem, this usage of an insecure hashing mechanism was flagged. - // An exception has been requested for the usage of this "unsafe" hashing mechanism. - // More details here (internal link): https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1676270 + // While MD5 is deemed to be not secure anymore, it is not used in a security context here. + // Here we hash a key value to ensure compatibility with the underlying platform's preferences storage (so the key was a determinate length and didn't exceed platform limits). + // As part as Microsofts ongoing efforts to secure the .NET ecosystem, this usage of an insecure hashing mechanism was flagged. + // An exception has been requested for the usage of this "unsafe" hashing mechanism. + // More details here (internal link): https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1676270 internal static string Md5Hash(string input) { var hash = new StringBuilder();