summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Howard Chen <howardsoc@google.com> 2021-07-23 11:10:29 +0800
committer Howard Chen <howardsoc@google.com> 2021-07-23 15:30:33 +0800
commit574f47af6514f346c5cb9712cc160e2c4b98afd5 (patch)
treea6efbc98513887f77e064cfb351f14638e591288
parentd7ec851ef4f08ba0213c509ed21c410bfea0ce0b (diff)
Fix test harness mode
There's legacy request that when OEM unlock is enabled, PDB service format the PDB in the onStart to make sure the fastboot -w can wipe the PDB for devices that do not have recovery OS. In the past, only the header is cleaned up so test harness can still peek the data in the PDB. b/185369514 is an issue due to the incomplete format so an explicit clean up is required. This CL makes it half-format to support both use cases. Bug: 192268220 Bug: 18644051 Bug: 185369514 Test: Test harness Change-Id: I290c5b2fde9f1337b41337795e4c2fbcb9e95f6e
-rw-r--r--services/core/java/com/android/server/PersistentDataBlockService.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/PersistentDataBlockService.java b/services/core/java/com/android/server/PersistentDataBlockService.java
index e336b6bafac4..16645dfd386d 100644
--- a/services/core/java/com/android/server/PersistentDataBlockService.java
+++ b/services/core/java/com/android/server/PersistentDataBlockService.java
@@ -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) {