Skip to content

Commit 3dd70de

Browse files
Merge pull request #1233 from alexbakker/explain-uri-perms
Explain vault backup permission error
2 parents 88caafd + 08c7392 commit 3dd70de

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

app/src/main/java/com/beemdevelopment/aegis/Preferences.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import com.beemdevelopment.aegis.util.JsonUtils;
1313
import com.beemdevelopment.aegis.util.TimeUtils;
14+
import com.beemdevelopment.aegis.vault.VaultBackupPermissionException;
1415

1516
import org.json.JSONArray;
1617
import org.json.JSONException;
@@ -507,14 +508,16 @@ public static class BackupResult {
507508
private final Date _time;
508509
private boolean _isBuiltIn;
509510
private final String _error;
511+
private final boolean _isPermissionError;
510512

511513
public BackupResult(@Nullable Exception e) {
512-
this(new Date(), e == null ? null : e.toString());
514+
this(new Date(), e == null ? null : e.toString(), e instanceof VaultBackupPermissionException);
513515
}
514516

515-
private BackupResult(Date time, @Nullable String error) {
517+
private BackupResult(Date time, @Nullable String error, boolean isPermissionError) {
516518
_time = time;
517519
_error = error;
520+
_isPermissionError = isPermissionError;
518521
}
519522

520523
@Nullable
@@ -542,12 +545,17 @@ private void setIsBuiltIn(boolean isBuiltIn) {
542545
_isBuiltIn = isBuiltIn;
543546
}
544547

548+
public boolean isPermissionError() {
549+
return _isPermissionError;
550+
}
551+
545552
public String toJson() {
546553
JSONObject obj = new JSONObject();
547554

548555
try {
549556
obj.put("time", _time.getTime());
550557
obj.put("error", _error == null ? JSONObject.NULL : _error);
558+
obj.put("isPermissionError", _isPermissionError);
551559
} catch (JSONException e) {
552560
throw new RuntimeException(e);
553561
}
@@ -559,7 +567,8 @@ public static BackupResult fromJson(String json) throws JSONException {
559567
JSONObject obj = new JSONObject(json);
560568
long time = obj.getLong("time");
561569
String error = JsonUtils.optString(obj, "error");
562-
return new BackupResult(new Date(time), error);
570+
boolean isPermissionError = obj.optBoolean("isPermissionError");
571+
return new BackupResult(new Date(time), error, isPermissionError);
563572
}
564573
}
565574

app/src/main/java/com/beemdevelopment/aegis/ui/dialogs/Dialogs.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ public static void showErrorDialog(Context context, String message, CharSequence
407407

408408
public static void showBackupErrorDialog(Context context, Preferences.BackupResult backupRes, DialogInterface.OnClickListener listener) {
409409
String system = context.getString(backupRes.isBuiltIn() ? R.string.backup_system_builtin : R.string.backup_system_android);
410-
String message = context.getString(R.string.backup_error_dialog_details, system, backupRes.getElapsedSince(context));
410+
@StringRes int details = backupRes.isPermissionError() ? R.string.backup_permission_error_dialog_details : R.string.backup_error_dialog_details;
411+
String message = context.getString(details, system, backupRes.getElapsedSince(context));
411412
Dialogs.showErrorDialog(context, message, backupRes.getError(), listener);
412413
}
413414

app/src/main/java/com/beemdevelopment/aegis/vault/VaultBackupManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,23 @@ public void scheduleBackup(File tempFile, Uri dirUri, int versionsToKeep) {
5353
try {
5454
createBackup(tempFile, dirUri, versionsToKeep);
5555
_prefs.setBuiltInBackupResult(new Preferences.BackupResult(null));
56-
} catch (VaultRepositoryException e) {
56+
} catch (VaultRepositoryException | VaultBackupPermissionException e) {
5757
e.printStackTrace();
5858
_prefs.setBuiltInBackupResult(new Preferences.BackupResult(e));
5959
}
6060
});
6161
}
6262

63-
private void createBackup(File tempFile, Uri dirUri, int versionsToKeep) throws VaultRepositoryException {
63+
private void createBackup(File tempFile, Uri dirUri, int versionsToKeep)
64+
throws VaultRepositoryException, VaultBackupPermissionException {
6465
FileInfo fileInfo = new FileInfo(FILENAME_PREFIX);
6566
DocumentFile dir = DocumentFile.fromTreeUri(_context, dirUri);
6667

6768
try {
6869
Log.i(TAG, String.format("Creating backup at %s: %s", Uri.decode(dir.getUri().toString()), fileInfo.toString()));
6970

7071
if (!hasPermissionsAt(dirUri)) {
71-
throw new VaultRepositoryException("No persisted URI permissions");
72+
throw new VaultBackupPermissionException("No persisted URI permissions");
7273
}
7374

7475
// If we create a file with a name that already exists, SAF will append a number
@@ -92,7 +93,7 @@ private void createBackup(File tempFile, Uri dirUri, int versionsToKeep) throws
9293
} catch (IOException e) {
9394
throw new VaultRepositoryException(e);
9495
}
95-
} catch (VaultRepositoryException e) {
96+
} catch (VaultRepositoryException | VaultBackupPermissionException e) {
9697
Log.e(TAG, String.format("Unable to create backup: %s", e.toString()));
9798
throw e;
9899
} finally {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.beemdevelopment.aegis.vault;
2+
3+
public class VaultBackupPermissionException extends Exception {
4+
public VaultBackupPermissionException(String message) {
5+
super(message);
6+
}
7+
}

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@
390390
comment="The first parameter is the type of backup (e.g. built-in or Android backup). The second parameter is an elapsed time in the style of 'x seconds/minutes/days ago'.">
391391
A recent vault backup attempt using %s failed because an error occurred. The backup was attempted %s. Please check your backup settings to make sure backups can complete successfully.
392392
</string>
393+
<string
394+
name="backup_permission_error_dialog_details"
395+
comment="The first parameter is the type of backup (e.g. built-in or Android backup). The second parameter is an elapsed time in the style of 'x seconds/minutes/days ago'.">
396+
A recent vault backup attempt using %s failed because Aegis did not have permission to write to the backup destination. The backup was attempted %s. This error can occur if you moved/renamed the backup destination or if you recently restored Aegis from a backup. Please reconfigure the backup destination.
397+
</string>
393398
<string name="backup_system_builtin">Aegis\' built-in automatic backups</string>
394399
<string name="backup_system_android">Android\'s cloud backup system</string>
395400
<string

0 commit comments

Comments
 (0)