Merge "Create top-level directory for secretkeeper" into main
diff --git a/Android.bp b/Android.bp
index 2f6fc20..64d193a 100644
--- a/Android.bp
+++ b/Android.bp
@@ -64,3 +64,9 @@
         },
     },
 }
+
+genrule_defaults {
+    name: "dts_to_dtb",
+    tools: ["dtc"],
+    cmd: "$(location dtc) -I dts -O dtb $(in) -o $(out)",
+}
diff --git a/compos/benchmark/Android.bp b/compos/benchmark/Android.bp
index dc0c01c..93927a2 100644
--- a/compos/benchmark/Android.bp
+++ b/compos/benchmark/Android.bp
@@ -13,7 +13,7 @@
         "androidx.test.ext.junit",
         "MicrodroidDeviceTestHelper",
         "MicrodroidTestHelper",
-        "truth-prebuilt",
+        "truth",
     ],
     sdk_version: "test_current",
     use_embedded_native_libs: true,
diff --git a/libs/apkverify/src/sigutil.rs b/libs/apkverify/src/sigutil.rs
index 395b493..99132b6 100644
--- a/libs/apkverify/src/sigutil.rs
+++ b/libs/apkverify/src/sigutil.rs
@@ -51,8 +51,8 @@
 }
 
 impl<R: Read + Seek> ApkSections<R> {
-    pub fn new(reader: R) -> Result<ApkSections<R>> {
-        let (mut reader, zip_sections) = zip_sections(reader)?;
+    pub fn new(mut reader: R) -> Result<ApkSections<R>> {
+        let zip_sections = zip_sections(&mut reader)?;
         let (signing_block_offset, signing_block_size) =
             find_signing_block(&mut reader, zip_sections.central_directory_offset)?;
         Ok(ApkSections {
diff --git a/libs/apkverify/src/ziputil.rs b/libs/apkverify/src/ziputil.rs
index 5e513a7..715ea30 100644
--- a/libs/apkverify/src/ziputil.rs
+++ b/libs/apkverify/src/ziputil.rs
@@ -40,7 +40,7 @@
 }
 
 /// Discover the layout of a zip file.
-pub fn zip_sections<R: Read + Seek>(mut reader: R) -> Result<(R, ZipSections)> {
+pub fn zip_sections<R: Read + Seek>(mut reader: R) -> Result<ZipSections> {
     // open a zip to parse EOCD
     let archive = ZipArchive::new(reader)?;
     let eocd_size = archive.comment().len() + EOCD_SIZE_WITHOUT_COMMENT;
@@ -65,15 +65,12 @@
         "Invalid ZIP: EOCD should follow CD with no extra data or overlap."
     );
 
-    Ok((
-        reader,
-        ZipSections {
-            central_directory_offset,
-            central_directory_size,
-            eocd_offset,
-            eocd_size: eocd_size as u32,
-        },
-    ))
+    Ok(ZipSections {
+        central_directory_offset,
+        central_directory_size,
+        eocd_offset,
+        eocd_size: eocd_size as u32,
+    })
 }
 
 fn get_central_directory(buf: &[u8]) -> Result<(u32, u32)> {
@@ -109,7 +106,8 @@
 
     #[test]
     fn test_zip_sections() {
-        let (cursor, sections) = zip_sections(create_test_zip()).unwrap();
+        let mut cursor = create_test_zip();
+        let sections = zip_sections(&mut cursor).unwrap();
         assert_eq!(
             sections.eocd_offset,
             (cursor.get_ref().len() - EOCD_SIZE_WITHOUT_COMMENT) as u32
@@ -136,8 +134,8 @@
 
     #[test]
     fn test_zip_sections_with_apk() {
-        let apk = File::open("tests/data/v3-only-with-stamp.apk").unwrap();
-        let (mut reader, sections) = zip_sections(apk).unwrap();
+        let mut reader = File::open("tests/data/v3-only-with-stamp.apk").unwrap();
+        let sections = zip_sections(&mut reader).unwrap();
 
         // Checks Central directory.
         assert_eq!(
diff --git a/libs/libfdt/Android.bp b/libs/libfdt/Android.bp
index 402040c..0a05471 100644
--- a/libs/libfdt/Android.bp
+++ b/libs/libfdt/Android.bp
@@ -66,28 +66,28 @@
 
 genrule {
     name: "fdt_test_tree_one_memory_range_dtb",
-    defaults: ["test_avf_dts_to_dtb"],
+    defaults: ["dts_to_dtb"],
     srcs: ["tests/data/test_tree_one_memory_range.dts"],
     out: ["data/test_tree_one_memory_range.dtb"],
 }
 
 genrule {
     name: "fdt_test_tree_multiple_memory_ranges_dtb",
-    defaults: ["test_avf_dts_to_dtb"],
+    defaults: ["dts_to_dtb"],
     srcs: ["tests/data/test_tree_multiple_memory_ranges.dts"],
     out: ["data/test_tree_multiple_memory_ranges.dtb"],
 }
 
 genrule {
     name: "fdt_test_tree_empty_memory_range_dtb",
-    defaults: ["test_avf_dts_to_dtb"],
+    defaults: ["dts_to_dtb"],
     srcs: ["tests/data/test_tree_empty_memory_range.dts"],
     out: ["data/test_tree_empty_memory_range.dtb"],
 }
 
 genrule {
     name: "fdt_test_tree_no_memory_node_dtb",
-    defaults: ["test_avf_dts_to_dtb"],
+    defaults: ["dts_to_dtb"],
     srcs: ["tests/data/test_tree_no_memory_node.dts"],
     out: ["data/test_tree_no_memory_node.dtb"],
 }
diff --git a/libs/libfdt/src/lib.rs b/libs/libfdt/src/lib.rs
index 758df2a..a6d5739 100644
--- a/libs/libfdt/src/lib.rs
+++ b/libs/libfdt/src/lib.rs
@@ -202,11 +202,11 @@
 }
 
 impl<'a> FdtNode<'a> {
-    /// Create immutable node from a mutable node at the same offset
+    /// Creates immutable node from a mutable node at the same offset.
     pub fn from_mut(other: &'a FdtNodeMut) -> Self {
         FdtNode { fdt: other.fdt, offset: other.offset }
     }
-    /// Find parent node.
+    /// Returns parent node.
     pub fn parent(&self) -> Result<Self> {
         // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
         let ret = unsafe { libfdt_bindgen::fdt_parent_offset(self.fdt.as_ptr(), self.offset) };
@@ -214,12 +214,12 @@
         Ok(Self { fdt: self.fdt, offset: fdt_err(ret)? })
     }
 
-    /// Retrieve the standard (deprecated) device_type <string> property.
+    /// Returns the standard (deprecated) device_type <string> property.
     pub fn device_type(&self) -> Result<Option<&CStr>> {
         self.getprop_str(CStr::from_bytes_with_nul(b"device_type\0").unwrap())
     }
 
-    /// Retrieve the standard reg <prop-encoded-array> property.
+    /// Returns the standard reg <prop-encoded-array> property.
     pub fn reg(&self) -> Result<Option<RegIterator<'a>>> {
         let reg = CStr::from_bytes_with_nul(b"reg\0").unwrap();
 
@@ -235,7 +235,7 @@
         }
     }
 
-    /// Retrieves the standard ranges property.
+    /// Returns the standard ranges property.
     pub fn ranges<A, P, S>(&self) -> Result<Option<RangesIterator<'a, A, P, S>>> {
         let ranges = CStr::from_bytes_with_nul(b"ranges\0").unwrap();
         if let Some(cells) = self.getprop_cells(ranges)? {
@@ -266,7 +266,7 @@
         CStr::from_bytes_with_nul(name).map_err(|_| FdtError::Internal)
     }
 
-    /// Retrieve the value of a given <string> property.
+    /// Returns the value of a given <string> property.
     pub fn getprop_str(&self, name: &CStr) -> Result<Option<&CStr>> {
         let value = if let Some(bytes) = self.getprop(name)? {
             Some(CStr::from_bytes_with_nul(bytes).map_err(|_| FdtError::BadValue)?)
@@ -276,7 +276,7 @@
         Ok(value)
     }
 
-    /// Retrieve the value of a given property as an array of cells.
+    /// Returns the value of a given property as an array of cells.
     pub fn getprop_cells(&self, name: &CStr) -> Result<Option<CellIterator<'a>>> {
         if let Some(cells) = self.getprop(name)? {
             Ok(Some(CellIterator::new(cells)))
@@ -285,7 +285,7 @@
         }
     }
 
-    /// Retrieve the value of a given <u32> property.
+    /// Returns the value of a given <u32> property.
     pub fn getprop_u32(&self, name: &CStr) -> Result<Option<u32>> {
         let value = if let Some(bytes) = self.getprop(name)? {
             Some(u32::from_be_bytes(bytes.try_into().map_err(|_| FdtError::BadValue)?))
@@ -295,7 +295,7 @@
         Ok(value)
     }
 
-    /// Retrieve the value of a given <u64> property.
+    /// Returns the value of a given <u64> property.
     pub fn getprop_u64(&self, name: &CStr) -> Result<Option<u64>> {
         let value = if let Some(bytes) = self.getprop(name)? {
             Some(u64::from_be_bytes(bytes.try_into().map_err(|_| FdtError::BadValue)?))
@@ -305,7 +305,7 @@
         Ok(value)
     }
 
-    /// Retrieve the value of a given property.
+    /// Returns the value of a given property.
     pub fn getprop(&self, name: &CStr) -> Result<Option<&'a [u8]>> {
         if let Some((prop, len)) = Self::getprop_internal(self.fdt, self.offset, name)? {
             Ok(Some(self.fdt.get_from_ptr(prop, len)?))
@@ -314,7 +314,7 @@
         }
     }
 
-    /// Return the pointer and size of the property named `name`, in a node at offset `offset`, in
+    /// Returns the pointer and size of the property named `name`, in a node at offset `offset`, in
     /// a device tree `fdt`. The pointer is guaranteed to be non-null, in which case error returns.
     fn getprop_internal(
         fdt: &'a Fdt,
@@ -347,7 +347,7 @@
         Ok(Some((prop.cast::<c_void>(), len)))
     }
 
-    /// Get reference to the containing device tree.
+    /// Returns reference to the containing device tree.
     pub fn fdt(&self) -> &Fdt {
         self.fdt
     }
@@ -412,7 +412,7 @@
 }
 
 impl<'a> FdtNodeMut<'a> {
-    /// Append a property name-value (possibly empty) pair to the given node.
+    /// Appends a property name-value (possibly empty) pair to the given node.
     pub fn appendprop<T: AsRef<[u8]>>(&mut self, name: &CStr, value: &T) -> Result<()> {
         // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor).
         let ret = unsafe {
@@ -428,7 +428,7 @@
         fdt_err_expect_zero(ret)
     }
 
-    /// Append a (address, size) pair property to the given node.
+    /// Appends a (address, size) pair property to the given node.
     pub fn appendprop_addrrange(&mut self, name: &CStr, addr: u64, size: u64) -> Result<()> {
         // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor).
         let ret = unsafe {
@@ -445,7 +445,9 @@
         fdt_err_expect_zero(ret)
     }
 
-    /// Create or change a property name-value pair to the given node.
+    /// Sets a property name-value pair to the given node.
+    ///
+    /// This may create a new prop or replace existing value.
     pub fn setprop(&mut self, name: &CStr, value: &[u8]) -> Result<()> {
         // SAFETY: New value size is constrained to the DT totalsize
         //          (validated by underlying libfdt).
@@ -462,8 +464,10 @@
         fdt_err_expect_zero(ret)
     }
 
-    /// Replace the value of the given property with the given value, and ensure that the given
-    /// value has the same length as the current value length
+    /// Sets the value of the given property with the given value, and ensure that the given
+    /// value has the same length as the current value length.
+    ///
+    /// This can only be used to replace existing value.
     pub fn setprop_inplace(&mut self, name: &CStr, value: &[u8]) -> Result<()> {
         // SAFETY: fdt size is not altered
         let ret = unsafe {
@@ -479,19 +483,23 @@
         fdt_err_expect_zero(ret)
     }
 
-    /// Replace the value of the given (address, size) pair property with the given value, and
-    /// ensure that the given value has the same length as the current value length
+    /// Sets the value of the given (address, size) pair property with the given value, and
+    /// ensure that the given value has the same length as the current value length.
+    ///
+    /// This can only be used to replace existing value.
     pub fn setprop_addrrange_inplace(&mut self, name: &CStr, addr: u64, size: u64) -> Result<()> {
         let pair = [addr.to_be(), size.to_be()];
         self.setprop_inplace(name, pair.as_bytes())
     }
 
-    /// Create or change a flag-like empty property.
+    /// Sets a flag-like empty property.
+    ///
+    /// This may create a new prop or replace existing value.
     pub fn setprop_empty(&mut self, name: &CStr) -> Result<()> {
         self.setprop(name, &[])
     }
 
-    /// Delete the given property.
+    /// Deletes the given property.
     pub fn delprop(&mut self, name: &CStr) -> Result<()> {
         // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor) when the
         // library locates the node's property. Removing the property may shift the offsets of
@@ -504,7 +512,7 @@
         fdt_err_expect_zero(ret)
     }
 
-    /// Overwrite the given property with FDT_NOP, effectively removing it from the DT.
+    /// Sets the given property with FDT_NOP, effectively removing it from the DT.
     pub fn nop_property(&mut self, name: &CStr) -> Result<()> {
         // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor) when the
         // library locates the node's property.
@@ -515,7 +523,7 @@
         fdt_err_expect_zero(ret)
     }
 
-    /// Reduce the size of the given property to new_size
+    /// Trims the size of the given property to new_size.
     pub fn trimprop(&mut self, name: &CStr, new_size: usize) -> Result<()> {
         let (prop, len) =
             FdtNode::getprop_internal(self.fdt, self.offset, name)?.ok_or(FdtError::NotFound)?;
@@ -540,12 +548,12 @@
         fdt_err_expect_zero(ret)
     }
 
-    /// Get reference to the containing device tree.
+    /// Returns reference to the containing device tree.
     pub fn fdt(&mut self) -> &mut Fdt {
         self.fdt
     }
 
-    /// Add a new subnode to the given node and return it as a FdtNodeMut on success.
+    /// Adds a new subnode to the given node and return it as a FdtNodeMut on success.
     pub fn add_subnode(&'a mut self, name: &CStr) -> Result<Self> {
         // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor).
         let ret = unsafe {
@@ -562,7 +570,7 @@
         Ok(FdtNode { fdt: &*self.fdt, offset: fdt_err(ret)? })
     }
 
-    /// Returns the compatible node of the given name that is next after this node
+    /// Returns the compatible node of the given name that is next after this node.
     pub fn next_compatible(self, compatible: &CStr) -> Result<Option<Self>> {
         // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
         let ret = unsafe {
@@ -576,8 +584,8 @@
         Ok(fdt_err_or_option(ret)?.map(|offset| Self { fdt: self.fdt, offset }))
     }
 
-    /// Replace this node and its subtree with nop tags, effectively removing it from the tree, and
-    /// then return the next compatible node of the given name.
+    /// Deletes the node effectively by overwriting this node and its subtree with nop tags.
+    /// Returns the next compatible node of the given name.
     // Side note: without this, filterint out excessive compatible nodes from the DT is impossible.
     // The reason is that libfdt ensures that the node from where the search for the next
     // compatible node is started is always a valid one -- except for the special case of offset =
@@ -678,7 +686,7 @@
         unsafe { mem::transmute::<&mut [u8], &mut Self>(fdt) }
     }
 
-    /// Update this FDT from a slice containing another FDT
+    /// Updates this FDT from a slice containing another FDT.
     pub fn copy_from_slice(&mut self, new_fdt: &[u8]) -> Result<()> {
         if self.buffer.len() < new_fdt.len() {
             Err(FdtError::NoSpace)
@@ -693,7 +701,7 @@
         }
     }
 
-    /// Make the whole slice containing the DT available to libfdt.
+    /// Unpacks the DT to cover the whole slice it is contained in.
     pub fn unpack(&mut self) -> Result<()> {
         // SAFETY: "Opens" the DT in-place (supported use-case) by updating its header and
         // internal structures to make use of the whole self.fdt slice but performs no accesses
@@ -708,7 +716,7 @@
         fdt_err_expect_zero(ret)
     }
 
-    /// Pack the DT to take a minimum amount of memory.
+    /// Packs the DT to take a minimum amount of memory.
     ///
     /// Doesn't shrink the underlying memory slice.
     pub fn pack(&mut self) -> Result<()> {
@@ -752,22 +760,22 @@
         self.memory()?.next().ok_or(FdtError::NotFound)
     }
 
-    /// Retrieve the standard /chosen node.
+    /// Returns the standard /chosen node.
     pub fn chosen(&self) -> Result<Option<FdtNode>> {
         self.node(CStr::from_bytes_with_nul(b"/chosen\0").unwrap())
     }
 
-    /// Retrieve the standard /chosen node as mutable.
+    /// Returns the standard /chosen node as mutable.
     pub fn chosen_mut(&mut self) -> Result<Option<FdtNodeMut>> {
         self.node_mut(CStr::from_bytes_with_nul(b"/chosen\0").unwrap())
     }
 
-    /// Get the root node of the tree.
+    /// Returns the root node of the tree.
     pub fn root(&self) -> Result<FdtNode> {
         self.node(CStr::from_bytes_with_nul(b"/\0").unwrap())?.ok_or(FdtError::Internal)
     }
 
-    /// Find a tree node by its full path.
+    /// Returns a tree node by its full path.
     pub fn node(&self, path: &CStr) -> Result<Option<FdtNode>> {
         Ok(self.path_offset(path)?.map(|offset| FdtNode { fdt: self, offset }))
     }
@@ -777,17 +785,17 @@
         CompatibleIterator::new(self, compatible)
     }
 
-    /// Get the mutable root node of the tree.
+    /// Returns the mutable root node of the tree.
     pub fn root_mut(&mut self) -> Result<FdtNodeMut> {
         self.node_mut(CStr::from_bytes_with_nul(b"/\0").unwrap())?.ok_or(FdtError::Internal)
     }
 
-    /// Find a mutable tree node by its full path.
+    /// Returns a mutable tree node by its full path.
     pub fn node_mut(&mut self, path: &CStr) -> Result<Option<FdtNodeMut>> {
         Ok(self.path_offset(path)?.map(|offset| FdtNodeMut { fdt: self, offset }))
     }
 
-    /// Return the device tree as a slice (may be smaller than the containing buffer).
+    /// Returns the device tree as a slice (may be smaller than the containing buffer).
     pub fn as_slice(&self) -> &[u8] {
         &self.buffer[..self.totalsize()]
     }
@@ -820,7 +828,7 @@
         self.buffer.get(offset..(offset + len)).ok_or(FdtError::Internal)
     }
 
-    /// Return a shared pointer to the device tree.
+    /// Returns a shared pointer to the device tree.
     pub fn as_ptr(&self) -> *const c_void {
         self.buffer.as_ptr().cast::<_>()
     }
diff --git a/tests/benchmark/Android.bp b/tests/benchmark/Android.bp
index 80fdff7..657241c 100644
--- a/tests/benchmark/Android.bp
+++ b/tests/benchmark/Android.bp
@@ -14,7 +14,7 @@
         "androidx.test.runner",
         "androidx.test.ext.junit",
         "com.android.microdroid.testservice-java",
-        "truth-prebuilt",
+        "truth",
     ],
     jni_libs: [
         "MicrodroidBenchmarkNativeLib",
diff --git a/tests/helper/Android.bp b/tests/helper/Android.bp
index 6f07efd..614c70c 100644
--- a/tests/helper/Android.bp
+++ b/tests/helper/Android.bp
@@ -17,7 +17,7 @@
         "androidx.test.ext.junit",
         "com.android.microdroid.testservice-java",
         "MicrodroidTestHelper",
-        "truth-prebuilt",
+        "truth",
     ],
     sdk_version: "test_current",
 }
diff --git a/tests/hostside/helper/Android.bp b/tests/hostside/helper/Android.bp
index e8b6f36..75553d0 100644
--- a/tests/hostside/helper/Android.bp
+++ b/tests/hostside/helper/Android.bp
@@ -9,7 +9,7 @@
         "androidx.annotation_annotation",
         "compatibility-tradefed",
         "tradefed",
-        "truth-prebuilt",
+        "truth",
     ],
     static_libs: [
         "MicrodroidTestHelper",
diff --git a/tests/no_avf/Android.bp b/tests/no_avf/Android.bp
index bece2ea..22d099e 100644
--- a/tests/no_avf/Android.bp
+++ b/tests/no_avf/Android.bp
@@ -13,7 +13,7 @@
         "androidx.test.runner",
         "androidx.test.ext.junit",
         "compatibility-common-util-devicesidelib",
-        "truth-prebuilt",
+        "truth",
     ],
     sdk_version: "test_current",
     compile_multilib: "both",
diff --git a/tests/pvmfw/Android.bp b/tests/pvmfw/Android.bp
index 474c62e..c12f67a 100644
--- a/tests/pvmfw/Android.bp
+++ b/tests/pvmfw/Android.bp
@@ -2,36 +2,30 @@
     default_applicable_licenses: ["Android-Apache-2.0"],
 }
 
-genrule_defaults {
-    name: "test_avf_dts_to_dtb",
-    tools: ["dtc"],
-    cmd: "$(location dtc) -I dts -O dtb $(in) -o $(out)",
-}
-
 genrule {
     name: "test_avf_debug_policy_with_ramdump",
-    defaults: ["test_avf_dts_to_dtb"],
+    defaults: ["dts_to_dtb"],
     srcs: ["assets/avf_debug_policy_with_ramdump.dts"],
     out: ["avf_debug_policy_with_ramdump.dtbo"],
 }
 
 genrule {
     name: "test_avf_debug_policy_without_ramdump",
-    defaults: ["test_avf_dts_to_dtb"],
+    defaults: ["dts_to_dtb"],
     srcs: ["assets/avf_debug_policy_without_ramdump.dts"],
     out: ["avf_debug_policy_without_ramdump.dtbo"],
 }
 
 genrule {
     name: "test_avf_debug_policy_with_adb",
-    defaults: ["test_avf_dts_to_dtb"],
+    defaults: ["dts_to_dtb"],
     srcs: ["assets/avf_debug_policy_with_adb.dts"],
     out: ["avf_debug_policy_with_adb.dtbo"],
 }
 
 genrule {
     name: "test_avf_debug_policy_without_adb",
-    defaults: ["test_avf_dts_to_dtb"],
+    defaults: ["dts_to_dtb"],
     srcs: ["assets/avf_debug_policy_without_adb.dts"],
     out: ["avf_debug_policy_without_adb.dtbo"],
 }
diff --git a/tests/testapk/Android.bp b/tests/testapk/Android.bp
index 526f240..6e8216f 100644
--- a/tests/testapk/Android.bp
+++ b/tests/testapk/Android.bp
@@ -41,7 +41,7 @@
         "androidx.test.ext.junit",
         "authfs_test_apk_assets",
         "cbor-java",
-        "truth-prebuilt",
+        "truth",
         "compatibility-common-util-devicesidelib",
         "measure_io_as_jar",
     ],