diff --git a/app/src/main/java/com/beemdevelopment/aegis/Preferences.java b/app/src/main/java/com/beemdevelopment/aegis/Preferences.java index de37bb81..73f1e619 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/Preferences.java +++ b/app/src/main/java/com/beemdevelopment/aegis/Preferences.java @@ -159,4 +159,12 @@ public class Preferences { public void setBackupsVersionCount(int versions) { _prefs.edit().putInt("pref_backups_versions", versions).apply(); } + + public boolean isTimeSyncWarningEnabled() { + return _prefs.getBoolean("pref_warn_time_sync", true); + } + + public void setIsTimeSyncWarningEnabled(boolean enabled) { + _prefs.edit().putBoolean("pref_warn_time_sync", enabled).apply(); + } } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/Dialogs.java b/app/src/main/java/com/beemdevelopment/aegis/ui/Dialogs.java index d9998840..16978e85 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/Dialogs.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/Dialogs.java @@ -6,6 +6,8 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; +import android.provider.Settings; import android.text.Editable; import android.text.InputType; import android.text.TextWatcher; @@ -293,6 +295,31 @@ public class Dialogs { Dialogs.showSecureDialog(dialog); } + public static void showTimeSyncWarningDialog(Context context, Dialog.OnClickListener listener) { + Preferences prefs = new Preferences(context); + View view = LayoutInflater.from(context).inflate(R.layout.dialog_time_sync, null); + CheckBox checkBox = view.findViewById(R.id.check_warning_disable); + + showSecureDialog(new AlertDialog.Builder(context) + .setTitle(R.string.time_sync_warning_title) + .setView(view) + .setCancelable(false) + .setPositiveButton(R.string.yes, (dialog, which) -> { + if (checkBox.isChecked()) { + prefs.setIsTimeSyncWarningEnabled(false); + } + if (listener != null) { + listener.onClick(dialog, which); + } + }) + .setNegativeButton(R.string.no, (dialog, which) -> { + if (checkBox.isChecked()) { + prefs.setIsTimeSyncWarningEnabled(false); + } + }) + .create()); + } + public interface NumberInputListener { void onNumberInputResult(int number); } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java index 2c4f14eb..8b70f4b9 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java @@ -10,6 +10,7 @@ import android.graphics.BitmapFactory; import android.graphics.Rect; import android.net.Uri; import android.os.Bundle; +import android.provider.Settings; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -343,11 +344,23 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene private void onDoIntroResult() { _vault = _app.getVaultManager(); loadEntries(); + checkTimeSyncSetting(); + } + + private void checkTimeSyncSetting() { + boolean autoTime = Settings.Global.getInt(getContentResolver(), Settings.Global.AUTO_TIME, 1) == 1; + if (!autoTime && getPreferences().isTimeSyncWarningEnabled()) { + Dialogs.showTimeSyncWarningDialog(this, (dialog, which) -> { + Intent intent = new Intent(Settings.ACTION_DATE_SETTINGS); + startActivity(intent); + }); + } } private void onDecryptResult() { _vault = _app.getVaultManager(); loadEntries(); + checkTimeSyncSetting(); } private void startScanActivity() { @@ -450,6 +463,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene _entryListView.refresh(false); } else { loadEntries(); + checkTimeSyncSetting(); } handleDeeplink(); diff --git a/app/src/main/res/layout/dialog_time_sync.xml b/app/src/main/res/layout/dialog_time_sync.xml new file mode 100644 index 00000000..49f42838 --- /dev/null +++ b/app/src/main/res/layout/dialog_time_sync.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7e9207e0..047eaaa4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -231,6 +231,9 @@ Support us by leaving a review in the Google Play Store This device doesn\'t support web view, which is necessary to view the changelog. It is missing a system component. Email + Automatic time synchronization + Aegis relies on the system time to be in sync to generate correct codes. A deviation of only a few seconds could result in incorrect codes. It looks like your device is not configured to automatically synchronize the time. Would you like to do so now? + Stop warning me. I know what I\'m doing. body {