From 8b3f19589460c25d7fb4d28aa5bdf217b0653055 Mon Sep 17 00:00:00 2001 From: Jamie Hodgson Date: Mon, 11 Sep 2023 14:42:53 +0200 Subject: [PATCH] show warning if auto time is disabled --- .../Resources/values/strings.xml | 2 + .../src/Activity/MainActivity.cs | 42 ++++++++++++++++++- .../src/PreferenceWrapper.cs | 9 ++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/AuthenticatorPro.Droid/Resources/values/strings.xml b/AuthenticatorPro.Droid/Resources/values/strings.xml index 88e48da44e..f208f2b423 100644 --- a/AuthenticatorPro.Droid/Resources/values/strings.xml +++ b/AuthenticatorPro.Droid/Resources/values/strings.xml @@ -172,6 +172,8 @@ An error occurred An error occurred when opening the database. Try launching the app again. If the issue persists, clear app data and restore your latest backup.\n\nAlternatively, you can submit an error report. View error log + Time sync disabled + Your device has automatic time disabled. Two-factor authentication requires an accurate clock to generate codes.\n\nPlease enable automatic time sync in your device settings to ensure that the generated codes are always valid. An unhandled error occurred within the application. Details of the error are below: diff --git a/AuthenticatorPro.Droid/src/Activity/MainActivity.cs b/AuthenticatorPro.Droid/src/Activity/MainActivity.cs index f299d72f0b..e2a6278e68 100644 --- a/AuthenticatorPro.Droid/src/Activity/MainActivity.cs +++ b/AuthenticatorPro.Droid/src/Activity/MainActivity.cs @@ -14,6 +14,7 @@ using Android.Content.PM; using Android.Graphics; using Android.OS; +using Android.Provider; using Android.Runtime; using Android.Views; using Android.Views.Animations; @@ -27,6 +28,7 @@ using AuthenticatorPro.Core.Backup.Encryption; using AuthenticatorPro.Core.Converter; using AuthenticatorPro.Core.Entity; +using AuthenticatorPro.Core.Generator; using AuthenticatorPro.Core.Persistence.Exception; using AuthenticatorPro.Core.Service; using AuthenticatorPro.Droid.Callback; @@ -1100,7 +1102,6 @@ private void OnAddButtonClick(object sender, EventArgs e) fragment.EnterKeyClicked += OpenAddDialog; fragment.RestoreClicked += delegate { StartFilePickActivity("*/*", RequestRestore); }; - fragment.ImportClicked += delegate { OpenImportMenu(); }; fragment.Show(SupportFragmentManager, fragment.Tag); @@ -1206,6 +1207,11 @@ async Task Finalise() await _authenticatorView.LoadFromPersistenceAsync(); CheckEmptyState(); + if (result.Authenticator.Type.GetGenerationMethod() == GenerationMethod.Time) + { + ShowAutoTimeWarning(); + } + var position = _authenticatorView.IndexOf(result.Authenticator); RunOnUiThread(delegate @@ -1538,6 +1544,7 @@ private async Task FinaliseRestore(RestoreResult result) await _customIconView.LoadFromPersistenceAsync(); await SwitchCategory(null); + ShowAutoTimeWarning(); RunOnUiThread(delegate { @@ -1754,6 +1761,11 @@ private async void OnAddDialogSubmit(object sender, await _authenticatorView.LoadFromPersistenceAsync(); CheckEmptyState(); + if (args.Authenticator.Type.GetGenerationMethod() == GenerationMethod.Time) + { + ShowAutoTimeWarning(); + } + var position = _authenticatorView.IndexOf(args.Authenticator); RunOnUiThread(delegate @@ -1835,6 +1847,11 @@ private async void OnEditDialogSubmit(object sender, await _authenticatorView.LoadFromPersistenceAsync(); + if (args.Authenticator.Type.GetGenerationMethod() == GenerationMethod.Time) + { + ShowAutoTimeWarning(); + } + RunOnUiThread(delegate { _authenticatorListAdapter.NotifyItemChanged(position); }); Preferences.BackupRequired = BackupRequirement.Urgent; @@ -2049,5 +2066,28 @@ private async void OnCategoriesDialogCategoryClicked(object sender, } #endregion + + #region Misc + + private void ShowAutoTimeWarning() + { + var autoTimeEnabled = Settings.Global.GetInt(ContentResolver, Settings.Global.AutoTime) == 1; + + if (autoTimeEnabled || Preferences.ShownAutoTimeWarning) + { + return; + } + + new MaterialAlertDialogBuilder(this) + .SetTitle(Resource.String.autoTimeWarningTitle) + .SetMessage(Resource.String.autoTimeWarningMessage) + .SetIcon(Resource.Drawable.baseline_warning_24) + .SetPositiveButton(Resource.String.ok, delegate { }) + .Show(); + + Preferences.ShownAutoTimeWarning = true; + } + + #endregion } } \ No newline at end of file diff --git a/AuthenticatorPro.Droid/src/PreferenceWrapper.cs b/AuthenticatorPro.Droid/src/PreferenceWrapper.cs index d51f30ff58..124f7075fb 100644 --- a/AuthenticatorPro.Droid/src/PreferenceWrapper.cs +++ b/AuthenticatorPro.Droid/src/PreferenceWrapper.cs @@ -228,6 +228,15 @@ public bool FirstLaunch set => SetPreference(FirstLaunchKey, value); } + private const string ShownAutoTimeWarningKey = "shownAutoTimeWarning"; + private const bool ShownAutoTimeWarningDefault = false; + + public bool ShownAutoTimeWarning + { + get => Preferences.GetBoolean(ShownAutoTimeWarningKey, ShownAutoTimeWarningDefault); + set => SetPreference(ShownAutoTimeWarningKey, value); + } + private const string DefaultCategoryKey = "defaultCategory"; private const string DefaultCategoryDefault = null;