예제 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            _fingerprintManagerCompat = FingerprintManagerCompat.From(this);
            _cancelation       = new global::Android.Support.V4.OS.CancellationSignal();
            _sharedPreferences = PreferenceManager.GetDefaultSharedPreferences(this);
            //TODO rest shared Preferences: Application.Context.GetSharedPreferences("sampleSharedPreferencesName",FileCreationMode.Private);


            SetContentView(Resource.Layout.Main);

            _emailEditText    = FindViewById <EditText>(Resource.Id.emailEditText);
            _passwordEditText = FindViewById <EditText>(Resource.Id.passwordEditText);
            _signinButton     = FindViewById <Button>(Resource.Id.signinButton);
            _registerButton   = FindViewById <Button>(Resource.Id.registerButton);

            _signinButton.Click   += SignInButton_Click;
            _registerButton.Click += RegisterButton_Click;


            //Register from Shortcut options
            if (!string.IsNullOrEmpty(Intent?.Data?.LastPathSegment))
            {
                if (Intent.Data.LastPathSegment == "register")
                {
                    StartActivity(typeof(RegisterActivity));
                }
            }
        }
예제 #2
0
        public void AuthenticateAndroid(string reason)
        {
            // CryptoObjectHelper is described in the previous section.
            var cryptoHelper = new CryptoObjectHelper();

            var context = Android.App.Application.Context;
            //if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M)
            //{
            //    /* ==================================================================================================
            //     * android api 23 or higher
            //     * ================================================================================================*/
            //    var manager = context.GetSystemService(Context.FingerprintService) as FingerprintManager;
            //    // cancellationSignal can be used to manually stop the fingerprint scanner.
            //    var cancellationSignal = new Android.OS.CancellationSignal();
            //    var authenticationCallback = new SimpleAuthCallback();
            //    // Start the fingerprint scanner.
            //    manager.Authenticate(cryptoHelper.BuildCryptoObject(), cancellationSignal, FingerprintAuthenticationFlags.None, authenticationCallback, null);
            //    return;
            //}

            // Using the Android Support Library v4
            var managerCompat = FingerprintManagerCompat.From(context);
            // cancellationSignal can be used to manually stop the fingerprint scanner.
            var cancellationSignalCompat = new Android.Support.V4.OS.CancellationSignal();
            // AuthenticationCallback is a base class that will be covered later on in this guide.
            var callbackCompat = new SimpleCompatAuthCallback();

            // Start the fingerprint scanner.
            managerCompat.Authenticate(cryptoHelper.BuildCompatCryptoObject(), 0, cancellationSignalCompat, callbackCompat, null);
            //return new LocalAuthResult(false);
            //return Task.FromResult(new LocalAuthResult(false));
        }
예제 #3
0
        public bool Login()
        {
            var retVal = true;

            Android.Content.PM.Permission permissionResult = ContextCompat.CheckSelfPermission(context, Manifest.Permission.UseFingerprint);

            if (permissionResult == Android.Content.PM.Permission.Granted)
            {
            }
            else
            {
                // No permission.
                // https://developer.android.com/training/permissions/requesting.html
            }

            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(context);

            const int flags = 0;

            CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();

            // cancellationSignal - stop scanning
            _cancellationSignal = new Android.Support.V4.OS.CancellationSignal();

            fingerprintManager = FingerprintManagerCompat.From(context);

            // Callback method
            FingerprintManagerCompat.AuthenticationCallback authenticationCallback = new AuthResultsCallback();

            // Start scanning
            fingerprintManager.Authenticate(cryptoHelper.BuildCryptoObject(), flags, _cancellationSignal, authenticationCallback, null);

            return(retVal);
        }
 public override void OnCreate(Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     fingerprintManager = FingerprintManagerCompat.From(Context);
     RetainInstance     = true;
     CryptObjectHelper  = new CryptoObjectHelper();
 }
