private void StoreUnlockMode() { ISharedPreferencesEditor edit = PreferenceManager.GetDefaultSharedPreferences(this).Edit(); if (_unlockMode == FingerprintUnlockMode.Disabled) { edit.PutString(CurrentPreferenceKey, ""); } else { try { if (_unlockMode == FingerprintUnlockMode.FullUnlock) { var userKey = App.Kp2a.CurrentDb.KpDatabase.MasterKey.GetUserKey <KcpPassword>(); _enc.StoreEncrypted(userKey != null ? userKey.Password.ReadString() : "", CurrentPreferenceKey, edit); } else { _enc.StoreEncrypted("QuickUnlock" /*some dummy data*/, CurrentPreferenceKey, edit); } } catch (Exception e) { new AlertDialog.Builder(this) .SetTitle(GetString(Resource.String.ErrorOcurred)) .SetMessage(GetString(Resource.String.FingerprintSetupFailed)) .SetCancelable(false) .SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { }) .Show(); } } edit.PutString(App.Kp2a.CurrentDb.CurrentFingerprintModePrefKey, _unlockMode.ToString()); edit.Commit(); }
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; } }
private void StoreUnlockMode() { ISharedPreferencesEditor edit = PreferenceManager.GetDefaultSharedPreferences(this).Edit(); if (_unlockMode == FingerprintUnlockMode.Disabled) { edit.PutString(CurrentPreferenceKey, ""); } else { if (_unlockMode == FingerprintUnlockMode.FullUnlock) { _enc.StoreEncrypted(App.Kp2a.GetDb().KpDatabase.MasterKey.GetUserKey <KcpPassword>().Password.ReadString(), CurrentPreferenceKey, edit); } else { _enc.StoreEncrypted("QuickUnlock" /*some dummy data*/, CurrentPreferenceKey, edit); } } edit.PutString(App.Kp2a.GetDb().CurrentFingerprintModePrefKey, _unlockMode.ToString()); edit.Commit(); }