Skip to content

Commit

Permalink
show warning if auto time is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-mh committed Sep 11, 2023
1 parent 6017883 commit 8b3f195
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions AuthenticatorPro.Droid/Resources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@
<string name="genericError">An error occurred</string>
<string name="databaseError">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.</string>
<string name="viewErrorLog">View error log</string>
<string name="autoTimeWarningTitle">Time sync disabled</string>
<string name="autoTimeWarningMessage">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.</string>

<!-- Error reporting -->
<string name="unhandledErrorMessage">An unhandled error occurred within the application. Details of the error are below:</string>
Expand Down
42 changes: 41 additions & 1 deletion AuthenticatorPro.Droid/src/Activity/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1538,6 +1544,7 @@ private async Task FinaliseRestore(RestoreResult result)
await _customIconView.LoadFromPersistenceAsync();

await SwitchCategory(null);
ShowAutoTimeWarning();

RunOnUiThread(delegate
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
}
}
9 changes: 9 additions & 0 deletions AuthenticatorPro.Droid/src/PreferenceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 8b3f195

Please sign in to comment.