Пример #1
0
        private void ChangeUnlockMode(FingerprintUnlockMode oldMode, FingerprintUnlockMode newMode)
        {
            if (oldMode == newMode)
            {
                return;
            }


            if (_samsungBiometry != null)
            {
                _unlockMode = newMode;
                UpdateCloseDatabaseAfterFailedBiometricQuickUnlockVisibility();

                ISharedPreferencesEditor edit = PreferenceManager.GetDefaultSharedPreferences(this).Edit();
                edit.PutString(App.Kp2a.CurrentDb.CurrentFingerprintModePrefKey, _unlockMode.ToString());
                edit.Commit();
                return;
            }

            if (newMode == FingerprintUnlockMode.Disabled)
            {
                _unlockMode = newMode;
                UpdateCloseDatabaseAfterFailedBiometricQuickUnlockVisibility();

                StoreUnlockMode();
                return;
            }

            _desiredUnlockMode = newMode;
            FindViewById(Resource.Id.radio_buttons).Visibility = ViewStates.Gone;
            UpdateCloseDatabaseAfterFailedBiometricQuickUnlockVisibility();

            FindViewById(Resource.Id.fingerprint_auth_container).Visibility = ViewStates.Visible;
            try
            {
                _enc = new BiometricEncryption(new BiometricModule(this), CurrentPreferenceKey);
                if (!_enc.Init())
                {
                    throw new Exception("Failed to initialize cipher");
                }
                ResetErrorTextRunnable();

                _enc.StartListening(new BiometricAuthCallbackAdapter(this, this));
            }
            catch (Exception e)
            {
                CheckCurrentRadioButton();
                Toast.MakeText(this, e.ToString(), ToastLength.Long).Show();
                FindViewById(Resource.Id.radio_buttons).Visibility = ViewStates.Visible;
                FindViewById(Resource.Id.fingerprint_auth_container).Visibility = ViewStates.Gone;
            }
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            _activityDesign.ApplyTheme();
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.fingerprint_setup);

            Enum.TryParse(
                PreferenceManager.GetDefaultSharedPreferences(this).GetString(App.Kp2a.CurrentDb.CurrentFingerprintModePrefKey, ""),
                out _unlockMode);

            _fpIcon     = FindViewById <ImageView>(Resource.Id.fingerprint_icon);
            _fpTextView = FindViewById <TextView>(Resource.Id.fingerprint_status);


            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);

            int[] radioButtonIds =
            {
                Resource.Id.radio_fingerprint_quickunlock, Resource.Id.radio_fingerprint_unlock,
                Resource.Id.radio_fingerprint_disabled
            };
            _radioButtons        = radioButtonIds.Select(FindViewById <RadioButton>).ToArray();
            _radioButtons[0].Tag = FingerprintUnlockMode.QuickUnlock.ToString();
            _radioButtons[1].Tag = FingerprintUnlockMode.FullUnlock.ToString();
            _radioButtons[2].Tag = FingerprintUnlockMode.Disabled.ToString();
            foreach (RadioButton r in _radioButtons)
            {
                r.CheckedChange += (sender, args) =>
                {
                    var rbSender = ((RadioButton)sender);
                    if (!rbSender.Checked)
                    {
                        return;
                    }
                    foreach (RadioButton rOther in _radioButtons)
                    {
                        if (rOther == sender)
                        {
                            continue;
                        }
                        rOther.Checked = false;
                    }
                    FingerprintUnlockMode newMode;
                    Enum.TryParse(rbSender.Tag.ToString(), out newMode);
                    ChangeUnlockMode(_unlockMode, newMode);
                };
            }

            CheckCurrentRadioButton();

            int errorId = Resource.String.fingerprint_os_error;

            SetError(errorId);

            FindViewById(Resource.Id.cancel_button).Click += (sender, args) =>
            {
                _enc.StopListening();
                _unlockMode = FingerprintUnlockMode.Disabled;                 //cancelling a FingerprintEncryption means a new key has been created but not been authenticated to encrypt something. We can't keep the previous state.
                StoreUnlockMode();
                FindViewById(Resource.Id.radio_buttons).Visibility = ViewStates.Visible;
                FindViewById(Resource.Id.fingerprint_auth_container).Visibility = ViewStates.Gone;
                _enc = null;
                CheckCurrentRadioButton();
            };

            FindViewById(Resource.Id.radio_buttons).Visibility = ViewStates.Gone;
            FindViewById(Resource.Id.fingerprint_auth_container).Visibility = ViewStates.Gone;

            FindViewById <CheckBox>(Resource.Id.close_database_after_failed).Checked =
                Util.GetCloseDatabaseAfterFailedBiometricQuickUnlock(this);

            FindViewById <CheckBox>(Resource.Id.close_database_after_failed).CheckedChange += (sender, args) =>
            {
                PreferenceManager.GetDefaultSharedPreferences(this)
                .Edit()
                .PutBoolean(GetString(Resource.String.CloseDatabaseAfterFailedBiometricQuickUnlock_key), args.IsChecked)
                .Commit();
            };


            UpdateCloseDatabaseAfterFailedBiometricQuickUnlockVisibility();
        }