예제 #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            _fingerprintManager = FingerprintManagerCompat.From(this);
            _cancellationSignal = new global::Android.Support.V4.OS.CancellationSignal();
            _preferences        = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);

            _emailEditText    = FindViewById <EditText>(Resource.Id.emailEditText);
            _passwordEditText = FindViewById <EditText>(Resource.Id.passwordEditText);
            _loginButton      = FindViewById <Button>(Resource.Id.loginButton);
            _registerButton   = FindViewById <Button>(Resource.Id.registerButton);

            _loginButton.Click    += LoginButton_Click;
            _registerButton.Click += RegisterButton_Click;

            if (string.IsNullOrEmpty(Intent?.Data?.LastPathSegment))
            {
                return;
            }
            if (Intent.Data.LastPathSegment == "register")
            {
                StartActivity(typeof(RegisterActivity));
            }
        }
        public bool IsFingerprintSupported()
        {
            if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.M)
            {
                return(false);
            }

            if (fingerprintManager == null)
            {
                fingerprintManager = FingerprintManagerCompat.From(activity);
            }
            if (fingerprintManager == null || !fingerprintManager.IsHardwareDetected)
            {
                return(false);
            }
            if (!fingerprintManager.HasEnrolledFingerprints)
            {
                return(false);
            }

            if (keyguardManager == null)
            {
                keyguardManager = (KeyguardManager)activity.GetSystemService(Context.KeyguardService);
            }
            if (keyguardManager == null || !keyguardManager.IsKeyguardSecure)
            {
                return(false);
            }

            return(true);
        }
예제 #7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            fpm               = FingerprintManagerCompat.From(this);
            cancel            = new Android.Support.V4.OS.CancellationSignal();
            sharedPreferences = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
            etEmail          = FindViewById <EditText>(Resource.Id.etEmail);
            etPassword       = FindViewById <EditText>(Resource.Id.etPassword);
            btnSignIn        = FindViewById <Button>(Resource.Id.btnSignIn);
            btnSignUp        = FindViewById <Button>(Resource.Id.btnSignUp);
            btnSignIn.Click += BtnSignIn_Click;
            btnSignUp.Click += BtnSignUp_Click;
            string Email = Intent.GetStringExtra("email");

            etEmail.Text = Email;
            string Password = Intent.GetStringExtra("password");

            etPassword.Text = Password;
            if (!string.IsNullOrEmpty(Intent?.Data?.LastPathSegment))
            {
                if (Intent.Data.LastPathSegment == "SignUp")
                {
                    var intent = new Intent(this, typeof(SignUpActivity));
                    StartActivity(intent);
                }
            }
        }
