Merge pull request #622 from andOTP/Add-backup-log
Add android sync to initial flow
This commit is contained in:
commit
03f7d0b020
6 changed files with 109 additions and 1 deletions
|
@ -41,6 +41,7 @@ import android.widget.ArrayAdapter;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
import android.widget.Switch;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -64,6 +65,7 @@ public class IntroScreenActivity extends IntroActivity {
|
||||||
|
|
||||||
private EncryptionFragment encryptionFragment;
|
private EncryptionFragment encryptionFragment;
|
||||||
private AuthenticationFragment authenticationFragment;
|
private AuthenticationFragment authenticationFragment;
|
||||||
|
private AndroidSyncFragment androidSyncFragment;
|
||||||
|
|
||||||
private void saveSettings() {
|
private void saveSettings() {
|
||||||
Constants.EncryptionType encryptionType = encryptionFragment.getEncryptionType();
|
Constants.EncryptionType encryptionType = encryptionFragment.getEncryptionType();
|
||||||
|
@ -71,6 +73,7 @@ public class IntroScreenActivity extends IntroActivity {
|
||||||
|
|
||||||
settings.setEncryption(encryptionType);
|
settings.setEncryption(encryptionType);
|
||||||
settings.setAuthMethod(authMethod);
|
settings.setAuthMethod(authMethod);
|
||||||
|
settings.setAndroidBackupServiceEnabled(androidSyncFragment.getSyncEnabled());
|
||||||
|
|
||||||
if (authMethod == Constants.AuthMethod.PASSWORD || authMethod == Constants.AuthMethod.PIN) {
|
if (authMethod == Constants.AuthMethod.PASSWORD || authMethod == Constants.AuthMethod.PIN) {
|
||||||
String password = authenticationFragment.getPassword();
|
String password = authenticationFragment.getPassword();
|
||||||
|
@ -87,6 +90,7 @@ public class IntroScreenActivity extends IntroActivity {
|
||||||
|
|
||||||
encryptionFragment = new EncryptionFragment();
|
encryptionFragment = new EncryptionFragment();
|
||||||
authenticationFragment = new AuthenticationFragment();
|
authenticationFragment = new AuthenticationFragment();
|
||||||
|
androidSyncFragment = new AndroidSyncFragment(encryptionFragment);
|
||||||
|
|
||||||
encryptionFragment.setEncryptionChangedCallback(newEncryptionType -> authenticationFragment.updateEncryptionType(newEncryptionType));
|
encryptionFragment.setEncryptionChangedCallback(newEncryptionType -> authenticationFragment.updateEncryptionType(newEncryptionType));
|
||||||
|
|
||||||
|
@ -119,6 +123,13 @@ public class IntroScreenActivity extends IntroActivity {
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
addSlide(new FragmentSlide.Builder()
|
||||||
|
.background(R.color.colorPrimary)
|
||||||
|
.backgroundDark(R.color.colorPrimaryDark)
|
||||||
|
.fragment(androidSyncFragment)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
addSlide(new SimpleSlide.Builder()
|
addSlide(new SimpleSlide.Builder()
|
||||||
.title(R.string.intro_slide4_title)
|
.title(R.string.intro_slide4_title)
|
||||||
.description(R.string.intro_slide4_desc)
|
.description(R.string.intro_slide4_desc)
|
||||||
|
@ -128,6 +139,7 @@ public class IntroScreenActivity extends IntroActivity {
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
addOnNavigationBlockedListener((position, direction) -> {
|
addOnNavigationBlockedListener((position, direction) -> {
|
||||||
if (position == 2)
|
if (position == 2)
|
||||||
authenticationFragment.flashWarning();
|
authenticationFragment.flashWarning();
|
||||||
|
@ -136,7 +148,7 @@ public class IntroScreenActivity extends IntroActivity {
|
||||||
addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPageSelected(int position) {
|
public void onPageSelected(int position) {
|
||||||
if (position == 3)
|
if (position == getSlides().size() - 1)
|
||||||
saveSettings();
|
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 {
|
public static class AuthenticationFragment extends SlideFragment {
|
||||||
private Constants.EncryptionType encryptionType = Constants.EncryptionType.KEYSTORE;
|
private Constants.EncryptionType encryptionType = Constants.EncryptionType.KEYSTORE;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ import android.preference.PreferenceManager;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
|
||||||
import android.provider.DocumentsContract;
|
import android.provider.DocumentsContract;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.ViewStub;
|
import android.view.ViewStub;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -168,6 +169,13 @@ public class SettingsActivity extends BaseActivity
|
||||||
if (fragment.useAndroidSync != null)
|
if (fragment.useAndroidSync != null)
|
||||||
fragment.useAndroidSync.setEnabled(true);
|
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();
|
fragment.updateAutoBackup();
|
||||||
|
|
|
@ -29,6 +29,8 @@ import android.app.backup.BackupDataOutput;
|
||||||
import android.app.backup.FileBackupHelper;
|
import android.app.backup.FileBackupHelper;
|
||||||
import android.app.backup.SharedPreferencesBackupHelper;
|
import android.app.backup.SharedPreferencesBackupHelper;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -44,19 +46,29 @@ public class BackupAgent extends BackupAgentHelper {
|
||||||
@Override
|
@Override
|
||||||
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) throws IOException {
|
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) throws IOException {
|
||||||
Settings settings = new Settings(this);
|
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()) {
|
if(settings.getAndroidBackupServiceEnabled()) {
|
||||||
synchronized (DatabaseHelper.DatabaseFileLock) {
|
synchronized (DatabaseHelper.DatabaseFileLock) {
|
||||||
|
stringBuilder.append(" calling parent onBackup");
|
||||||
super.onBackup(oldState, data, newState);
|
super.onBackup(oldState, data, newState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Log.d(BackupAgent.class.getSimpleName(), stringBuilder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException {
|
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) {
|
synchronized (DatabaseHelper.DatabaseFileLock) {
|
||||||
|
stringBuilder.append(" but restore happens regardless, calling parent onRestore");
|
||||||
super.onRestore(data, appVersionCode, newState);
|
super.onRestore(data, appVersionCode, newState);
|
||||||
}
|
}
|
||||||
|
Log.d(BackupAgent.class.getSimpleName(), stringBuilder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
39
app/src/main/res/layout/component_intro_android_sync.xml
Normal file
39
app/src/main/res/layout/component_intro_android_sync.xml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clipToPadding="false">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="top"
|
||||||
|
android:gravity="top"
|
||||||
|
android:padding="@dimen/activity_margin_large" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:text="@string/settings_title_enable_android_backup_service" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/activity_margin"
|
||||||
|
android:text="@string/intro_slide_android_backup_desc"/>
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/introAndroidSync"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/activity_margin"
|
||||||
|
android:checked="true"
|
||||||
|
android:text="@string/settings_toast_android_sync_enabled" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
|
@ -38,4 +38,5 @@
|
||||||
<string name="intro_slide4_title">Finished</string>
|
<string name="intro_slide4_title">Finished</string>
|
||||||
<string name="intro_slide4_desc">Your settings have been saved, you are now all set to use
|
<string name="intro_slide4_desc">Your settings have been saved, you are now all set to use
|
||||||
<b>andOTP</b>!</string>
|
<b>andOTP</b>!</string>
|
||||||
|
<string name="intro_slide_android_backup_desc">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.</string>
|
||||||
</resources>
|
</resources>
|
|
@ -136,6 +136,9 @@
|
||||||
<string name="settings_toast_auth_upgrade_failed">Failed to silently upgrade your password / PIN
|
<string name="settings_toast_auth_upgrade_failed">Failed to silently upgrade your password / PIN
|
||||||
to the new encryption, please manually reset it in the Settings!</string>
|
to the new encryption, please manually reset it in the Settings!</string>
|
||||||
|
|
||||||
|
<string name="settings_toast_android_sync_enabled">Android sync enabled</string>
|
||||||
|
<string name="settings_toast_android_sync_disabled">Android sync disabled</string>
|
||||||
|
|
||||||
<string name="settings_dialog_title_warning">Warning</string>
|
<string name="settings_dialog_title_warning">Warning</string>
|
||||||
<string name="settings_dialog_title_error">Error</string>
|
<string name="settings_dialog_title_error">Error</string>
|
||||||
<string name="settings_dialog_title_clear_keystore">Clear the KeyStore?</string>
|
<string name="settings_dialog_title_clear_keystore">Clear the KeyStore?</string>
|
||||||
|
|
Loading…
Reference in a new issue