releasetools: Handle two edge cases in FinalizeMetadata().
In FinalizeMetadata and PropertyFiles, we need to reserve space between
the calls to Compute() and Finalize(). We used to put a 10-byte
placeholder, in the hope of covering the 'offset:length' space for the
metadata entry, as well as the possible value changes in other entries.
However, this could fail in two possible cases: (a) metadata entry
itself has a large offset (e.g. staying near the end of a 1-GiB package,
where the offset itself has 10-digit); or (b) the offsets for other
entries change substantially due to entry reordering. Note that for case
(b), it's space inefficient to always reserve 15-byte for _each_ token
in the property-files.
This CL handles both of these two cases. For (a), we bump up the 10-byte
to 15-byte, which is large enough to cover a package size up to 10-digit
number (i.e. ~9GiB) with a metadata entry size of 4-digit. All these
15-byte will be used for the metadata token alone.
For (b), we add a fallback flow that would retry one more time, but
based on the already signed package that has entries in desired order.
Bug: 74210298
Test: python -m unittest test_ota_from_target_files
Test: Generate aosp-bullhead full OTA with '--no_signing' flag.
Change-Id: If20487602d2ad09b3797465c01972f2fa792a1f1
diff --git a/tools/releasetools/test_utils.py b/tools/releasetools/test_utils.py
index e64355b..a15ff5b 100644
--- a/tools/releasetools/test_utils.py
+++ b/tools/releasetools/test_utils.py
@@ -32,6 +32,22 @@
return os.path.join(current_dir, 'testdata')
+def get_search_path():
+ """Returns the search path that has 'framework/signapk.jar' under."""
+ current_dir = os.path.dirname(os.path.realpath(__file__))
+ for path in (
+ # In relative to 'build/make/tools/releasetools' in the Android source.
+ ['..'] * 4 + ['out', 'host', 'linux-x86'],
+ # Or running the script unpacked from otatools.zip.
+ ['..']):
+ full_path = os.path.realpath(os.path.join(current_dir, *path))
+ signapk_path = os.path.realpath(
+ os.path.join(full_path, 'framework', 'signapk.jar'))
+ if os.path.exists(signapk_path):
+ return full_path
+ return None
+
+
def construct_sparse_image(chunks):
"""Returns a sparse image file constructed from the given chunks.