예제 #8
0
        private async Task <bool> Authenticate()
        {
            var callback           = new SimpleAuthCallbacks();
            var context            = Android.App.Application.Context;
            var isUsingFingerprint = ContextCompat.CheckSelfPermission(context, Manifest.Permission.UseFingerprint);

            if (isUsingFingerprint == Permission.Granted)
            {
                var cancellationSignal = new Android.Support.V4.OS.CancellationSignal();
                var cryptHelper        = new CryptoObjectHelper();
                var fingerprintManager = FingerprintManagerCompat.From(context);
                fingerprintManager.Authenticate(
                    cryptHelper.BuildCryptoObject(),
                    (int)FingerprintAuthenticationFlags.None, /* flags */
                    cancellationSignal,
                    callback,
                    null
                    );
            }

            while (callback.IsWaiting)
            {
                await Task.Delay(87);
            }

            return(callback.Status == SimpleAuthCallbacks.AuthenticateResult.Success);
        }
        public void Authenticate(Action successAction, Action failAction)
        {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(Android.App.Application.Context);
            const int          flags        = 0; /* always zero (0) */
            CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();
            // Using the Support Library classes for maximum reach
            FingerprintManagerCompat fingerPrintManager = FingerprintManagerCompat.From(Android.App.Application.Context);

            // AuthCallbacks is a C# class defined elsewhere in code.
            FingerprintManagerCompat.AuthenticationCallback authenticationCallback = new AuthenticationCallBack();

            var page = new FingerprintAuthenticationPage((int)Android.OS.Build.VERSION.SdkInt);

            Xamarin.Forms.Application.Current.MainPage.Navigation.PushPopupAsync(page);

            MessagingCenter.Subscribe <string, string>("FingerprintAuthentication", "Authenticate", (sender, arg) =>
            {
                string result = arg;

                if (arg == "true")
                {
                    MessagingCenter.Unsubscribe <string, string>("FingerprintAuthentication", "Authenticate");
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Xamarin.Forms.Application.Current.MainPage.Navigation.PopPopupAsync();
                    });
                    //Do the thing when success to pass
                    if (successAction != null)
                    {
                        successAction.Invoke();
                    }
                }
                else if (arg == "false")
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        page.SetFailLabelText("Fail to authenticate!");
                    });
                }
                else
                {
                    MessagingCenter.Unsubscribe <string, string>("FingerprintAuthentication", "Authenticate");
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Xamarin.Forms.Application.Current.MainPage.Navigation.PopPopupAsync();
                    });
                    //Do the thing when fail to pass
                    if (failAction != null)
                    {
                        failAction.Invoke();
                    }
                }
            });



            cancellationSignal = new Android.Support.V4.OS.CancellationSignal();
            // Here is where the CryptoObjectHelper builds the CryptoObject.
            fingerprintManager.Authenticate(cryptoHelper.BuildCryptoObject(), flags, cancellationSignal, authenticationCallback, null);
        }
 private bool HasEnrolledFingerprints(FingerprintManagerCompat fingerprintManagerCmp = null)
 {
     try
     {
         FingerprintManagerCompat fpManager = fingerprintManagerCmp;
         if (fpManager == null)
         {
             fpManager = FingerprintManagerCompat.From(CurrentContext);
         }
         if (!fpManager.IsHardwareDetected)
         {
             throw new Exception(Resources.GetString(Resource.String.errFpHWNotDetected));
         }
         if (!fpManager.HasEnrolledFingerprints)
         {
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         Android.Util.Log.Error(App.Title, ex.Message);
         return(false);
     }
 }
예제 #11
0
        Button _startAuthenticationScanButton, _failedScanAgainButton, _showAccountBalanceButton, _transferAccountBalanceButton, _transferBalanceButton;// _scanAgainButton,

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_fingerprintmanager_api);
            client = new HttpClient();
            InitializeViewReferences();

            _fingerprintManager = FingerprintManagerCompat.From(this);
            string canScanMsg = CheckFingerprintEligibility();

            _startAuthenticationScanButton.Click += StartFingerprintScan;
            //_startAuthenticationScanButton.Click += ShowTransferPanel;

            //_scanAgainButton.Click += ScanAgainButtonOnClick;
            _failedScanAgainButton.Click        += RecheckEligibility;
            _showAccountBalanceButton.Click     += ShowAccountBalance;
            _transferAccountBalanceButton.Click += ShowTransferPanel;
            _transferBalanceButton.Click        += makeTransaction;

            if (_canScan)
            {
                _dialogFrag = FingerprintManagerApiDialogFragment.NewInstance(_fingerprintManager);
            }
            else
            {
                ShowError("Can't use this device for the sample.", canScanMsg);
            }
        }
        protected override async Task <GetSecureValueResult> NativeGetSecureValue(SecureValueRequestConfiguration secureValueRequestConfig, CancellationToken cancellationToken)
        {
            var currentActivity     = CrossFingerprint.CurrentActivity;
            var _fingerprintManager = FingerprintManagerCompat.From(currentActivity);

            var taskCompletionSource = new TaskCompletionSource <AuthenticationCallbackResult>();

            byte[] iv;
            byte[] value;
            try
            {
                var prefs = Application.Context.GetSharedPreferences(prefsName, FileCreationMode.Private);
                iv    = Convert.FromBase64String(prefs.GetString($"{secureValueRequestConfig.Key}:iv", null));
                value = Convert.FromBase64String(prefs.GetString($"{secureValueRequestConfig.Key}:value", null));
            }
            catch (Exception ex)
            {
                return(new GetSecureValueResult
                {
                    Status = FingerprintAuthenticationResultStatus.UnknownError,
                    ErrorMessage = $"No values for {secureValueRequestConfig.Key}"
                });
            }

            try
            {
                _fingerprintManager.Authenticate(CryptoObjectHelper.Instance.BuildCryptoObject(CipherMode.DecryptMode, iv),
                                                 (int)FingerprintAuthenticationFlags.None,
                                                 new CancellationSignal(),
                                                 new AuthenticationCallback(value, taskCompletionSource),
                                                 null);

                var fragment = CrossFingerprint.CreateSecureValueDialogFragment();
                var result   = await fragment.ShowAsync(secureValueRequestConfig, taskCompletionSource, cancellationToken);

                if (result.Status == FingerprintAuthenticationResultStatus.Succeeded)
                {
                    return(new GetSecureValueResult
                    {
                        Status = result.Status,
                        Value = System.Text.Encoding.UTF8.GetString(result.Result),
                    });
                }

                return(new GetSecureValueResult
                {
                    Status = result.Status,
                    // Pass through error info?
                });
            }
            catch (Exception ex)
            {
                return(new GetSecureValueResult
                {
                    Status = FingerprintAuthenticationResultStatus.UnknownError,
                    ErrorMessage = ex.Message
                });
            }
        }
 public static FingerprintManagerApiDialogFragment NewInstance(FingerprintManagerCompat fingerprintManager)
 {
     FingerprintManagerApiDialogFragment frag = new FingerprintManagerApiDialogFragment
                                                {
                                                    _fingerprintManager = fingerprintManager
                                                };
     return frag;
 }
