Implement several new features and improve SAF integration

This commit implements the following features:
- Trash/Archive for deleted entries
- Duress Password (Decoy Vault)
- Advanced Sorting and Usage Insights
- Improved Storage Access Framework (SAF) Integration

The NFC Vault Transfer feature was disabled due to build issues with deprecated APIs.
pull/1699/head
google-labs-jules[bot] 2 months ago
parent f2276f0e45
commit 0139bd46e1

@ -167,6 +167,22 @@ public class BackupsPreferencesFragment extends PreferencesFragment {
});
return false;
});
Preference testBackupsLocationPreference = requirePreference("pref_test_backups_location");
testBackupsLocationPreference.setOnPreferenceClickListener(preference -> {
Uri backupsLocation = _prefs.getBackupsLocation();
if (backupsLocation != null) {
boolean success = new VaultBackupManager(requireContext(), _auditLogRepository).testBackupLocation(backupsLocation);
if (success) {
Toast.makeText(requireContext(), "Test successful!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(requireContext(), "Test failed. Please check the backup location and permissions.", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(requireContext(), "No backup location set.", Toast.LENGTH_SHORT).show();
}
return true;
});
}
private void saveAndDisableBackupReminder(boolean understand) {
@ -198,6 +214,7 @@ public class BackupsPreferencesFragment extends PreferencesFragment {
boolean androidBackupEnabled = _prefs.isAndroidBackupsEnabled() && encrypted;
boolean backupEnabled = _prefs.isBackupsEnabled() && encrypted;
boolean backupReminderEnabled = _prefs.isBackupReminderEnabled();
requirePreference("pref_test_backups_location").setVisible(backupEnabled);
_backupsPasswordWarningPreference.setVisible(_vaultManager.getVault().isBackupPasswordSet());
_androidBackupsPreference.setChecked(androidBackupEnabled);
_androidBackupsPreference.setEnabled(encrypted);

@ -86,7 +86,7 @@ public class VaultBackupManager {
Log.i(TAG, String.format("Creating backup at %s", fileUri));
try {
if (!hasPermissionsAt(fileUri)) {
throw new VaultBackupPermissionException("No persisted URI permissions");
throw new VaultBackupPermissionException("Aegis does not have permission to write to the selected backup location. Please select the backup location again.");
}
ContentResolver resolver = _context.getContentResolver();
try (FileInputStream inStream = new FileInputStream(tempFile);
@ -116,7 +116,7 @@ public class VaultBackupManager {
Log.i(TAG, String.format("Creating backup at %s: %s", Uri.decode(dir.getUri().toString()), fileInfo.toString()));
if (!hasPermissionsAt(dirUri)) {
throw new VaultBackupPermissionException("No persisted URI permissions");
throw new VaultBackupPermissionException("Aegis does not have permission to write to the selected backup location. Please select the backup location again.");
}
// If we create a file with a name that already exists, SAF will append a number
@ -160,6 +160,27 @@ public class VaultBackupManager {
return false;
}
public boolean testBackupLocation(Uri uri) {
if (uri == null) {
return false;
}
try {
DocumentFile dir = DocumentFile.fromTreeUri(_context, uri);
if (dir == null || !dir.isDirectory() || !dir.canWrite()) {
return false;
}
DocumentFile testFile = dir.createFile("text/plain", "aegis_test_file");
if (testFile == null) {
return false;
}
testFile.delete();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
private void enforceVersioning(DocumentFile dir, int versionsToKeep) {
if (versionsToKeep <= 0) {
return;

@ -31,6 +31,9 @@
android:key="pref_backups_location"
android:title="@string/pref_backups_location_title"
android:summary="@string/pref_backups_location_summary" />
<Preference
android:key="pref_test_backups_location"
android:title="Test Location" />
<Preference
android:key="pref_backups_trigger"
android:title="@string/pref_backups_trigger_title"

Loading…
Cancel
Save