Only update if user has enabled

This commit is contained in:
RichyHBM 2018-01-05 20:10:17 +00:00
parent 2bf20ce7f1
commit 984b180fba
5 changed files with 26 additions and 4 deletions

View file

@ -20,15 +20,23 @@ public class BackupAgent extends BackupAgentHelper {
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) throws IOException {
synchronized (DatabaseHelper.DatabaseFileLock) {
super.onBackup(oldState, data, newState);
Settings settings = new Settings(this);
if(settings.getAndroidBackupServiceEnabled()) {
synchronized (DatabaseHelper.DatabaseFileLock) {
super.onBackup(oldState, data, newState);
}
}
}
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException {
synchronized (DatabaseHelper.DatabaseFileLock) {
super.onRestore(data, appVersionCode, newState);
Settings settings = new Settings(this);
if(settings.getAndroidBackupServiceEnabled()) {
synchronized (DatabaseHelper.DatabaseFileLock) {
super.onRestore(data, appVersionCode, newState);
}
}
}

View file

@ -376,4 +376,8 @@ public class Settings {
public void setLastUsedDialogShown(boolean value) {
setBoolean(R.string.settings_key_last_used_dialog_shown, value);
}
public boolean getAndroidBackupServiceEnabled() {
return getBoolean(R.string.settings_key_enable_android_backup_service, false);
}
}

View file

@ -36,6 +36,7 @@
<string name="settings_key_tags_toggles" translatable="false">pref_tags_toggles</string>
<string name="settings_key_enable_screenshot" translatable="false">pref_enable_screenshot</string>
<string name="settings_key_enable_android_backup_service" translatable="false">pref_enable_android_backup_service</string>
<string name="settings_key_last_used_dialog_shown" translatable="false">pref_last_used_dialog_shown</string>

View file

@ -32,6 +32,7 @@
<string name="settings_title_special_features">Enable special features</string>
<string name="settings_title_enable_screenshot">Enable screenshots</string>
<string name="settings_title_enable_android_backup_service">Enable android backup</string>
<!-- Descriptions -->
<string name="settings_desc_tap_to_reveal">Hide the OTP tokens by default, requiring them to be
@ -56,6 +57,8 @@
<string name="settings_desc_enable_screenshot">Allow to take screenshots of the main screen
(disabled by default for security reasons)</string>
<string name="settings_desc_enable_android_backup_service">Enables andOTP to use android\'s
built in backup service to bacup keys and preferences</string>
<string name="settings_desc_special_features">Uncheck to disable the special features again</string>
<!-- Toasts -->

View file

@ -17,6 +17,12 @@
android:summary="@string/settings_desc_enable_screenshot"
android:defaultValue="false" />
<CheckBoxPreference
android:key="@string/settings_key_enable_android_backup_service"
android:title="@string/settings_title_enable_android_backup_service"
android:summary="@string/settings_desc_enable_android_backup_service"
android:defaultValue="false" />
</PreferenceCategory>
</PreferenceScreen>