예제 #14
0
 public override void OnCreate(Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     _fingerprintManager = FingerprintManagerCompat.From(Context);
     RetainInstance      = true;
     CryptObjectHelper   = new CryptoObjectHelper();
     SetStyle(DialogFragmentStyle.Normal, Res.Style.ThemeMaterialLightDialog);
 }
        public static FingerprintManagerApiDialogFragment NewInstance(FingerprintManagerCompat fingerprintManager)
        {
            FingerprintManagerApiDialogFragment frag = new FingerprintManagerApiDialogFragment
            {
                _fingerprintManager = fingerprintManager
            };

            return(frag);
        }
 internal FingerprintManagerFragment(string alertTitle, string alertMessage, TaskCompletionSource <AuthenticationResult> tcs)
 {
     _fingerprintManager = FingerprintManagerCompat.From(MainApplication.CurrentActivity);
     _alertTitle         = alertTitle;
     _alertMessage       = alertMessage;
     _cryptObjectHelper  = new CryptoObjectHelper();
     _cancellationSignal = new CancellationSignal();
     _tcsWeak            = new WeakReference <TaskCompletionSource <AuthenticationResult> >(tcs);
 }
예제 #17
0
 public void InitReader()
 {
     m_fingerprintManager = FingerprintManagerCompat.From(Application.Context);
     //make sure hardware is available
     if (!m_fingerprintManager.IsHardwareDetected)
     {
         return;
     }
     m_ready = true;
 }
