From ff322cd2dd5f1e89683f34ee8b2832eaae03e58a Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Wed, 8 Jul 2020 14:09:08 -0500 Subject: [PATCH] Modified Permissions Flow (#1005) Permissions flow for Android was causing the white screen on initial permission grant on occasion. Moved permission grant to pre-TOTP page load. --- src/Android/MainActivity.cs | 4 ++-- src/App/Pages/Vault/AddEditPage.xaml.cs | 8 ++++++++ src/App/Utilities/PermissionManager.cs | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/App/Utilities/PermissionManager.cs diff --git a/src/Android/MainActivity.cs b/src/Android/MainActivity.cs index d36a6df89..1cf8ba7fb 100644 --- a/src/Android/MainActivity.cs +++ b/src/Android/MainActivity.cs @@ -18,6 +18,7 @@ using Android.Nfc; using Bit.App.Utilities; using System.Threading.Tasks; using AndroidX.Core.Content; +using ZXing.Net.Mobile.Android; namespace Bit.Droid { @@ -193,8 +194,7 @@ namespace Bit.Droid else { Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); - ZXing.Net.Mobile.Forms.Android.PermissionsHandler.OnRequestPermissionsResult( - requestCode, permissions, grantResults); + PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults); } base.OnRequestPermissionsResult(requestCode, permissions, grantResults); } diff --git a/src/App/Pages/Vault/AddEditPage.xaml.cs b/src/App/Pages/Vault/AddEditPage.xaml.cs index 654159c40..3a8d9cc06 100644 --- a/src/App/Pages/Vault/AddEditPage.xaml.cs +++ b/src/App/Pages/Vault/AddEditPage.xaml.cs @@ -1,12 +1,14 @@ using Bit.App.Abstractions; using Bit.App.Models; using Bit.App.Resources; +using Bit.App.Utilities; using Bit.Core; using Bit.Core.Abstractions; using Bit.Core.Enums; using Bit.Core.Utilities; using System.Collections.Generic; using System.Threading.Tasks; +using Xamarin.Essentials; using Xamarin.Forms; using Xamarin.Forms.PlatformConfiguration; using Xamarin.Forms.PlatformConfiguration.iOSSpecific; @@ -243,6 +245,12 @@ namespace Bit.App.Pages { if (DoOnce()) { + var cameraPermission = await PermissionManager.CheckAndRequestPermissionAsync(new Permissions.Camera()); + if (cameraPermission != PermissionStatus.Granted) + { + return; + } + var page = new ScanPage(key => { Device.BeginInvokeOnMainThread(async () => diff --git a/src/App/Utilities/PermissionManager.cs b/src/App/Utilities/PermissionManager.cs new file mode 100644 index 000000000..8af2ecff2 --- /dev/null +++ b/src/App/Utilities/PermissionManager.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; +using Xamarin.Essentials; +using static Xamarin.Essentials.Permissions; + +namespace Bit.App.Utilities +{ + public static class PermissionManager + { + public static async Task CheckAndRequestPermissionAsync(T permission) + where T : BasePermission + { + var status = await permission.CheckStatusAsync(); + if (status != PermissionStatus.Granted) + { + status = await permission.RequestAsync(); + } + + return status; + } + } +}