예제 #1
0
        public void GetFingerprint(EventHandler evt, bool encrypt, byte[] data)
        {
            //make sure the device is secured
            KeyguardManager keyguardManager = (KeyguardManager)Application.Context.GetSystemService(Context.KeyguardService);

            if (!keyguardManager.IsKeyguardSecure)
            {
                return;
            }
            //make sure fingerprints are enrolled
            if (!m_fingerprintManager.HasEnrolledFingerprints)
            {
                return;
            }
            //check permissions
            Android.Content.PM.Permission permissionResult = ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.UseFingerprint);
            if (permissionResult != Android.Content.PM.Permission.Granted)
            {
                return;
            }

            m_evt  = evt;
            m_data = data;
            m_mode = encrypt ? CipherMode.EncryptMode : CipherMode.DecryptMode;

            CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();

            cancellationSignal = new Android.Support.V4.OS.CancellationSignal();

            //prompt user to scan their fingerprint
            m_fingerprintManager.Authenticate(cryptoHelper.BuildCryptoObject(m_mode), 0, cancellationSignal, this, null);
        }
예제 #2
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 bool IsPermissionGranted()
 {
     Android.Content.PM.Permission permissionResult = ContextCompat.CheckSelfPermission(Android.App.Application.Context, Manifest.Permission.UseFingerprint);
     if (permissionResult == Android.Content.PM.Permission.Granted)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #4
0
        private void OnClickFaceAuthWithCrpObj(object sender, EventArgs e)
        {
            string Tag = "FaceAuthWithCrpObj";

            Android.Content.PM.Permission permissionCheck = Android.Content.PM.Permission.Granted;
            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                permissionCheck = CheckSelfPermission(Manifest.Permission.Camera);
            }
            if (permissionCheck != Android.Content.PM.Permission.Granted)
            {
                log.Info(Tag, "The camera permission is not enabled. Please enable it.");

                // request camera permissions
                if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
                {
                    RequestPermissions(new string[] { Manifest.Permission.Camera }, 1);
                }
                return;
            }
            BioAuthnCallback callback = new FidoBioAuthnCallback();
            // Cancellation Signal
            CancellationSignal cancellationSignal = new CancellationSignal();

            FaceManager faceManager = new FaceManager(this);

            Log.Info("HasEnrolledTemplates", faceManager.HasEnrolledTemplates.ToString());
            Log.Info("IsHardwareDetected", faceManager.IsHardwareDetected.ToString());
            Log.Info("CanAuth", faceManager.CanAuth().ToString());

            log.Info(Tag, $"IsHardwareDetected:{faceManager.IsHardwareDetected}");

            // Checks whether 3D facial authentication can be used.
            int errorCode = faceManager.CanAuth();

            if (errorCode != 0)
            {
                log.Info(Tag, "Can not authenticate. errorCode=" + errorCode);
                return;
            }
            // flags
            int flags = 0;

            // Authentication messsage handler.
            Handler handler = null;

            // Recommended CryptoObject to be set to null. KeyStore is not associated with face authentication in current
            // version. KeyGenParameterSpec.Builder.SetUserAuthenticationRequired() must be set false in this scenario.
            CryptoObject crypto = null;

            log.Info(Tag, "Start face authentication.\nAuthenticating......\n");
            faceManager.Auth(crypto, cancellationSignal, flags, callback, handler);
        }
        /// <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 void ConfigurarNotificacion()
        {
            Android.Content.PM.Permission permiso_noty = contextApp.CheckSelfPermission(Manifest.Permission.BindNotificationListenerService);
            //permiso_noty == Permission.Denied ||

            NotificationManagerCompat manager = NotificationManagerCompat.From(contextApp);
            var IsAllowed = manager.AreNotificationsEnabled();



            if (IsAllowed)
            {
                Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
                contextApp.StartActivity(intent);
            }
        }