예제 #18
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.fragment_settings, container, false);

            spinner = (Spinner)v.FindViewById(Resource.Id.alarmSpinner);
            SetupSpinner(v);
            enablefingerprint = v.FindViewById <Switch>(Resource.Id.fingerPrintSwitch);
            enablePin         = v.FindViewById <Switch>(Resource.Id.pin_switch);
            _version          = v.FindViewById <TextView>(Resource.Id.tv_version);
            string ver = Context.PackageManager.GetPackageInfo(Context.PackageName, 0).VersionName;

            _version.Text               = "Versiunea " + ver;
            _tvDevicesManagement        = v.FindViewById <TextView>(Resource.Id.devices);
            _rlMedicineTitle            = v.FindViewById <RelativeLayout>(Resource.Id.medicine_relative);
            _tvDeviceTitle              = v.FindViewById <TextView>(Resource.Id.tv_devices);
            _tvMedicineTitle            = v.FindViewById <TextView>(Resource.Id.tv_medicine);
            _tvDevicesManagement.Click += (sender, args) =>
                                          Activity.StartActivity(typeof(DevicesManagementActivity));
            FingerprintManagerCompat checkHardware;

            checkHardware = FingerprintManagerCompat.From(Activity);


            var fingerprint = Convert.ToBoolean(Utils.GetDefaults("fingerprint"));

            if (!checkHardware.IsHardwareDetected)
            {
                enablefingerprint.Enabled = false;
            }

            enablefingerprint.Checked        = fingerprint;
            enablePin.Checked                = !string.IsNullOrEmpty(Utils.GetDefaults("UserPin"));
            enablefingerprint.CheckedChange += Enablefingerprint_CheckedChange;
            enablePin.CheckedChange         += EnablePin_CheckedChange;
            if (int.Parse(Utils.GetDefaults("UserType")) == 2)
            {
                _tvDevicesManagement.Visibility = ViewStates.Visible;
                _tvDeviceTitle.Visibility       = ViewStates.Visible;
            }
            if (int.Parse(Utils.GetDefaults("UserType")) == 1)
            {
                _tvDevicesManagement.Visibility = ViewStates.Gone;
                _tvDeviceTitle.Visibility       = ViewStates.Gone;
            }
            if (int.Parse(Utils.GetDefaults("UserType")) == 2)
            {
                spinner.Visibility          = ViewStates.Gone;
                _rlMedicineTitle.Visibility = ViewStates.Gone;
                _tvMedicineTitle.Visibility = ViewStates.Gone;
            }

            SetViewSettingsForTrackerActivity(v);

            return(v);
        }
        /// <summary>
        /// Inizializza lo scanner per l'impronta digitale
        /// </summary>
        public void Init()
        {
            try
            {
                FingerprintManagerCompat fingerprintManagerCmp = FingerprintManagerCompat.From(CurrentContext);
                if (!fingerprintManagerCmp.IsHardwareDetected)
                {
                    throw new Exception(Resources.GetString(Resource.String.errFpHWNotDetected));
                }

                // Il dispositivo deve essere protetto da blocca schermo, altrimenti non si può usare
                // l'impronta digitale
                KeyguardManager keyguardManager = (KeyguardManager)CurrentContext.GetSystemService(Context.KeyguardService);
                if (!keyguardManager.IsKeyguardSecure)
                {
                    throw new Exception(Resources.GetString(Resource.String.errFpLockScreen));
                }

                // Verifica la presenza della registrazione di almeno una impronta digitale
                if (!HasEnrolledFingerprints(fingerprintManagerCmp))
                {
                    throw new Exception(Resources.GetString(Resource.String.errFpNotFound));
                }

                // Verifica delle autorizzazioni da Android 6 in poi
                if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
                {
                    Android.Content.PM.Permission permissionResult = ContextCompat.CheckSelfPermission(CurrentContext, USE_FINFERPRINT_PERMISSION);
                    if (permissionResult == Android.Content.PM.Permission.Granted)
                    {
                        FingerprintManager = fingerprintManagerCmp;
                    }
                    else
                    {
                        // No permission. Go and ask for permissions and don't start the scanner. See
                        // https://developer.android.com/training/permissions/requesting.html
                        MainActivity.Instance.RequestPermissions(new[] { USE_FINFERPRINT_PERMISSION }, 0);
                        // Verifico di nuovo i permessi
                        permissionResult = ContextCompat.CheckSelfPermission(CurrentContext, USE_FINFERPRINT_PERMISSION);
                        if (permissionResult != Android.Content.PM.Permission.Granted)
                        {
                            throw new Exception(Resources.GetString(Resource.String.errFpPermissionDenied));
                        }
                    }
                }
            }
            catch (Exception)
            {
                FingerprintManager = null;
                throw;
            }
        }
        public bool IsHardwareDetected()
        {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(Android.App.Application.Context);

            if (!fingerprintManager.IsHardwareDetected)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        public bool IsFingerPrintEnrolled()
        {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(Android.App.Application.Context);

            if (!fingerprintManager.HasEnrolledFingerprints)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Xamarin.Android.Fingerprint.FingerprintAuthenticator"/> class.
        /// </summary>
        /// <param name="context">Context.</param>
        /// <param name="callbacks">Callbacks.</param>
        public FingerprintAuthenticator(Context context, IFingerprintAuthenticatorCallbacks callbacks)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (callbacks == null)
            {
                throw new ArgumentNullException(nameof(callbacks));
            }

            _authenticationCallback = callbacks;
            _fingerprintManager     = FingerprintManagerCompat.From(context);
        }
예제 #23
0
        /// <summary>
        /// Initialize fingerprint authentication mechanism
        /// </summary>
        /// <param name="activity">Root activity</param>
        public static void FingerprintAuthenticate(Activity activity)
        {
            FingerprintManagerCompat fingerprint = FingerprintManagerCompat.From(activity);
            KeyguardManager          keyGuard    = activity.GetSystemService(Context.KeyguardService) as KeyguardManager;

            Android.Content.PM.Permission permission = activity.CheckSelfPermission(Android.Manifest.Permission.UseFingerprint);
            if (fingerprint.IsHardwareDetected &&
                keyGuard.IsKeyguardSecure &&
                fingerprint.HasEnrolledFingerprints &&
                permission == Android.Content.PM.Permission.Granted)
            {
                const int           flags        = 0;
                CryptoObjectFactory cryptoHelper = new CryptoObjectFactory();
                FingerprintManagerCompat.AuthenticationCallback authCallback = new AuthCallback(activity as Activities.LoginActivity);
                fingerprint.Authenticate(cryptoHelper.BuildCryptoObject(), flags, new Android.Support.V4.OS.CancellationSignal(), authCallback, null);
            }
        }
예제 #24
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_fingerprintmanager_api);

            InitializeViewReferences();

            _fingerprintManager = FingerprintManagerCompat.From(this);
            string canScanMsg = CheckFingerprintEligibility();

            _startAuthenticationScanButton.Click += StartFingerprintScan;
            _scanAgainButton.Click       += ScanAgainButtonOnClick;
            _failedScanAgainButton.Click += RecheckEligibility;

            if (_canScan)
            {
                _dialogFrag = FingerprintManagerApiDialogFragment.NewInstance(_fingerprintManager);
            }
            else
            {
                Toast.MakeText(this, "No se puede utilizar escaneo de huella dactilar en el dispositivo. " + canScanMsg, ToastLength.Long).Show();
                OnBackPressed();
                return;
            }
            Permission permissionResult = ContextCompat.CheckSelfPermission(this,
                                                                            Manifest.Permission.UseFingerprint);

            if (permissionResult == Permission.Granted)
            {
                _initialPanel.Visibility        = ViewStates.Gone;
                _authenticatedPanel.Visibility  = ViewStates.Gone;
                _errorPanel.Visibility          = ViewStates.Gone;
                _scanInProgressPanel.Visibility = ViewStates.Visible;
                _dialogFrag.Init();
                _dialogFrag.Show(FragmentManager, DIALOG_FRAGMENT_TAG);
            }
            else
            {
                Snackbar.Make(FindViewById(Res.Id.Content),
                              Resource.String.missing_fingerprint_permissions,
                              Snackbar.LengthLong)
                .Show();
            }
        }
