From a906545f1dc43fc702510a7b2dc2a7e2212b2d0c Mon Sep 17 00:00:00 2001 From: Gulam Ali H Date: Fri, 21 Jun 2024 23:52:05 +0530 Subject: [PATCH] feat: added a way to confirm if a platform is supported by the plugin (#9) --- .../AuthenticationRequest.cs | 4 +- .../AuthenticationResponse.cs | 2 +- .../AuthenticatorStrength.cs | 1 + .../BiometricAuthenticationService.cs | 2 +- .../BiometricHwStatus.cs | 10 +- .../BiometricResponseStatus.cs | 4 +- .../Plugin.Maui.Biometric/BiometricService.cs | 6 +- .../BiometricService.net.cs | 4 +- .../Plugin.Maui.Biometric/BiometricType.cs | 4 +- .../Plugin.Maui.Biometric/IBiometric.cs | 6 +- .../Platforms/Android/AuthCallback.cs | 2 +- .../Android/BiometricService.android.cs | 2 + .../Platforms/iOS/BiometricService.ios.cs | 2 + .../Plugin.Maui.Biometric.csproj | 8 +- Plugin.Maui.Biometric/Samples/App.xaml | 14 +-- Plugin.Maui.Biometric/Samples/App.xaml.cs | 13 +- Plugin.Maui.Biometric/Samples/AppShell.xaml | 8 +- .../Samples/AppShell.xaml.cs | 11 +- Plugin.Maui.Biometric/Samples/MainPage.xaml | 37 +++--- .../Samples/MainPage.xaml.cs | 4 +- Plugin.Maui.Biometric/Samples/MauiProgram.cs | 44 ++++--- .../Samples/Platforms/Android/MainActivity.cs | 3 +- .../Platforms/Android/MainApplication.cs | 13 +- .../Android/Resources/values/colors.xml | 2 +- .../Samples/Platforms/iOS/AppDelegate.cs | 5 +- .../Samples/Platforms/iOS/Program.cs | 20 ++-- .../Samples/Properties/launchSettings.json | 2 +- .../Samples/Resources/AppIcon/appicon.svg | 5 +- .../Samples/Resources/AppIcon/appiconfg.svg | 12 +- .../Samples/Resources/Splash/splash.svg | 13 +- .../Samples/Resources/Styles/Colors.xaml | 34 +++--- .../Samples/Resources/Styles/Styles.xaml | 112 +++++++++--------- README.md | 4 + 33 files changed, 205 insertions(+), 208 deletions(-) diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticationRequest.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticationRequest.cs index 6f3ebfc..9a64ea6 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticationRequest.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticationRequest.cs @@ -5,7 +5,7 @@ public class AuthenticationRequest public bool AllowPasswordAuth { get; set; } public string Title { get; set; } public string Subtitle { get; set; } - public string NegativeText { get; set; } - public string Description { get; set; } + public string NegativeText { get; set; } + public string Description { get; set; } public AuthenticatorStrength AuthStrength { get; set; } } \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticationResponse.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticationResponse.cs index a6d7ac9..e8570df 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticationResponse.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticationResponse.cs @@ -5,4 +5,4 @@ public class AuthenticationResponse public BiometricResponseStatus Status { get; set; } public AuthenticationType AuthenticationType { get; set; } public string ErrorMsg { get; set; } -} +} \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticatorStrength.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticatorStrength.cs index 39fe321..96f84e1 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticatorStrength.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/AuthenticatorStrength.cs @@ -5,6 +5,7 @@ public enum AuthenticatorStrength { //Authentication using a Class 3 biometric, as defined on the Android compatibility definition page. Strong, + //Authentication using a Class 2 biometric, as defined on the Android compatibility definition page. Weak } \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricAuthenticationService.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricAuthenticationService.cs index b859ee9..8fcfd6c 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricAuthenticationService.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricAuthenticationService.cs @@ -1,6 +1,6 @@ namespace Plugin.Maui.Biometric; -public class BiometricAuthenticationService +public static class BiometricAuthenticationService { private static readonly Lazy defaultImpl = new(() => new BiometricService(), LazyThreadSafetyMode.PublicationOnly); diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricHwStatus.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricHwStatus.cs index 6db6746..c7e1bd5 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricHwStatus.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricHwStatus.cs @@ -6,11 +6,11 @@ /// public enum BiometricHwStatus { - NoHardware, - Unavailable, - Unsupported, - NotEnrolled, - LockedOut, + NoHardware, + Unavailable, + Unsupported, + NotEnrolled, + LockedOut, Success, Failure } \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricResponseStatus.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricResponseStatus.cs index 8e72a3d..219754a 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricResponseStatus.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricResponseStatus.cs @@ -2,6 +2,6 @@ public enum BiometricResponseStatus { - Failure, - Success + Failure, + Success } \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricService.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricService.cs index 4f25f08..1698340 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricService.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricService.cs @@ -1,10 +1,14 @@ -namespace Plugin.Maui.Biometric; +namespace Plugin.Maui.Biometric; internal partial class BiometricService : IBiometric { + public bool IsPlatformSupported { get; } = GetIsPlatformSupported(); + public partial Task GetAuthenticationStatusAsync(AuthenticatorStrength authStrength = AuthenticatorStrength.Strong); public partial Task AuthenticateAsync(AuthenticationRequest request, CancellationToken token); public partial Task> GetEnrolledBiometricTypesAsync(); + + private static partial bool GetIsPlatformSupported(); } \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricService.net.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricService.net.cs index 58d15be..fb33b75 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricService.net.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricService.net.cs @@ -1,4 +1,4 @@ -namespace Plugin.Maui.Biometric; +namespace Plugin.Maui.Biometric; #if NET && !ANDROID && !IOS internal partial class BiometricService : IBiometric { @@ -16,5 +16,7 @@ public partial Task> GetEnrolledBiometricTypesAsync() { throw new NotImplementedException(); } + + private static partial bool GetIsPlatformSupported() => false; } #endif \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricType.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricType.cs index 8c43ba4..1a2e96f 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricType.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/BiometricType.cs @@ -1,8 +1,8 @@ namespace Plugin.Maui.Biometric; + public enum BiometricType { None, Fingerprint, Face -} - +} \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/IBiometric.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/IBiometric.cs index 19c6a24..35808a6 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/IBiometric.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/IBiometric.cs @@ -1,8 +1,12 @@ -namespace Plugin.Maui.Biometric; +namespace Plugin.Maui.Biometric; public interface IBiometric { Task GetAuthenticationStatusAsync(AuthenticatorStrength authStrength = AuthenticatorStrength.Strong); + Task AuthenticateAsync(AuthenticationRequest request, CancellationToken token); + Task> GetEnrolledBiometricTypesAsync(); + + bool IsPlatformSupported { get; } } \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/Android/AuthCallback.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/Android/AuthCallback.cs index f583caa..ce8a136 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/Android/AuthCallback.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/Android/AuthCallback.cs @@ -23,7 +23,7 @@ public override void OnAuthenticationSucceeded(BiometricPrompt.AuthenticationRes ErrorMsg = string.Empty }); } - + public override void OnAuthenticationError(int errorCode, ICharSequence errString) { base.OnAuthenticationError(errorCode, errString); diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/Android/BiometricService.android.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/Android/BiometricService.android.cs index c6418b4..6f90ced 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/Android/BiometricService.android.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/Android/BiometricService.android.cs @@ -125,4 +125,6 @@ public partial Task> GetEnrolledBiometricTypesAsync() } return Task.FromResult(availableOptions); } + + private static partial bool GetIsPlatformSupported() => true; } \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/iOS/BiometricService.ios.cs b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/iOS/BiometricService.ios.cs index b06afb8..c116bfe 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/iOS/BiometricService.ios.cs +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Platforms/iOS/BiometricService.ios.cs @@ -64,4 +64,6 @@ public partial Task> GetEnrolledBiometricTypesAsync() } return Task.FromResult(availableOptions); } + + private static partial bool GetIsPlatformSupported() => true; } \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Plugin.Maui.Biometric.csproj b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Plugin.Maui.Biometric.csproj index 4ecc317..184e787 100644 --- a/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Plugin.Maui.Biometric.csproj +++ b/Plugin.Maui.Biometric/Plugin.Maui.Biometric/Plugin.Maui.Biometric.csproj @@ -9,14 +9,14 @@ true 0.0.2 0.0.2 - 0.0.2-pre + 0.0.2 en Plugin.Maui.Biometric latest FreakyAli MIT - A Biometric plugin for .NET MAUI + A Biometric plug-in for .NET MAUI auth_icon.jpg https://github.com/FreakyAli/Plugin.Maui.Biometric https://github.com/FreakyAli/Plugin.Maui.Biometric @@ -40,13 +40,13 @@ true - false + false - + diff --git a/Plugin.Maui.Biometric/Samples/App.xaml b/Plugin.Maui.Biometric/Samples/App.xaml index 58ffc95..9133b8b 100644 --- a/Plugin.Maui.Biometric/Samples/App.xaml +++ b/Plugin.Maui.Biometric/Samples/App.xaml @@ -1,8 +1,9 @@ - - + + @@ -11,5 +12,4 @@ - - + \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Samples/App.xaml.cs b/Plugin.Maui.Biometric/Samples/App.xaml.cs index 923ddbc..380b1fa 100644 --- a/Plugin.Maui.Biometric/Samples/App.xaml.cs +++ b/Plugin.Maui.Biometric/Samples/App.xaml.cs @@ -2,11 +2,10 @@ public partial class App : Application { - public App() - { - InitializeComponent(); - - MainPage = new AppShell(); - } -} + public App() + { + InitializeComponent(); + MainPage = new AppShell(); + } +} \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Samples/AppShell.xaml b/Plugin.Maui.Biometric/Samples/AppShell.xaml index 7eacabd..37364f7 100644 --- a/Plugin.Maui.Biometric/Samples/AppShell.xaml +++ b/Plugin.Maui.Biometric/Samples/AppShell.xaml @@ -4,13 +4,11 @@ xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Samples" - Shell.FlyoutBehavior="Disabled" - Title="Samples"> + Title="Samples" + Shell.FlyoutBehavior="Disabled"> - - - + \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Samples/AppShell.xaml.cs b/Plugin.Maui.Biometric/Samples/AppShell.xaml.cs index 1609efb..77ba257 100644 --- a/Plugin.Maui.Biometric/Samples/AppShell.xaml.cs +++ b/Plugin.Maui.Biometric/Samples/AppShell.xaml.cs @@ -2,9 +2,8 @@ public partial class AppShell : Shell { - public AppShell() - { - InitializeComponent(); - } -} - + public AppShell() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/Plugin.Maui.Biometric/Samples/MainPage.xaml b/Plugin.Maui.Biometric/Samples/MainPage.xaml index f75ecb6..50547e4 100644 --- a/Plugin.Maui.Biometric/Samples/MainPage.xaml +++ b/Plugin.Maui.Biometric/Samples/MainPage.xaml @@ -1,37 +1,34 @@  - + - + + HeightRequest="185" + SemanticProperties.Description="dot net bot in a race car number eight" + Source="dotnet_bot.png" />