beemdevelopment/Aegis · error · VaultBackupPermissionException

No persisted URI permissions

Error message

No persisted URI permissions

What it means

Guard in VaultBackupManager.createBackup(File, Uri): thrown as VaultBackupPermissionException when hasPermissionsAt(fileUri) reports no persisted SAF write permission for the backup destination. This happens when the user picked a backup folder but the persisted URI grant was revoked (e.g. after the document moved or permissions were cleared), so writing the backup would fail.

Solutions

  1. On VaultBackupPermissionException, prompt the user to re-select the backup location so fresh persistable URI permissions are granted
  2. Call takePersistableUriPermission with FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION when the backup Uri is first chosen
  3. Check ContentResolver.getPersistedUriPermissions() before writing and fail with instructions instead of attempting the write
  4. Handle the case where the persisted grant was revoked (e.g. app reinstall or user revocation) by resetting the backup setting
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at app/src/main/java/com/beemdevelopment/aegis/vault/VaultBackupManager.java:89 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of beemdevelopment/Aegis@d6f4e5925a (2026-09-08). Data as JSON: /api/errors/3cee4e5aea108fa3. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/com/beemdevelopment/aegis/vault/VaultBackupManager.java:89

            throws VaultRepositoryException, VaultBackupPermissionException {
        if (uri == null) {
            throw new VaultRepositoryException("getBackupsLocation returned null");
        }
        if (strategy == BackupsVersioningStrategy.SINGLE_BACKUP) {
            createBackup(tempFile, uri);
        } else if (strategy == BackupsVersioningStrategy.MULTIPLE_BACKUPS) {
            createBackup(tempFile, uri, versionsToKeep);
        } else {
            throw new VaultRepositoryException("Invalid backups versioning strategy");
        }
    }

    private void createBackup(File tempFile, Uri fileUri)
            throws VaultRepositoryException, VaultBackupPermissionException {
        Log.i(TAG, String.format("Creating backup at %s", fileUri));
        try {
            if (!hasPermissionsAt(fileUri)) {
                throw new VaultBackupPermissionException("No persisted URI permissions");
            }
            ContentResolver resolver = _context.getContentResolver();
            try (FileInputStream inStream = new FileInputStream(tempFile);
                 OutputStream outStream = resolver.openOutputStream(fileUri, "wt")
            ) {
                if (outStream == null) {
                    throw new IOException("openOutputStream returned null");
                }
                IOUtils.copy(inStream, outStream);
            } catch (IOException exception) {
                throw new VaultRepositoryException(exception);
            }
        } catch (VaultRepositoryException | VaultBackupPermissionException exception) {
            Log.e(TAG, String.format("Unable to create backup: %s", exception));
            throw exception;
        } finally {
            tempFile.delete();
        }

View on GitHub (pinned to d6f4e5925a)