Merge "Corrupt the PersistentDataBlock payload explicitly in factory reset"
diff --git a/services/core/java/com/android/server/PersistentDataBlockService.java b/services/core/java/com/android/server/PersistentDataBlockService.java
index c6fdb9d..e109b87 100644
--- a/services/core/java/com/android/server/PersistentDataBlockService.java
+++ b/services/core/java/com/android/server/PersistentDataBlockService.java
@@ -38,11 +38,9 @@
import libcore.io.IoUtils;
import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
@@ -375,11 +373,16 @@
try {
FileChannel channel = getBlockOutputChannel();
- ByteBuffer buf = ByteBuffer.allocate(DIGEST_SIZE_BYTES + HEADER_SIZE);
+ int header_size = DIGEST_SIZE_BYTES + HEADER_SIZE;
+ ByteBuffer buf = ByteBuffer.allocate(header_size);
buf.put(new byte[DIGEST_SIZE_BYTES]);
buf.putInt(PARTITION_TYPE_MARKER);
buf.putInt(0);
channel.write(buf);
+ // corrupt the payload explicitly
+ int payload_size = (int) getBlockDeviceSize() - header_size;
+ buf = ByteBuffer.allocate(payload_size);
+ channel.write(buf);
channel.force(true);
} catch (IOException e) {
Slog.e(TAG, "failed to format block", e);