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 28cbf504..cc027ed5 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; @@ -64,6 +65,7 @@ public class IntroScreenActivity extends IntroActivity { private EncryptionFragment encryptionFragment; private AuthenticationFragment authenticationFragment; + private AndroidSyncFragment androidSyncFragment; private void saveSettings() { Constants.EncryptionType encryptionType = encryptionFragment.getEncryptionType(); @@ -71,6 +73,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(); @@ -87,6 +90,7 @@ public class IntroScreenActivity extends IntroActivity { encryptionFragment = new EncryptionFragment(); authenticationFragment = new AuthenticationFragment(); + androidSyncFragment = new AndroidSyncFragment(encryptionFragment); encryptionFragment.setEncryptionChangedCallback(newEncryptionType -> authenticationFragment.updateEncryptionType(newEncryptionType)); @@ -119,6 +123,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) @@ -128,6 +139,7 @@ public class IntroScreenActivity extends IntroActivity { .build() ); + addOnNavigationBlockedListener((position, direction) -> { if (position == 2) authenticationFragment.flashWarning(); @@ -136,7 +148,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(); } @@ -221,6 +233,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/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java index 9ee85cfa..236bb05d 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; @@ -168,6 +169,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/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 diff --git a/app/src/main/res/values/strings_settings.xml b/app/src/main/res/values/strings_settings.xml index 48ca4ea1..0c5e2912 100644 --- a/app/src/main/res/values/strings_settings.xml +++ b/app/src/main/res/values/strings_settings.xml @@ -136,6 +136,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?