Verify number of backup frames written is read back.

This commit is contained in:
Clark
2023-06-06 10:14:19 -04:00
committed by Cody Henthorne
parent 93df01e266
commit 71aa17bad6
2 changed files with 12 additions and 1 deletions

View File

@@ -42,12 +42,20 @@ object BackupVerifier {
frame = inputStream.readFrame()
}
if (frame.end == true) {
count++
}
}
if (cancellationSignal.isCanceled) {
throw FullBackupExporter.BackupCanceledException()
}
if (count != expectedCount) {
Log.e(TAG, "Incorrect number of frames expected $expectedCount but only $count")
return false
}
return true
}

View File

@@ -228,7 +228,7 @@ public class FullBackupExporter extends FullBackupBase {
outputStream.close();
}
}
return new BackupEvent(BackupEvent.Type.FINISHED, ++count, estimatedCountOutside);
return new BackupEvent(BackupEvent.Type.FINISHED, outputStream.frames, estimatedCountOutside);
}
private static long calculateCount(@NonNull Context context, @NonNull SQLiteDatabase input, List<String> tables) {
@@ -637,6 +637,8 @@ public class FullBackupExporter extends FullBackupBase {
private final byte[] iv;
private int counter;
private int frames;
private BackupFrameOutputStream(@NonNull OutputStream output, @NonNull String passphrase) throws IOException {
try {
byte[] salt = Util.getSecretBytes(32);
@@ -796,6 +798,7 @@ public class FullBackupExporter extends FullBackupBase {
out.write(length);
out.write(frameCiphertext);
out.write(frameMac, 0, 10);
frames++;
} catch (InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) {
throw new AssertionError(e);
}