From 18fdbb96ce1d30c7d146853d70ad1fad6e50e88e Mon Sep 17 00:00:00 2001 From: RichyHBM Date: Mon, 10 Aug 2020 18:01:05 +0100 Subject: [PATCH 1/2] Add additional log lines to inform of the sync state --- .../flocke/andotp/Activities/SettingsActivity.java | 8 ++++++++ .../flocke/andotp/Utilities/BackupAgent.java | 12 ++++++++++++ app/src/main/res/values/strings_settings.xml | 3 +++ 3 files changed, 23 insertions(+) diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java index bb8e45e5..0f9f05d8 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java @@ -40,6 +40,7 @@ import android.preference.PreferenceManager; import androidx.appcompat.widget.Toolbar; import android.provider.DocumentsContract; +import android.util.Log; import android.view.ViewStub; import android.widget.Toast; @@ -166,6 +167,13 @@ public class SettingsActivity extends BaseActivity if (fragment.useAndroidSync != null) fragment.useAndroidSync.setEnabled(true); } + } else if(key.equals(getString(R.string.settings_key_enable_android_backup_service))) + { + Log.d(SettingsActivity.class.getSimpleName(), "onSharedPreferenceChanged called modifying settings_key_enable_android_backup_service service is now: " + + (settings.getAndroidBackupServiceEnabled() ? "enabled" : "disabled")); + + int message = settings.getAndroidBackupServiceEnabled() ? R.string.settings_toast_android_sync_enabled : R.string.settings_toast_android_sync_disabled; + Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); } fragment.updateAutoBackup(); diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/BackupAgent.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/BackupAgent.java index ead9e95f..9d154eb9 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/BackupAgent.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/BackupAgent.java @@ -29,6 +29,8 @@ import android.app.backup.BackupDataOutput; import android.app.backup.FileBackupHelper; import android.app.backup.SharedPreferencesBackupHelper; import android.os.ParcelFileDescriptor; +import android.util.Log; + import java.io.IOException; @@ -44,19 +46,29 @@ public class BackupAgent extends BackupAgentHelper { @Override public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) throws IOException { Settings settings = new Settings(this); + StringBuilder stringBuilder = new StringBuilder("onBackup called with the backup service set to "); + stringBuilder.append(settings.getAndroidBackupServiceEnabled() ? "enabled" : "disabled"); if(settings.getAndroidBackupServiceEnabled()) { synchronized (DatabaseHelper.DatabaseFileLock) { + stringBuilder.append(" calling parent onBackup"); super.onBackup(oldState, data, newState); } } + Log.d(BackupAgent.class.getSimpleName(), stringBuilder.toString()); } @Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { + Settings settings = new Settings(this); + StringBuilder stringBuilder = new StringBuilder("onRestore called with the backup service set to "); + stringBuilder.append(settings.getAndroidBackupServiceEnabled() ? "enabled" : "disabled"); + synchronized (DatabaseHelper.DatabaseFileLock) { + stringBuilder.append(" but restore happens regardless, calling parent onRestore"); super.onRestore(data, appVersionCode, newState); } + Log.d(BackupAgent.class.getSimpleName(), stringBuilder.toString()); } @Override diff --git a/app/src/main/res/values/strings_settings.xml b/app/src/main/res/values/strings_settings.xml index c2720231..cbfbd159 100644 --- a/app/src/main/res/values/strings_settings.xml +++ b/app/src/main/res/values/strings_settings.xml @@ -134,6 +134,9 @@ Failed to silently upgrade your password / PIN to the new encryption, please manually reset it in the Settings! + Android sync enabled + Android sync disabled + Warning Error Clear the KeyStore? From 5ae895132635a70cbc4a9518c48714d6f7916de6 Mon Sep 17 00:00:00 2001 From: RichyHBM Date: Tue, 11 Aug 2020 08:52:38 +0100 Subject: [PATCH 2/2] Add android sync toggle to initial flow --- .../Activities/IntroScreenActivity.java | 47 ++++++++++++++++++- .../layout/component_intro_android_sync.xml | 39 +++++++++++++++ app/src/main/res/values/strings_intro.xml | 1 + 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/layout/component_intro_android_sync.xml diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/IntroScreenActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/IntroScreenActivity.java index 31724ea9..7ea9d109 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/IntroScreenActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/IntroScreenActivity.java @@ -41,6 +41,7 @@ import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Spinner; +import android.widget.Switch; import android.widget.TextView; import androidx.annotation.NonNull; @@ -63,6 +64,7 @@ public class IntroScreenActivity extends IntroActivity { private EncryptionFragment encryptionFragment; private AuthenticationFragment authenticationFragment; + private AndroidSyncFragment androidSyncFragment; private void saveSettings() { Constants.EncryptionType encryptionType = encryptionFragment.getEncryptionType(); @@ -70,6 +72,7 @@ public class IntroScreenActivity extends IntroActivity { settings.setEncryption(encryptionType); settings.setAuthMethod(authMethod); + settings.setAndroidBackupServiceEnabled(androidSyncFragment.getSyncEnabled()); if (authMethod == Constants.AuthMethod.PASSWORD || authMethod == Constants.AuthMethod.PIN) { String password = authenticationFragment.getPassword(); @@ -86,6 +89,7 @@ public class IntroScreenActivity extends IntroActivity { encryptionFragment = new EncryptionFragment(); authenticationFragment = new AuthenticationFragment(); + androidSyncFragment = new AndroidSyncFragment(encryptionFragment); encryptionFragment.setEncryptionChangedCallback(newEncryptionType -> authenticationFragment.updateEncryptionType(newEncryptionType)); @@ -118,6 +122,13 @@ public class IntroScreenActivity extends IntroActivity { .build() ); + addSlide(new FragmentSlide.Builder() + .background(R.color.colorPrimary) + .backgroundDark(R.color.colorPrimaryDark) + .fragment(androidSyncFragment) + .build() + ); + addSlide(new SimpleSlide.Builder() .title(R.string.intro_slide4_title) .description(R.string.intro_slide4_desc) @@ -127,6 +138,7 @@ public class IntroScreenActivity extends IntroActivity { .build() ); + addOnNavigationBlockedListener((position, direction) -> { if (position == 2) authenticationFragment.flashWarning(); @@ -135,7 +147,7 @@ public class IntroScreenActivity extends IntroActivity { addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { - if (position == 3) + if (position == getSlides().size() - 1) saveSettings(); } @@ -220,6 +232,39 @@ public class IntroScreenActivity extends IntroActivity { } } + public static class AndroidSyncFragment extends SlideFragment { + private Switch introAndroidSync; + private EncryptionFragment encryptionFragment; + + public AndroidSyncFragment(EncryptionFragment encryptionFragment) { + this.encryptionFragment = encryptionFragment; + } + + public boolean getSyncEnabled() + { + return introAndroidSync.isChecked(); + } + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View root = inflater.inflate(R.layout.component_intro_android_sync, container, false); + + introAndroidSync = root.findViewById(R.id.introAndroidSync); + introAndroidSync.setOnCheckedChangeListener((compoundButton, b) -> { + compoundButton.setText( b ? + R.string.settings_toast_android_sync_enabled : + R.string.settings_toast_android_sync_disabled + ); + }); + + introAndroidSync.setChecked(encryptionFragment.getEncryptionType() != Constants.EncryptionType.KEYSTORE); + introAndroidSync.setEnabled(encryptionFragment.getEncryptionType() != Constants.EncryptionType.KEYSTORE); + + return root; + } + } + public static class AuthenticationFragment extends SlideFragment { private Constants.EncryptionType encryptionType = Constants.EncryptionType.KEYSTORE; diff --git a/app/src/main/res/layout/component_intro_android_sync.xml b/app/src/main/res/layout/component_intro_android_sync.xml new file mode 100644 index 00000000..0bc7a73f --- /dev/null +++ b/app/src/main/res/layout/component_intro_android_sync.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings_intro.xml b/app/src/main/res/values/strings_intro.xml index 5856d1bc..ff465dbe 100644 --- a/app/src/main/res/values/strings_intro.xml +++ b/app/src/main/res/values/strings_intro.xml @@ -38,4 +38,5 @@ Finished Your settings have been saved, you are now all set to use andOTP! + Android sync is a feature built in to android used to back up app data to a 3rd party service (usually Google). Backups are always encrypted and unaccessible to 3rd parties without your master password. Requires use of Password encryption method. \ No newline at end of file