예제 #25
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            fingerprintManager = FingerprintManagerCompat.From(this);
            cancellation       = new Android.Support.V4.OS.CancellationSignal();
            preferences        = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            emailEditText    = FindViewById <EditText>(Resource.Id.emailEditText);
            passwordEditText = FindViewById <EditText>(Resource.Id.passwordEditText);
            signinButton     = FindViewById <Button>(Resource.Id.signinButton);
            registerButton   = FindViewById <Button>(Resource.Id.registerButton);

            signinButton.Click   += SigninButton_Click;
            registerButton.Click += RegisterButton_Click;
        }
예제 #26
0
        public bool IsSupported()
        {
            var context = Android.App.Application.Context;

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M)
            {
                /* ==================================================================================================
                 * android api 23 or higher
                 * ================================================================================================*/
                var manager = context.GetSystemService(Context.FingerprintService) as FingerprintManager;
                var rs      = manager.IsHardwareDetected;
                return(rs);
            }

            // Using the Android Support Library v4
            var managerCompat = FingerprintManagerCompat.From(context);
            var rs2           = managerCompat.IsHardwareDetected;

            return(rs2);
        }
예제 #27
0
        public Task <bool> Scan()
        {
            tcs = new TaskCompletionSource <bool>();
            var Context = Android.App.Application.Context;
            // Using the Android Support Library v4
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(Context);


            if (!fingerprintManager.IsHardwareDetected)
            {
                Toast.MakeText(Context, "FingerPrint authentication permission not enable", ToastLength.Short).Show();
                tcs.SetResult(false);
                return(tcs.Task);
            }

            if (!fingerprintManager.HasEnrolledFingerprints)
            {
                Toast.MakeText(Context, "Register at least one fingerprint in Settings", ToastLength.Short).Show();
            }
            else
            {
                const int flags = 0; /* always zero (0) */

                // CryptoObjectHelper is described in the previous section.
                CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();

                // cancellationSignal can be used to manually stop the fingerprint scanner.
                var cancellationSignal = new Android.Support.V4.OS.CancellationSignal();


                // AuthenticationCallback is a base class that will be covered later on in this guide.
                //FingerprintManagerCompat.AuthenticationCallback authenticationCallback = new MyAuthCallbackSample(this);

                // Start the fingerprint scanner.
                fingerprintManager.Authenticate(cryptoHelper.BuildCryptoObject(), flags, cancellationSignal, this, null);

                Toast.MakeText(Context, "Put your finger to scan", ToastLength.Short).Show();
            }

            return(tcs.Task);
        }
