Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5daa9b5 authored by Howard Chen's avatar Howard Chen Committed by Automerger Merge Worker
Browse files

Merge "Corrupt the PersistentDataBlock payload explicitly in factory reset"...

Merge "Corrupt the PersistentDataBlock payload explicitly in factory reset" am: af5c516b am: 26bad177 am: fd89f0cf am: 6e6da13a

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1710289

Change-Id: I723dee63543ad524c7598047d8a1a5ce83ab0acb
parents 524d68d4 6e6da13a
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -39,11 +39,9 @@ import com.android.internal.annotations.GuardedBy;
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;
@@ -377,11 +375,16 @@ public class PersistentDataBlockService extends SystemService {

        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);