예제 #7
0
        /// <summary>
        /// 判断用户是否有权限
        /// </summary>
        /// <param name="permissionName"></param>
        /// <returns></returns>
        public bool CheckPermission(string permissionName)
        {
            if (Xamarin.Essentials.DeviceInfo.Version.Major < 6)
            {
#if DEBUG
                string msg = $"当前系统为 Android{Xamarin.Essentials.DeviceInfo.Version.Major}";
                System.Diagnostics.Debug.WriteLine(msg);

                System.Diagnostics.Debugger.Break();
#endif
                return(true);
            }

            Android.Content.PM.Permission permission = mAppActivity.CheckSelfPermission(permissionName);
            return(permission == Android.Content.PM.Permission.Granted ? true : false);
        }
예제 #8
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);
            }
        }
예제 #9
0
        private async Task <bool> CheckPermissionIfNeeded()
        {
            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.
                return(true);
            }
            else
            {
                await Task.Delay(3000);//Simulate

                return(true);
                // No permission. Go and ask for permissions and don't start the scanner. See
                // http://developer.android.com/training/permissions/requesting.html
            }
        }
        private void Authenticate()
        {
            FingerprintManager fingerprint = this.GetSystemService(FingerprintService) as FingerprintManager;
            KeyguardManager    keyGuard    = GetSystemService(KeyguardService) as KeyguardManager;

            Android.Content.PM.Permission permission = CheckSelfPermission(Android.Manifest.Permission.UseFingerprint);
            if (fingerprint.IsHardwareDetected &&
                keyGuard.IsKeyguardSecure &&
                fingerprint.HasEnrolledFingerprints &&
                permission == Android.Content.PM.Permission.Granted)
            {
                const int           flags              = 0;
                CryptoObjectFactory cryptoObject       = new CryptoObjectFactory();
                CancellationSignal  cancellationSignal = new CancellationSignal();
                FingerprintManager.AuthenticationCallback authCallback = new AuthCallback(this);
                fingerprint.Authenticate(cryptoObject.BuildCryptoObject(), cancellationSignal, flags, authCallback, null);
            }
        }
예제 #11
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
            }
        }
예제 #12
0
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
            PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
            Android.Content.PM.Permission test = Android.Content.PM.Permission.Granted;
            if (grantResults[0] == test && grantResults[0] == test)
            {
                ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
                if (!prefs.GetBoolean("Install", false))
                {
                    BDD.CreateBDD();
                }

                Intent intent = new Intent(this, typeof(SynchroLogic));
                StartActivity(intent);
            }
            else
            {
                Intent intent = new Intent(this, typeof(NoData));
                Toast.MakeText(this, "Authorizations are necessary for the application.Please go to settings to enable it.", ToastLength.Long).Show();
                StartActivity(intent);
            }
        }
예제 #13
0
        public async void BntFPButtonClicked(object sender, EventArgs e)
        {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(Android.App.Application.Context);


            if (!fingerprintManager.IsHardwareDetected)
            {
            }

            KeyguardManager keyguardManager = (KeyguardManager)Android.App.Application.Context.GetSystemService(Context.KeyguardService);

            {
                if (!keyguardManager.IsKeyguardSecure)
                {
                }
            }


            if (!fingerprintManager.HasEnrolledFingerprints)
            {
            }
            // The context is typically a reference to the current activity.
            Android.Content.PM.Permission permissionResult = ContextCompat.CheckSelfPermission(Android.App.Application.Context, Manifest.Permission.UseFingerprint);
            if (permissionResult == Android.Content.PM.Permission.Granted)
            {
                bool isFingerprintAvailable = await CrossFingerprint.Current.IsAvailableAsync(false);

                if (!isFingerprintAvailable)
                {
                    await DisplayAlert("Error",
                                       "Biometric authentication is not available or is not configured.", "OK");

                    return;
                }

                AuthenticationRequestConfiguration conf =
                    new AuthenticationRequestConfiguration("Authentication",
                                                           "Authenticate access to your personal data");

                var authResult = await CrossFingerprint.Current.AuthenticateAsync(conf);

                if (authResult.Authenticated)
                {
                    //Success
                    await DisplayAlert("Success", "Authentication succeeded", "OK");

                    using (HttpClient client = new HttpClient())
                    {
                        StringContent       content         = new StringContent(JsonConvert.SerializeObject(Register), Encoding.UTF8, "application/json");
                        HttpResponseMessage responseMessage = await client.PutAsync(UrlBase + "PresenceAPI", content);

                        if (responseMessage.StatusCode == System.Net.HttpStatusCode.OK)
                        {
                            string responseContent = await responseMessage.Content.ReadAsStringAsync();
                            await DisplayAlert("Success", responseContent, "OK");
                        }
                    }
                }
            }

            else
            {
                // No permission. Go and ask for permissions and don't start the scanner. See
            }
        }
