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

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

Merge "Fix test harness mode" into sc-dev am: c11f9eca

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

Change-Id: Iaee6a86cd18a20d5bba56ad125c3ebe4b6aebca5
parents c253e33e c11f9eca
Loading
Loading
Loading
Loading
+25 −2
Original line number Diff line number Diff line
@@ -375,15 +375,38 @@ public class PersistentDataBlockService extends SystemService {

        try {
            FileChannel channel = getBlockOutputChannel();
            // Format the data selectively.
            //
            // 1. write header, set length = 0
            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);
            buf.flip();
            channel.write(buf);
            // corrupt the payload explicitly
            channel.force(true);

            // 2. corrupt the legacy FRP data explicitly
            int payload_size = (int) getBlockDeviceSize() - header_size;
            buf = ByteBuffer.allocate(payload_size);
            buf = ByteBuffer.allocate(payload_size
                          - TEST_MODE_RESERVED_SIZE - FRP_CREDENTIAL_RESERVED_SIZE - 1);
            channel.write(buf);
            channel.force(true);

            // 3. skip the test mode data and leave it unformat
            //    This is for a feature that enables testing.
            channel.position(channel.position() + TEST_MODE_RESERVED_SIZE);

            // 4. wipe the FRP_CREDENTIAL explicitly
            buf = ByteBuffer.allocate(FRP_CREDENTIAL_RESERVED_SIZE);
            channel.write(buf);
            channel.force(true);

            // 5. set unlock = 0 because it's a formatPartitionLocked
            buf = ByteBuffer.allocate(FRP_CREDENTIAL_RESERVED_SIZE);
            buf.put((byte)0);
            buf.flip();
            channel.write(buf);
            channel.force(true);
        } catch (IOException e) {