Merge "releasetools: Use "ota-downgrade=yes" for --override_timestamp."
This commit is contained in:
@@ -24,12 +24,12 @@ Common options that apply to both of non-A/B and A/B OTAs
|
|||||||
|
|
||||||
--downgrade
|
--downgrade
|
||||||
Intentionally generate an incremental OTA that updates from a newer build
|
Intentionally generate an incremental OTA that updates from a newer build
|
||||||
to an older one (based on timestamp comparison). "post-timestamp" will be
|
to an older one (e.g. downgrading from P preview back to O MR1).
|
||||||
replaced by "ota-downgrade=yes" in the metadata file. A data wipe will
|
"ota-downgrade=yes" will be set in the package metadata file. A data wipe
|
||||||
always be enforced, so "ota-wipe=yes" will also be included in the
|
will always be enforced when using this flag, so "ota-wipe=yes" will also
|
||||||
metadata file. The update-binary in the source build will be used in the
|
be included in the metadata file. The update-binary in the source build
|
||||||
OTA package, unless --binary flag is specified. Please also check the doc
|
will be used in the OTA package, unless --binary flag is specified. Please
|
||||||
for --override_timestamp below.
|
also check the comment for --override_timestamp below.
|
||||||
|
|
||||||
-i (--incremental_from) <file>
|
-i (--incremental_from) <file>
|
||||||
Generate an incremental OTA using the given target-files zip as the
|
Generate an incremental OTA using the given target-files zip as the
|
||||||
@@ -46,14 +46,19 @@ Common options that apply to both of non-A/B and A/B OTAs
|
|||||||
|
|
||||||
--override_timestamp
|
--override_timestamp
|
||||||
Intentionally generate an incremental OTA that updates from a newer build
|
Intentionally generate an incremental OTA that updates from a newer build
|
||||||
to an older one (based on timestamp comparison), by overriding the
|
to an older one (based on timestamp comparison), by setting the downgrade
|
||||||
timestamp in package metadata. This differs from --downgrade flag: we know
|
flag in the package metadata. This differs from --downgrade flag, as we
|
||||||
for sure this is NOT an actual downgrade case, but two builds are cut in a
|
don't enforce a data wipe with this flag. Because we know for sure this is
|
||||||
reverse order. A legit use case is that we cut a new build C (after having
|
NOT an actual downgrade case, but two builds happen to be cut in a reverse
|
||||||
A and B), but want to enfore an update path of A -> C -> B. Specifying
|
order (e.g. from two branches). A legit use case is that we cut a new
|
||||||
--downgrade may not help since that would enforce a data wipe for C -> B
|
build C (after having A and B), but want to enfore an update path of A ->
|
||||||
update. The value of "post-timestamp" will be set to the newer timestamp
|
C -> B. Specifying --downgrade may not help since that would enforce a
|
||||||
plus one, so that the package can be pushed and applied.
|
data wipe for C -> B update.
|
||||||
|
|
||||||
|
We used to set a fake timestamp in the package metadata for this flow. But
|
||||||
|
now we consolidate the two cases (i.e. an actual downgrade, or a downgrade
|
||||||
|
based on timestamp) with the same "ota-downgrade=yes" flag, with the
|
||||||
|
difference being whether "ota-wipe=yes" is set.
|
||||||
|
|
||||||
--wipe_user_data
|
--wipe_user_data
|
||||||
Generate an OTA package that will wipe the user data partition when
|
Generate an OTA package that will wipe the user data partition when
|
||||||
@@ -184,7 +189,6 @@ OPTIONS.verify = False
|
|||||||
OPTIONS.patch_threshold = 0.95
|
OPTIONS.patch_threshold = 0.95
|
||||||
OPTIONS.wipe_user_data = False
|
OPTIONS.wipe_user_data = False
|
||||||
OPTIONS.downgrade = False
|
OPTIONS.downgrade = False
|
||||||
OPTIONS.timestamp = False
|
|
||||||
OPTIONS.extra_script = None
|
OPTIONS.extra_script = None
|
||||||
OPTIONS.worker_threads = multiprocessing.cpu_count() // 2
|
OPTIONS.worker_threads = multiprocessing.cpu_count() // 2
|
||||||
if OPTIONS.worker_threads == 0:
|
if OPTIONS.worker_threads == 0:
|
||||||
@@ -902,23 +906,16 @@ def HandleDowngradeMetadata(metadata, target_info, source_info):
|
|||||||
|
|
||||||
if OPTIONS.downgrade:
|
if OPTIONS.downgrade:
|
||||||
if not is_downgrade:
|
if not is_downgrade:
|
||||||
raise RuntimeError("--downgrade specified but no downgrade detected: "
|
raise RuntimeError(
|
||||||
"pre: %s, post: %s" % (pre_timestamp, post_timestamp))
|
"--downgrade or --override_timestamp specified but no downgrade "
|
||||||
|
"detected: pre: %s, post: %s" % (pre_timestamp, post_timestamp))
|
||||||
metadata["ota-downgrade"] = "yes"
|
metadata["ota-downgrade"] = "yes"
|
||||||
elif OPTIONS.timestamp:
|
|
||||||
if not is_downgrade:
|
|
||||||
raise RuntimeError("--override_timestamp specified but no timestamp hack "
|
|
||||||
"needed: pre: %s, post: %s" % (pre_timestamp,
|
|
||||||
post_timestamp))
|
|
||||||
metadata["post-timestamp"] = str(long(pre_timestamp) + 1)
|
|
||||||
else:
|
else:
|
||||||
if is_downgrade:
|
if is_downgrade:
|
||||||
raise RuntimeError("Downgrade detected based on timestamp check: "
|
raise RuntimeError(
|
||||||
"pre: %s, post: %s. Need to specify "
|
"Downgrade detected based on timestamp check: pre: %s, post: %s. "
|
||||||
"--override_timestamp OR --downgrade to allow "
|
"Need to specify --override_timestamp OR --downgrade to allow "
|
||||||
"building the incremental." % (pre_timestamp,
|
"building the incremental." % (pre_timestamp, post_timestamp))
|
||||||
post_timestamp))
|
|
||||||
metadata["post-timestamp"] = post_timestamp
|
|
||||||
|
|
||||||
|
|
||||||
def GetPackageMetadata(target_info, source_info=None):
|
def GetPackageMetadata(target_info, source_info=None):
|
||||||
@@ -926,7 +923,7 @@ def GetPackageMetadata(target_info, source_info=None):
|
|||||||
|
|
||||||
It generates a dict() that contains the info to be written into an OTA
|
It generates a dict() that contains the info to be written into an OTA
|
||||||
package (META-INF/com/android/metadata). It also handles the detection of
|
package (META-INF/com/android/metadata). It also handles the detection of
|
||||||
downgrade / timestamp override / data wipe based on the global options.
|
downgrade / data wipe based on the global options.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
target_info: The BuildInfo instance that holds the target build info.
|
target_info: The BuildInfo instance that holds the target build info.
|
||||||
@@ -967,11 +964,12 @@ def GetPackageMetadata(target_info, source_info=None):
|
|||||||
else:
|
else:
|
||||||
metadata['pre-device'] = target_info.device
|
metadata['pre-device'] = target_info.device
|
||||||
|
|
||||||
# Detect downgrades, or fill in the post-timestamp.
|
# Use the actual post-timestamp, even for a downgrade case.
|
||||||
|
metadata['post-timestamp'] = target_info.GetBuildProp('ro.build.date.utc')
|
||||||
|
|
||||||
|
# Detect downgrades and set up downgrade flags accordingly.
|
||||||
if is_incremental:
|
if is_incremental:
|
||||||
HandleDowngradeMetadata(metadata, target_info, source_info)
|
HandleDowngradeMetadata(metadata, target_info, source_info)
|
||||||
else:
|
|
||||||
metadata['post-timestamp'] = target_info.GetBuildProp('ro.build.date.utc')
|
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
@@ -1796,7 +1794,7 @@ def main(argv):
|
|||||||
OPTIONS.downgrade = True
|
OPTIONS.downgrade = True
|
||||||
OPTIONS.wipe_user_data = True
|
OPTIONS.wipe_user_data = True
|
||||||
elif o == "--override_timestamp":
|
elif o == "--override_timestamp":
|
||||||
OPTIONS.timestamp = True
|
OPTIONS.downgrade = True
|
||||||
elif o in ("-o", "--oem_settings"):
|
elif o in ("-o", "--oem_settings"):
|
||||||
OPTIONS.oem_source = a.split(',')
|
OPTIONS.oem_source = a.split(',')
|
||||||
elif o == "--oem_no_mount":
|
elif o == "--oem_no_mount":
|
||||||
@@ -1874,19 +1872,12 @@ def main(argv):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if OPTIONS.downgrade:
|
if OPTIONS.downgrade:
|
||||||
# Sanity check to enforce a data wipe.
|
|
||||||
if not OPTIONS.wipe_user_data:
|
|
||||||
raise ValueError("Cannot downgrade without a data wipe")
|
|
||||||
|
|
||||||
# We should only allow downgrading incrementals (as opposed to full).
|
# We should only allow downgrading incrementals (as opposed to full).
|
||||||
# Otherwise the device may go back from arbitrary build with this full
|
# Otherwise the device may go back from arbitrary build with this full
|
||||||
# OTA package.
|
# OTA package.
|
||||||
if OPTIONS.incremental_source is None:
|
if OPTIONS.incremental_source is None:
|
||||||
raise ValueError("Cannot generate downgradable full OTAs")
|
raise ValueError("Cannot generate downgradable full OTAs")
|
||||||
|
|
||||||
assert not (OPTIONS.downgrade and OPTIONS.timestamp), \
|
|
||||||
"Cannot have --downgrade AND --override_timestamp both"
|
|
||||||
|
|
||||||
# Load the build info dicts from the zip directly or the extracted input
|
# Load the build info dicts from the zip directly or the extracted input
|
||||||
# directory. We don't need to unzip the entire target-files zips, because they
|
# directory. We don't need to unzip the entire target-files zips, because they
|
||||||
# won't be needed for A/B OTAs (brillo_update_payload does that on its own).
|
# won't be needed for A/B OTAs (brillo_update_payload does that on its own).
|
||||||
|
@@ -532,31 +532,7 @@ class OtaFromTargetFilesTest(unittest.TestCase):
|
|||||||
'post-build-incremental' : 'build-version-incremental-target',
|
'post-build-incremental' : 'build-version-incremental-target',
|
||||||
'post-sdk-level' : '27',
|
'post-sdk-level' : '27',
|
||||||
'post-security-patch-level' : '2017-12-01',
|
'post-security-patch-level' : '2017-12-01',
|
||||||
'pre-device' : 'product-device',
|
'post-timestamp' : '1400000000',
|
||||||
'pre-build' : 'build-fingerprint-source',
|
|
||||||
'pre-build-incremental' : 'build-version-incremental-source',
|
|
||||||
},
|
|
||||||
metadata)
|
|
||||||
|
|
||||||
def test_GetPackageMetadata_overrideTimestamp(self):
|
|
||||||
target_info_dict = copy.deepcopy(self.TEST_TARGET_INFO_DICT)
|
|
||||||
source_info_dict = copy.deepcopy(self.TEST_SOURCE_INFO_DICT)
|
|
||||||
self._test_GetPackageMetadata_swapBuildTimestamps(
|
|
||||||
target_info_dict, source_info_dict)
|
|
||||||
|
|
||||||
target_info = BuildInfo(target_info_dict, None)
|
|
||||||
source_info = BuildInfo(source_info_dict, None)
|
|
||||||
common.OPTIONS.incremental_source = ''
|
|
||||||
common.OPTIONS.timestamp = True
|
|
||||||
metadata = GetPackageMetadata(target_info, source_info)
|
|
||||||
self.assertDictEqual(
|
|
||||||
{
|
|
||||||
'ota-type' : 'BLOCK',
|
|
||||||
'post-build' : 'build-fingerprint-target',
|
|
||||||
'post-build-incremental' : 'build-version-incremental-target',
|
|
||||||
'post-sdk-level' : '27',
|
|
||||||
'post-security-patch-level' : '2017-12-01',
|
|
||||||
'post-timestamp' : '1500000001',
|
|
||||||
'pre-device' : 'product-device',
|
'pre-device' : 'product-device',
|
||||||
'pre-build' : 'build-fingerprint-source',
|
'pre-build' : 'build-fingerprint-source',
|
||||||
'pre-build-incremental' : 'build-version-incremental-source',
|
'pre-build-incremental' : 'build-version-incremental-source',
|
||||||
|
Reference in New Issue
Block a user