예제 #14
0
        private void initRecorder(int width, int height)
        {
            mMediaRecorder = new Android.Media.MediaRecorder();

            // 遇到的坑 -- 用户权限没有赋予 Mic 会报错 "setAudioSource failed.", 故此处进行判断是否含有麦克风权限
            if (Xamarin.Essentials.DeviceInfo.Version.Major >= 6)
            {
                Android.Content.PM.Permission permission = mAppActivity.CheckSelfPermission(Android.Manifest.Permission.RecordAudio);
                if (permission == Android.Content.PM.Permission.Granted)
                {
                    // mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                    mMediaRecorder.SetAudioSource(Android.Media.AudioSource.Mic);
                }
            }

            // mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
            mMediaRecorder.SetVideoSource(Android.Media.VideoSource.Surface);

            // mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            mMediaRecorder.SetOutputFormat(Android.Media.OutputFormat.ThreeGpp);

            // mediaRecorder.setOutputFile(getsaveDirectory() + System.currentTimeMillis() + ".mp4");
            // 遇到的坑 -- 目录没有创建会报出 Java.IO.FileNotFoundException, 要先判断 Dir 是否存在, 不存在则进行创建
            var mp4FileInfo = MyAndroidScreenRecord.GetScreenVideoFileInfo(mImageFileDateTime, mDirName);

            if (mp4FileInfo.Directory.Exists == false)
            {
                mp4FileInfo.Directory.Create();
            }

            mMediaRecorder.SetOutputFile(mp4FileInfo.FullName);

            // mediaRecorder.setVideoSize(width, height);
            mMediaRecorder.SetVideoSize(width, height);

            // mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
            mMediaRecorder.SetVideoEncoder(Android.Media.VideoEncoder.H264);

            // 遇到的坑 -- 用户权限没有赋予 Mic 会报错 "setAudioSource failed.", 故此处进行判断是否含有麦克风权限
            if (Xamarin.Essentials.DeviceInfo.Version.Major >= 6)
            {
                Android.Content.PM.Permission permission = mAppActivity.CheckSelfPermission(Android.Manifest.Permission.RecordAudio);
                if (permission == Android.Content.PM.Permission.Granted)
                {
                    // mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                    mMediaRecorder.SetAudioEncoder(Android.Media.AudioEncoder.AmrNb);
                }
            }

            // mediaRecorder.setVideoEncodingBitRate(5 * 1024 * 1024);
            mMediaRecorder.SetVideoEncodingBitRate(5 * 1024 * 1024);

            // mediaRecorder.setVideoFrameRate(30);
            mMediaRecorder.SetVideoFrameRate(mDpi);

            try
            {
                mMediaRecorder.Prepare();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("MyAndroidScreenRecord - initRecorder 捕获到错误");
                System.Diagnostics.Debug.WriteLine(ex.GetFullInfo());
                System.Diagnostics.Debugger.Break();

                throw ex;
            }
        }