From 05ff7055b6d1a62cad87f179f605f624ce2b2c63 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Wed, 10 Feb 2021 09:13:26 -0500 Subject: [PATCH] Add spl-downgrade field to ota metadata In aosp/1581143 , we banned generation of SPL downgrade OTAs. However, caller of OTA script can still force an SPL downgrade OTA by passing --spl_downgrade flag. If this flag is specified, we propagate it to OTA metadata so that GOTA server can properly honor this flag. Test: th Change-Id: Ic8cdc850d2210f4149ad9121fa4ed2e5a4f59bcc --- tools/releasetools/ota_from_target_files.py | 14 ++- tools/releasetools/ota_metadata.proto | 3 + tools/releasetools/ota_metadata_pb2.py | 117 ++++++++---------- tools/releasetools/ota_utils.py | 9 +- .../test_ota_from_target_files.py | 8 +- 5 files changed, 80 insertions(+), 71 deletions(-) diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py index 2cbaf373e2..3dcabd5f1a 100755 --- a/tools/releasetools/ota_from_target_files.py +++ b/tools/releasetools/ota_from_target_files.py @@ -230,7 +230,7 @@ import zipfile import common import ota_utils from ota_utils import (UNZIP_PATTERN, FinalizeMetadata, GetPackageMetadata, - PropertyFiles) + PropertyFiles, SECURITY_PATCH_LEVEL_PROP_NAME) import target_files_diff from check_target_files_vintf import CheckVintfIfTrebleEnabled from non_ab_ota import GenerateNonAbOtaPackage @@ -292,7 +292,7 @@ SECONDARY_PAYLOAD_SKIPPED_IMAGES = [ 'system_ext', 'vbmeta', 'vbmeta_system', 'vbmeta_vendor', 'vendor', 'vendor_boot'] -SECURITY_PATCH_LEVEL_PROP_NAME = "ro.build.version.security_patch" + class PayloadSigner(object): @@ -1418,14 +1418,20 @@ def main(argv): target_build_prop = OPTIONS.target_info_dict["build.prop"] source_spl = source_build_prop.GetProp(SECURITY_PATCH_LEVEL_PROP_NAME) target_spl = target_build_prop.GetProp(SECURITY_PATCH_LEVEL_PROP_NAME) - if target_spl < source_spl and not OPTIONS.spl_downgrade: + is_spl_downgrade = target_spl < source_spl + if is_spl_downgrade and not OPTIONS.spl_downgrade: raise common.ExternalError( "Target security patch level {} is older than source SPL {} applying " - "such OTA will likely cause device fail to boot. Pass --spl-downgrade " + "such OTA will likely cause device fail to boot. Pass --spl_downgrade " "to override this check. This script expects security patch level to " "be in format yyyy-mm-dd (e.x. 2021-02-05). It's possible to use " "separators other than -, so as long as it's used consistenly across " "all SPL dates".format(target_spl, source_spl)) + elif not is_spl_downgrade and OPTIONS.spl_downgrade: + raise ValueError("--spl_downgrade specified but no actual SPL downgrade" + " detected. Please only pass in this flag if you want a" + " SPL downgrade. Target SPL: {} Source SPL: {}" + .format(target_spl, source_spl)) if generate_ab: GenerateAbOtaPackage( target_file=args[0], diff --git a/tools/releasetools/ota_metadata.proto b/tools/releasetools/ota_metadata.proto index 5da8b844b8..7aaca6f8b1 100644 --- a/tools/releasetools/ota_metadata.proto +++ b/tools/releasetools/ota_metadata.proto @@ -105,4 +105,7 @@ message OtaMetadata { bool retrofit_dynamic_partitions = 7; // The required size of the cache partition, only valid for non-A/B update. int64 required_cache = 8; + + // True iff security patch level downgrade is permitted on this OTA. + bool spl_downgrade = 9; } diff --git a/tools/releasetools/ota_metadata_pb2.py b/tools/releasetools/ota_metadata_pb2.py index 27cc9300f9..255246434f 100644 --- a/tools/releasetools/ota_metadata_pb2.py +++ b/tools/releasetools/ota_metadata_pb2.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: ota_metadata.proto -"""Generated protocol buffer code.""" + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection @@ -17,9 +19,8 @@ DESCRIPTOR = _descriptor.FileDescriptor( name='ota_metadata.proto', package='build.tools.releasetools', syntax='proto3', - serialized_options=b'H\003', - create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\x12ota_metadata.proto\x12\x18\x62uild.tools.releasetools\"X\n\x0ePartitionState\x12\x16\n\x0epartition_name\x18\x01 \x01(\t\x12\x0e\n\x06\x64\x65vice\x18\x02 \x03(\t\x12\r\n\x05\x62uild\x18\x03 \x03(\t\x12\x0f\n\x07version\x18\x04 \x01(\t\"\xce\x01\n\x0b\x44\x65viceState\x12\x0e\n\x06\x64\x65vice\x18\x01 \x03(\t\x12\r\n\x05\x62uild\x18\x02 \x03(\t\x12\x19\n\x11\x62uild_incremental\x18\x03 \x01(\t\x12\x11\n\ttimestamp\x18\x04 \x01(\x03\x12\x11\n\tsdk_level\x18\x05 \x01(\t\x12\x1c\n\x14security_patch_level\x18\x06 \x01(\t\x12\x41\n\x0fpartition_state\x18\x07 \x03(\x0b\x32(.build.tools.releasetools.PartitionState\"c\n\x08\x41pexInfo\x12\x14\n\x0cpackage_name\x18\x01 \x01(\t\x12\x0f\n\x07version\x18\x02 \x01(\x03\x12\x15\n\ris_compressed\x18\x03 \x01(\x08\x12\x19\n\x11\x64\x65\x63ompressed_size\x18\x04 \x01(\x03\"E\n\x0c\x41pexMetadata\x12\x35\n\tapex_info\x18\x01 \x03(\x0b\x32\".build.tools.releasetools.ApexInfo\"\x98\x04\n\x0bOtaMetadata\x12;\n\x04type\x18\x01 \x01(\x0e\x32-.build.tools.releasetools.OtaMetadata.OtaType\x12\x0c\n\x04wipe\x18\x02 \x01(\x08\x12\x11\n\tdowngrade\x18\x03 \x01(\x08\x12P\n\x0eproperty_files\x18\x04 \x03(\x0b\x32\x38.build.tools.releasetools.OtaMetadata.PropertyFilesEntry\x12;\n\x0cprecondition\x18\x05 \x01(\x0b\x32%.build.tools.releasetools.DeviceState\x12<\n\rpostcondition\x18\x06 \x01(\x0b\x32%.build.tools.releasetools.DeviceState\x12#\n\x1bretrofit_dynamic_partitions\x18\x07 \x01(\x08\x12\x16\n\x0erequired_cache\x18\x08 \x01(\x03\x12\x35\n\tapex_info\x18\t \x03(\x0b\x32\".build.tools.releasetools.ApexInfo\x1a\x34\n\x12PropertyFilesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"4\n\x07OtaType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x06\n\x02\x41\x42\x10\x01\x12\t\n\x05\x42LOCK\x10\x02\x12\t\n\x05\x42RICK\x10\x03\x42\x02H\x03\x62\x06proto3' + serialized_options=_b('H\003'), + serialized_pb=_b('\n\x12ota_metadata.proto\x12\x18\x62uild.tools.releasetools\"X\n\x0ePartitionState\x12\x16\n\x0epartition_name\x18\x01 \x01(\t\x12\x0e\n\x06\x64\x65vice\x18\x02 \x03(\t\x12\r\n\x05\x62uild\x18\x03 \x03(\t\x12\x0f\n\x07version\x18\x04 \x01(\t\"\xce\x01\n\x0b\x44\x65viceState\x12\x0e\n\x06\x64\x65vice\x18\x01 \x03(\t\x12\r\n\x05\x62uild\x18\x02 \x03(\t\x12\x19\n\x11\x62uild_incremental\x18\x03 \x01(\t\x12\x11\n\ttimestamp\x18\x04 \x01(\x03\x12\x11\n\tsdk_level\x18\x05 \x01(\t\x12\x1c\n\x14security_patch_level\x18\x06 \x01(\t\x12\x41\n\x0fpartition_state\x18\x07 \x03(\x0b\x32(.build.tools.releasetools.PartitionState\"c\n\x08\x41pexInfo\x12\x14\n\x0cpackage_name\x18\x01 \x01(\t\x12\x0f\n\x07version\x18\x02 \x01(\x03\x12\x15\n\ris_compressed\x18\x03 \x01(\x08\x12\x19\n\x11\x64\x65\x63ompressed_size\x18\x04 \x01(\x03\"E\n\x0c\x41pexMetadata\x12\x35\n\tapex_info\x18\x01 \x03(\x0b\x32\".build.tools.releasetools.ApexInfo\"\xf8\x03\n\x0bOtaMetadata\x12;\n\x04type\x18\x01 \x01(\x0e\x32-.build.tools.releasetools.OtaMetadata.OtaType\x12\x0c\n\x04wipe\x18\x02 \x01(\x08\x12\x11\n\tdowngrade\x18\x03 \x01(\x08\x12P\n\x0eproperty_files\x18\x04 \x03(\x0b\x32\x38.build.tools.releasetools.OtaMetadata.PropertyFilesEntry\x12;\n\x0cprecondition\x18\x05 \x01(\x0b\x32%.build.tools.releasetools.DeviceState\x12<\n\rpostcondition\x18\x06 \x01(\x0b\x32%.build.tools.releasetools.DeviceState\x12#\n\x1bretrofit_dynamic_partitions\x18\x07 \x01(\x08\x12\x16\n\x0erequired_cache\x18\x08 \x01(\x03\x12\x15\n\rspl_downgrade\x18\t \x01(\x08\x1a\x34\n\x12PropertyFilesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"4\n\x07OtaType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x06\n\x02\x41\x42\x10\x01\x12\t\n\x05\x42LOCK\x10\x02\x12\t\n\x05\x42RICK\x10\x03\x42\x02H\x03\x62\x06proto3') ) @@ -29,33 +30,28 @@ _OTAMETADATA_OTATYPE = _descriptor.EnumDescriptor( full_name='build.tools.releasetools.OtaMetadata.OtaType', filename=None, file=DESCRIPTOR, - create_key=_descriptor._internal_create_key, values=[ _descriptor.EnumValueDescriptor( name='UNKNOWN', index=0, number=0, serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key), + type=None), _descriptor.EnumValueDescriptor( name='AB', index=1, number=1, serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key), + type=None), _descriptor.EnumValueDescriptor( name='BLOCK', index=2, number=2, serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key), + type=None), _descriptor.EnumValueDescriptor( name='BRICK', index=3, number=3, serialized_options=None, - type=None, - create_key=_descriptor._internal_create_key), + type=None), ], containing_type=None, serialized_options=None, - serialized_start=1004, - serialized_end=1056, + serialized_start=972, + serialized_end=1024, ) _sym_db.RegisterEnumDescriptor(_OTAMETADATA_OTATYPE) @@ -66,36 +62,35 @@ _PARTITIONSTATE = _descriptor.Descriptor( filename=None, file=DESCRIPTOR, containing_type=None, - create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( name='partition_name', full_name='build.tools.releasetools.PartitionState.partition_name', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=b"".decode('utf-8'), + has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='device', full_name='build.tools.releasetools.PartitionState.device', index=1, number=2, type=9, cpp_type=9, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='build', full_name='build.tools.releasetools.PartitionState.build', index=2, number=3, type=9, cpp_type=9, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='version', full_name='build.tools.releasetools.PartitionState.version', index=3, number=4, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=b"".decode('utf-8'), + has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), ], extensions=[ ], @@ -119,7 +114,6 @@ _DEVICESTATE = _descriptor.Descriptor( filename=None, file=DESCRIPTOR, containing_type=None, - create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( name='device', full_name='build.tools.releasetools.DeviceState.device', index=0, @@ -127,49 +121,49 @@ _DEVICESTATE = _descriptor.Descriptor( has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='build', full_name='build.tools.releasetools.DeviceState.build', index=1, number=2, type=9, cpp_type=9, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='build_incremental', full_name='build.tools.releasetools.DeviceState.build_incremental', index=2, number=3, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=b"".decode('utf-8'), + has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='timestamp', full_name='build.tools.releasetools.DeviceState.timestamp', index=3, number=4, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='sdk_level', full_name='build.tools.releasetools.DeviceState.sdk_level', index=4, number=5, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=b"".decode('utf-8'), + has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='security_patch_level', full_name='build.tools.releasetools.DeviceState.security_patch_level', index=5, number=6, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=b"".decode('utf-8'), + has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='partition_state', full_name='build.tools.releasetools.DeviceState.partition_state', index=6, number=7, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), ], extensions=[ ], @@ -193,36 +187,35 @@ _APEXINFO = _descriptor.Descriptor( filename=None, file=DESCRIPTOR, containing_type=None, - create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( name='package_name', full_name='build.tools.releasetools.ApexInfo.package_name', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=b"".decode('utf-8'), + has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='version', full_name='build.tools.releasetools.ApexInfo.version', index=1, number=2, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='is_compressed', full_name='build.tools.releasetools.ApexInfo.is_compressed', index=2, number=3, type=8, cpp_type=7, label=1, has_default_value=False, default_value=False, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='decompressed_size', full_name='build.tools.releasetools.ApexInfo.decompressed_size', index=3, number=4, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), ], extensions=[ ], @@ -246,7 +239,6 @@ _APEXMETADATA = _descriptor.Descriptor( filename=None, file=DESCRIPTOR, containing_type=None, - create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( name='apex_info', full_name='build.tools.releasetools.ApexMetadata.apex_info', index=0, @@ -254,7 +246,7 @@ _APEXMETADATA = _descriptor.Descriptor( has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), ], extensions=[ ], @@ -278,36 +270,35 @@ _OTAMETADATA_PROPERTYFILESENTRY = _descriptor.Descriptor( filename=None, file=DESCRIPTOR, containing_type=None, - create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( name='key', full_name='build.tools.releasetools.OtaMetadata.PropertyFilesEntry.key', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=b"".decode('utf-8'), + has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='value', full_name='build.tools.releasetools.OtaMetadata.PropertyFilesEntry.value', index=1, number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=b"".decode('utf-8'), + has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), ], extensions=[ ], nested_types=[], enum_types=[ ], - serialized_options=b'8\001', + serialized_options=_b('8\001'), is_extendable=False, syntax='proto3', extension_ranges=[], oneofs=[ ], - serialized_start=950, - serialized_end=1002, + serialized_start=918, + serialized_end=970, ) _OTAMETADATA = _descriptor.Descriptor( @@ -316,7 +307,6 @@ _OTAMETADATA = _descriptor.Descriptor( filename=None, file=DESCRIPTOR, containing_type=None, - create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( name='type', full_name='build.tools.releasetools.OtaMetadata.type', index=0, @@ -324,63 +314,63 @@ _OTAMETADATA = _descriptor.Descriptor( has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='wipe', full_name='build.tools.releasetools.OtaMetadata.wipe', index=1, number=2, type=8, cpp_type=7, label=1, has_default_value=False, default_value=False, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='downgrade', full_name='build.tools.releasetools.OtaMetadata.downgrade', index=2, number=3, type=8, cpp_type=7, label=1, has_default_value=False, default_value=False, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='property_files', full_name='build.tools.releasetools.OtaMetadata.property_files', index=3, number=4, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='precondition', full_name='build.tools.releasetools.OtaMetadata.precondition', index=4, number=5, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='postcondition', full_name='build.tools.releasetools.OtaMetadata.postcondition', index=5, number=6, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='retrofit_dynamic_partitions', full_name='build.tools.releasetools.OtaMetadata.retrofit_dynamic_partitions', index=6, number=7, type=8, cpp_type=7, label=1, has_default_value=False, default_value=False, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='required_cache', full_name='build.tools.releasetools.OtaMetadata.required_cache', index=7, number=8, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='apex_info', full_name='build.tools.releasetools.OtaMetadata.apex_info', index=8, - number=9, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], + name='spl_downgrade', full_name='build.tools.releasetools.OtaMetadata.spl_downgrade', index=8, + number=9, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + serialized_options=None, file=DESCRIPTOR), ], extensions=[ ], @@ -395,7 +385,7 @@ _OTAMETADATA = _descriptor.Descriptor( oneofs=[ ], serialized_start=520, - serialized_end=1056, + serialized_end=1024, ) _DEVICESTATE.fields_by_name['partition_state'].message_type = _PARTITIONSTATE @@ -405,7 +395,6 @@ _OTAMETADATA.fields_by_name['type'].enum_type = _OTAMETADATA_OTATYPE _OTAMETADATA.fields_by_name['property_files'].message_type = _OTAMETADATA_PROPERTYFILESENTRY _OTAMETADATA.fields_by_name['precondition'].message_type = _DEVICESTATE _OTAMETADATA.fields_by_name['postcondition'].message_type = _DEVICESTATE -_OTAMETADATA.fields_by_name['apex_info'].message_type = _APEXINFO _OTAMETADATA_OTATYPE.containing_type = _OTAMETADATA DESCRIPTOR.message_types_by_name['PartitionState'] = _PARTITIONSTATE DESCRIPTOR.message_types_by_name['DeviceState'] = _DEVICESTATE diff --git a/tools/releasetools/ota_utils.py b/tools/releasetools/ota_utils.py index 6bbcc923bb..104f02f35e 100644 --- a/tools/releasetools/ota_utils.py +++ b/tools/releasetools/ota_utils.py @@ -39,6 +39,8 @@ OPTIONS.boot_variable_file = None METADATA_NAME = 'META-INF/com/android/metadata' METADATA_PROTO_NAME = 'META-INF/com/android/metadata.pb' UNZIP_PATTERN = ['IMAGES/*', 'META/*', 'OTA/*', 'RADIO/*'] +SECURITY_PATCH_LEVEL_PROP_NAME = "ro.build.version.security_patch" + def FinalizeMetadata(metadata, input_file, output_file, needed_property_files): """Finalizes the metadata and signs an A/B OTA package. @@ -168,7 +170,7 @@ def UpdateDeviceState(device_state, build_info, boot_variable_values, build_info_set = ComputeRuntimeBuildInfos(build_info, boot_variable_values) assert "ab_partitions" in build_info.info_dict,\ - "ab_partitions property required for ab update." + "ab_partitions property required for ab update." ab_partitions = set(build_info.info_dict.get("ab_partitions")) # delta_generator will error out on unused timestamps, @@ -317,6 +319,8 @@ def BuildLegacyOtaMetadata(metadata_proto): metadata_dict['pre-build'] = separator.join(pre_build.build) metadata_dict['pre-build-incremental'] = pre_build.build_incremental + if metadata_proto.spl_downgrade: + metadata_dict['spl-downgrade'] = 'yes' metadata_dict.update(metadata_proto.property_files) return metadata_dict @@ -330,6 +334,9 @@ def HandleDowngradeMetadata(metadata_proto, target_info, source_info): pre_timestamp = source_info.GetBuildProp("ro.build.date.utc") is_downgrade = int(post_timestamp) < int(pre_timestamp) + if OPTIONS.spl_downgrade: + metadata_proto.spl_downgrade = True + if OPTIONS.downgrade: if not is_downgrade: raise RuntimeError( diff --git a/tools/releasetools/test_ota_from_target_files.py b/tools/releasetools/test_ota_from_target_files.py index 82669088e8..9f6484924f 100644 --- a/tools/releasetools/test_ota_from_target_files.py +++ b/tools/releasetools/test_ota_from_target_files.py @@ -290,11 +290,11 @@ class OtaFromTargetFilesTest(test_utils.ReleaseToolsTestCase): self.assertEqual(apex_infos[0].is_compressed, True) # Compare the decompressed APEX size with the original uncompressed APEX original_apex_name = 'com.android.apex.compressed.v1_original.apex' - original_apex_filepath = os.path.join(test_utils.get_current_dir(), original_apex_name) + original_apex_filepath = os.path.join( + test_utils.get_current_dir(), original_apex_name) uncompressed_apex_size = os.path.getsize(original_apex_filepath) self.assertEqual(apex_infos[0].decompressed_size, uncompressed_apex_size) - def test_GetPackageMetadata_retrofitDynamicPartitions(self): target_info = common.BuildInfo(self.TEST_TARGET_INFO_DICT, None) common.OPTIONS.retrofit_dynamic_partitions = True @@ -343,7 +343,10 @@ class OtaFromTargetFilesTest(test_utils.ReleaseToolsTestCase): common.OPTIONS.incremental_source = '' common.OPTIONS.downgrade = True common.OPTIONS.wipe_user_data = True + common.OPTIONS.spl_downgrade = True metadata = self.GetLegacyOtaMetadata(target_info, source_info) + # Reset spl_downgrade so other tests are unaffected + common.OPTIONS.spl_downgrade = False self.assertDictEqual( { @@ -359,6 +362,7 @@ class OtaFromTargetFilesTest(test_utils.ReleaseToolsTestCase): 'pre-device': 'product-device', 'pre-build': 'build-fingerprint-source', 'pre-build-incremental': 'build-version-incremental-source', + 'spl-downgrade': 'yes', }, metadata)