Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 05ff7055 authored by Kelvin Zhang's avatar Kelvin Zhang
Browse files

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
parent 3f631cf2
Loading
Loading
Loading
Loading
+10 −4
Original line number Original line Diff line number Diff line
@@ -230,7 +230,7 @@ import zipfile
import common
import common
import ota_utils
import ota_utils
from ota_utils import (UNZIP_PATTERN, FinalizeMetadata, GetPackageMetadata,
from ota_utils import (UNZIP_PATTERN, FinalizeMetadata, GetPackageMetadata,
                       PropertyFiles)
                       PropertyFiles, SECURITY_PATCH_LEVEL_PROP_NAME)
import target_files_diff
import target_files_diff
from check_target_files_vintf import CheckVintfIfTrebleEnabled
from check_target_files_vintf import CheckVintfIfTrebleEnabled
from non_ab_ota import GenerateNonAbOtaPackage
from non_ab_ota import GenerateNonAbOtaPackage
@@ -292,7 +292,7 @@ SECONDARY_PAYLOAD_SKIPPED_IMAGES = [
    'system_ext', 'vbmeta', 'vbmeta_system', 'vbmeta_vendor', 'vendor',
    'system_ext', 'vbmeta', 'vbmeta_system', 'vbmeta_vendor', 'vendor',
    'vendor_boot']
    'vendor_boot']


SECURITY_PATCH_LEVEL_PROP_NAME = "ro.build.version.security_patch"





class PayloadSigner(object):
class PayloadSigner(object):
@@ -1418,14 +1418,20 @@ def main(argv):
    target_build_prop = OPTIONS.target_info_dict["build.prop"]
    target_build_prop = OPTIONS.target_info_dict["build.prop"]
    source_spl = source_build_prop.GetProp(SECURITY_PATCH_LEVEL_PROP_NAME)
    source_spl = source_build_prop.GetProp(SECURITY_PATCH_LEVEL_PROP_NAME)
    target_spl = target_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(
      raise common.ExternalError(
        "Target security patch level {} is older than source SPL {} applying "
        "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 "
        "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 "
        "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 "
        "separators other than -, so as long as it's used consistenly across "
        "all SPL dates".format(target_spl, source_spl))
        "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:
  if generate_ab:
    GenerateAbOtaPackage(
    GenerateAbOtaPackage(
        target_file=args[0],
        target_file=args[0],
+3 −0
Original line number Original line Diff line number Diff line
@@ -105,4 +105,7 @@ message OtaMetadata {
  bool retrofit_dynamic_partitions = 7;
  bool retrofit_dynamic_partitions = 7;
  // The required size of the cache partition, only valid for non-A/B update.
  // The required size of the cache partition, only valid for non-A/B update.
  int64 required_cache = 8;
  int64 required_cache = 8;

  // True iff security patch level downgrade is permitted on this OTA.
  bool spl_downgrade = 9;
}
}
+53 −64

File changed.

Preview size limit exceeded, changes collapsed.

+8 −1
Original line number Original line Diff line number Diff line
@@ -39,6 +39,8 @@ OPTIONS.boot_variable_file = None
METADATA_NAME = 'META-INF/com/android/metadata'
METADATA_NAME = 'META-INF/com/android/metadata'
METADATA_PROTO_NAME = 'META-INF/com/android/metadata.pb'
METADATA_PROTO_NAME = 'META-INF/com/android/metadata.pb'
UNZIP_PATTERN = ['IMAGES/*', 'META/*', 'OTA/*', 'RADIO/*']
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):
def FinalizeMetadata(metadata, input_file, output_file, needed_property_files):
  """Finalizes the metadata and signs an A/B OTA package.
  """Finalizes the metadata and signs an A/B OTA package.
@@ -317,6 +319,8 @@ def BuildLegacyOtaMetadata(metadata_proto):
    metadata_dict['pre-build'] = separator.join(pre_build.build)
    metadata_dict['pre-build'] = separator.join(pre_build.build)
    metadata_dict['pre-build-incremental'] = pre_build.build_incremental
    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)
  metadata_dict.update(metadata_proto.property_files)


  return metadata_dict
  return metadata_dict
@@ -330,6 +334,9 @@ def HandleDowngradeMetadata(metadata_proto, target_info, source_info):
  pre_timestamp = source_info.GetBuildProp("ro.build.date.utc")
  pre_timestamp = source_info.GetBuildProp("ro.build.date.utc")
  is_downgrade = int(post_timestamp) < int(pre_timestamp)
  is_downgrade = int(post_timestamp) < int(pre_timestamp)


  if OPTIONS.spl_downgrade:
    metadata_proto.spl_downgrade = True

  if OPTIONS.downgrade:
  if OPTIONS.downgrade:
    if not is_downgrade:
    if not is_downgrade:
      raise RuntimeError(
      raise RuntimeError(
+6 −2

File changed.

Preview size limit exceeded, changes collapsed.