예제 #28
0
        public void fingerPrintDetection(Activity context)
        {
            // Using the Android Support Library v4
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(context);

            if (fingerprintManager.IsHardwareDetected)
            {
                if (fingerprintManager.HasEnrolledFingerprints)
                {
                    // The context is typically a reference to the current activity.
                    Android.Content.PM.Permission permissionResult = ContextCompat.CheckSelfPermission(context, Manifest.Permission.UseFingerprint);
                    if (permissionResult == Android.Content.PM.Permission.Granted)
                    {
                        // Permission granted - go ahead and start the fingerprint scanner.
                        CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();
                        var cancellationSignal          = new Android.Support.V4.OS.CancellationSignal();

                        // AuthCallbacks is a C# class defined elsewhere in code.
                        FingerprintManagerCompat.AuthenticationCallback authenticationCallback = new SimpleAuthCallbacks(context);

                        // Here is where the CryptoObjectHelper builds the CryptoObject.
                        fingerprintManager.Authenticate(cryptoHelper.BuildCryptoObject(), (int)FingerprintAuthenticationFlags.None, cancellationSignal, authenticationCallback, null);
                    }
                    else
                    {
                        // No permission. Go and ask for permissions and don't start the scanner. See
                        // http://developer.android.com/training/permissions/requesting.html
                    }
                }
                else
                {
                    //user has not enrolled for fingerprint
                }
            }
            else
            {
                //Device is not compatible for fingerprint scanning
            }
        }
