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

Commit 201cb593 authored by Kelvin Zhang's avatar Kelvin Zhang
Browse files

Check device's launch API level before using new compresison algo

If a T launch device later changes to LZ4(which is supported since U),
we will fallback to older compression algorithms, because if the full
OTA is applied on an T build, the update_engine on device won't support
lz4.

Bug: 295989519
Bug: 291594891
Test: generate full OTA for T launched devices, make sure lz4 is not
used
(cherry picked from https://android-review.googlesource.com/q/commit:8f830007321ef0cbabd5f581da5a6429843ff399)

Merged-In: I82fdf788e47e2a6daeaa4479bfecf317d8ebb5d5
Change-Id: I82fdf788e47e2a6daeaa4479bfecf317d8ebb5d5
parent 421f5836
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -461,6 +461,10 @@ class BuildInfo(object):
    system_prop = self.info_dict.get("system.build.prop")
    return system_prop and system_prop.GetProp("ro.build.version.release") == "11"

  @property
  def vabc_compression_param(self):
    return self.get("virtual_ab_compression_method", "")

  @property
  def vendor_api_level(self):
    vendor_prop = self.info_dict.get("vendor.build.prop")
+21 −1
Original line number Diff line number Diff line
@@ -270,7 +270,7 @@ import care_map_pb2
import common
import ota_utils
from ota_utils import (UNZIP_PATTERN, FinalizeMetadata, GetPackageMetadata,
                       PayloadGenerator, SECURITY_PATCH_LEVEL_PROP_NAME, CopyTargetFilesDir)
                       PayloadGenerator, SECURITY_PATCH_LEVEL_PROP_NAME, CopyTargetFilesDir, VABC_COMPRESSION_PARAM_SUPPORT)
from common import DoesInputFileContain, IsSparseImage
import target_files_diff
from check_target_files_vintf import CheckVintfIfTrebleEnabled
@@ -865,6 +865,10 @@ def GenerateAbOtaPackage(target_file, output_file, source_file=None):
    if not source_info.is_vabc or not target_info.is_vabc:
      logger.info("Either source or target does not support VABC, disabling.")
      OPTIONS.disable_vabc = True
    if source_info.vabc_compression_param != target_info.vabc_compression_param:
      logger.info("Source build and target build use different compression methods {} vs {}, default to source builds parameter {}".format(
          source_info.vabc_compression_param, target_info.vabc_compression_param, source_info.vabc_compression_param))
      OPTIONS.vabc_compression_param = source_info.vabc_compression_param

    # Virtual AB Compression was introduced in Androd S.
    # Later, we backported VABC to Android R. But verity support was not
@@ -879,6 +883,22 @@ def GenerateAbOtaPackage(target_file, output_file, source_file=None):
        "META/ab_partitions.txt is required for ab_update."
    target_info = common.BuildInfo(OPTIONS.info_dict, OPTIONS.oem_dicts)
    source_info = None
    if target_info.vabc_compression_param:
      minimum_api_level_required = VABC_COMPRESSION_PARAM_SUPPORT[
          target_info.vabc_compression_param]
      if target_info.vendor_api_level < minimum_api_level_required:
        logger.warning(
            "This full OTA is configured to use VABC compression algorithm"
            " {}, which is supported since"
            " Android API level {}, but device is "
            "launched with {} . If this full OTA is"
            " served to a device running old build, OTA might fail due to "
            "unsupported compression parameter. For safety, gz is used because "
            "it's supported since day 1.".format(
                target_info.vabc_compression_param,
                minimum_api_level_required,
                target_info.vendor_api_level))
        OPTIONS.vabc_compression_param = "gz"

  if OPTIONS.partial == []:
    logger.info(
+13 −0
Original line number Diff line number Diff line
@@ -50,6 +50,19 @@ UNZIP_PATTERN = ['IMAGES/*', 'META/*', 'OTA/*',
SECURITY_PATCH_LEVEL_PROP_NAME = "ro.build.version.security_patch"


# Key is the compression algorithm, value is minimum API level required to
# use this compression algorithm for VABC OTA on device.
VABC_COMPRESSION_PARAM_SUPPORT = {
    "gz": 31,
    "brotli": 31,
    "none": 31,
    # lz4 support is added in Android U
    "lz4": 34,
    # zstd support is added in Android V
    "zstd": 35,
}


def FinalizeMetadata(metadata, input_file, output_file, needed_property_files=None, package_key=None, pw=None):
  """Finalizes the metadata and signs an A/B OTA package.