예제 #29
0
        public void CheckFingerPrint()
        {
            try
            {
                FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(this);
                KeyguardManager          keyguardManager    = GetSystemService(KeyguardService) as KeyguardManager;
                App.AndroidFingerPrintSupported = fingerprintManager.IsHardwareDetected && keyguardManager.IsKeyguardSecure && fingerprintManager.HasEnrolledFingerprints;
                CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);//Register FingerScan Nuget
            }
            catch (Exception e)
            {
            }


            //if (!keyguardManager.IsKeyguardSecure)
            //{
            //}
            //if (!fingerprintManager.HasEnrolledFingerprints)
            //{
            //    // Can't use fingerprint authentication - notify the user that they need to
            //    // enroll at least one fingerprint with the device.
            //}
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_fingerprintmanager_api);

            InitializeViewReferences();

            _fingerprintManager = FingerprintManagerCompat.From(this);
            string canScanMsg = CheckFingerprintEligibility();

            _startAuthenticationScanButton.Click += StartFingerprintScan;
            _scanAgainButton.Click += ScanAgainButtonOnClick;
            _failedScanAgainButton.Click += RecheckEligibility;

            if (_canScan)
            {
                _dialogFrag = FingerprintManagerApiDialogFragment.NewInstance(_fingerprintManager);
            }
            else
            {
                ShowError("Can't use this device for the sample.", canScanMsg);
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "FingerprintAuthorization" layout resource
            SetContentView(Resource.Layout.FingerprintAuthorization);

            sharedPreferences        = PreferenceManager.GetDefaultSharedPreferences(this);
            fingerprintManagerCompat = FingerprintManagerCompat.From(this);
            cancelationSignal        = new Android.Support.V4.OS.CancellationSignal();

            fingerprintStatusTextView = FindViewById <TextView>(Resource.Id.tvFingerprintStatusTextView);
            buttonAuthenticate        = FindViewById <Button>(Resource.Id.buttonFingerPrintAuthenticate);
            buttonReset = FindViewById <Button>(Resource.Id.buttonFingerPrintReset);
            FindViewById <ProgressBar>(Resource.Id.pbFingerprintAuthenticationProgressBar).Visibility = ViewStates.Invisible;

            buttonAuthenticate.Click += (sender, e) => {
                // Implementation
                FindViewById <ProgressBar>(Resource.Id.pbFingerprintAuthenticationProgressBar).Visibility = ViewStates.Visible;

                if (CanUseFingerprintBiometric())
                {
                    LogUserIn();
                }
                else
                {
                    FindViewById <ProgressBar>(Resource.Id.pbFingerprintAuthenticationProgressBar).Visibility = ViewStates.Invisible;
                    Toast.MakeText(this, "This device is not configured for Fingerprint Biometrics", ToastLength.Long).Show();
                }
            };

            buttonReset.Click += (sender, e) => {
                // Implementation
                FindViewById <ProgressBar>(Resource.Id.pbFingerprintAuthenticationProgressBar).Visibility = ViewStates.Invisible;
                fingerprintStatusTextView.Text = "You Must Authenticate";
            };
        }
예제 #32
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Forms.Forms.Init(this, savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            SetContentView(Resource.Layout.activity_fingerprintmanager_api);
            InitializeViewReferences();

            _fingerprintManager = FingerprintManagerCompat.From(this);
            string canScanMsg = CheckFingerprintEligibility();

            _startAuthenticationScanButton.Click += StartFingerprintScan;
            _failedScanAgainButton.Click         += RecheckEligibility;

            if (_canScan)
            {
                _dialogFrag = FingerprintManagerApiDialogFragment.NewInstance();
            }
            else
            {
                ShowError("Can't use this device for the sample.", canScanMsg);
            }
        }
            public override void OnAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result)
            {
                Log.Debug(TAG, "OnAuthenticationSucceeded");
                if (result.CryptoObject.Cipher != null)
                {
                    try
                    {
                        // Calling DoFinal on the Cipher ensures that the encryption worked.
                        byte[] doFinalResult = result.CryptoObject.Cipher.DoFinal(SECRET_BYTES);
                        Log.Debug(TAG, "Fingerprint authentication succeeded, doFinal results: {0}",
                                  Convert.ToBase64String(doFinalResult));

                        ReportSuccess();
                    }
                    catch (BadPaddingException bpe)
                    {
                        Log.Error(TAG, "Failed to encrypt the data with the generated key." + bpe);
                        ReportAuthenticationFailed();
                    }
                    catch (IllegalBlockSizeException ibse)
                    {
                        Log.Error(TAG, "Failed to encrypt the data with the generated key." + ibse);
                        ReportAuthenticationFailed();
                    }
                }
                else
                {
                    // No cipher used, assume that everything went well and trust the results.
                    Log.Debug(TAG, "Fingerprint authentication succeeded.");
                    ReportSuccess();
                }
            }