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

Commit a8d60eb0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Move more non-AB code to separate files" into main

parents 32500b00 513b86e5
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -483,8 +483,13 @@ python_binary_host {
    defaults: ["releasetools_binary_defaults"],
    srcs: [
        "make_recovery_patch.py",
        "non_ab_ota.py",
        "edify_generator.py",
        "check_target_files_vintf.py",
    ],
    libs: [
        "ota_utils_lib",
        "ota_metadata_proto",
        "releasetools_common",
    ],
}
+0 −1
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import sys
import zipfile

import common
from apex_manifest import ParseApexManifest

logger = logging.getLogger(__name__)

+1 −923

File changed.

Preview size limit exceeded, changes collapsed.

+39 −9
Original line number Diff line number Diff line
@@ -16,6 +16,36 @@ import re

import common


class ErrorCode(object):
  """Define error_codes for failures that happen during the actual
  update package installation.

  Error codes 0-999 are reserved for failures before the package
  installation (i.e. low battery, package verification failure).
  Detailed code in 'bootable/recovery/error_code.h' """

  SYSTEM_VERIFICATION_FAILURE = 1000
  SYSTEM_UPDATE_FAILURE = 1001
  SYSTEM_UNEXPECTED_CONTENTS = 1002
  SYSTEM_NONZERO_CONTENTS = 1003
  SYSTEM_RECOVER_FAILURE = 1004
  VENDOR_VERIFICATION_FAILURE = 2000
  VENDOR_UPDATE_FAILURE = 2001
  VENDOR_UNEXPECTED_CONTENTS = 2002
  VENDOR_NONZERO_CONTENTS = 2003
  VENDOR_RECOVER_FAILURE = 2004
  OEM_PROP_MISMATCH = 3000
  FINGERPRINT_MISMATCH = 3001
  THUMBPRINT_MISMATCH = 3002
  OLDER_BUILD = 3003
  DEVICE_MISMATCH = 3004
  BAD_PATCH_FILE = 3005
  INSUFFICIENT_CACHE_SPACE = 3006
  TUNE_PARTITION_FAILURE = 3007
  APPLY_PATCH_FAILURE = 3008


class EdifyGenerator(object):
  """Class to generate scripts in the 'edify' recovery script language
  used from donut onwards."""
@@ -88,7 +118,7 @@ class EdifyGenerator(object):
        'abort("E{code}: This package expects the value \\"{values}\\" for '
        '\\"{name}\\"; this has value \\"" + '
        '{get_prop_command} + "\\".");').format(
            code=common.ErrorCode.OEM_PROP_MISMATCH,
            code=ErrorCode.OEM_PROP_MISMATCH,
            get_prop_command=get_prop_command, name=name,
            values='\\" or \\"'.join(values))
    self.script.append(cmd)
@@ -101,7 +131,7 @@ class EdifyGenerator(object):
                             for i in fp]) +
           ' ||\n    abort("E%d: Package expects build fingerprint of %s; '
           'this device has " + getprop("ro.build.fingerprint") + ".");') % (
               common.ErrorCode.FINGERPRINT_MISMATCH, " or ".join(fp))
               ErrorCode.FINGERPRINT_MISMATCH, " or ".join(fp))
    self.script.append(cmd)

  def AssertSomeThumbprint(self, *fp):
@@ -112,7 +142,7 @@ class EdifyGenerator(object):
                             for i in fp]) +
           ' ||\n    abort("E%d: Package expects build thumbprint of %s; this '
           'device has " + getprop("ro.build.thumbprint") + ".");') % (
               common.ErrorCode.THUMBPRINT_MISMATCH, " or ".join(fp))
               ErrorCode.THUMBPRINT_MISMATCH, " or ".join(fp))
    self.script.append(cmd)

  def AssertFingerprintOrThumbprint(self, fp, tp):
@@ -133,14 +163,14 @@ class EdifyGenerator(object):
        ('(!less_than_int(%s, getprop("ro.build.date.utc"))) || '
         'abort("E%d: Can\'t install this package (%s) over newer '
         'build (" + getprop("ro.build.date") + ").");') % (
             timestamp, common.ErrorCode.OLDER_BUILD, timestamp_text))
             timestamp, ErrorCode.OLDER_BUILD, timestamp_text))

  def AssertDevice(self, device):
    """Assert that the device identifier is the given string."""
    cmd = ('getprop("ro.product.device") == "%s" || '
           'abort("E%d: This package is for \\"%s\\" devices; '
           'this is a \\"" + getprop("ro.product.device") + "\\".");') % (
               device, common.ErrorCode.DEVICE_MISMATCH, device)
               device, ErrorCode.DEVICE_MISMATCH, device)
    self.script.append(cmd)

  def AssertSomeBootloader(self, *bootloaders):
@@ -207,7 +237,7 @@ class EdifyGenerator(object):
        'unexpected contents."));').format(
            target=target_expr,
            source=source_expr,
            code=common.ErrorCode.BAD_PATCH_FILE)))
            code=ErrorCode.BAD_PATCH_FILE)))

  def CacheFreeSpaceCheck(self, amount):
    """Check that there's at least 'amount' space that can be made
@@ -216,7 +246,7 @@ class EdifyGenerator(object):
    self.script.append(('apply_patch_space(%d) || abort("E%d: Not enough free '
                        'space on /cache to apply patches.");') % (
                            amount,
                            common.ErrorCode.INSUFFICIENT_CACHE_SPACE))
                            ErrorCode.INSUFFICIENT_CACHE_SPACE))

  def Mount(self, mount_point, mount_options_by_format=""):
    """Mount the partition with the given mount_point.
@@ -264,7 +294,7 @@ class EdifyGenerator(object):
        'tune2fs(' + "".join(['"%s", ' % (i,) for i in options]) +
        '%s) || abort("E%d: Failed to tune partition %s");' % (
            self._GetSlotSuffixDeviceForEntry(p),
            common.ErrorCode.TUNE_PARTITION_FAILURE, partition))
            ErrorCode.TUNE_PARTITION_FAILURE, partition))

  def FormatPartition(self, partition):
    """Format the given partition, specified by its mount point (eg,
@@ -354,7 +384,7 @@ class EdifyGenerator(object):
            target=target_expr,
            source=source_expr,
            patch=patch_expr,
            code=common.ErrorCode.APPLY_PATCH_FAILURE)))
            code=ErrorCode.APPLY_PATCH_FAILURE)))

  def _GetSlotSuffixDeviceForEntry(self, entry=None):
    """
+2 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import os
import sys

import common
from non_ab_ota import MakeRecoveryPatch

if sys.hexversion < 0x02070000:
  print("Python 2.7 or newer is required.", file=sys.stderr)
@@ -60,7 +61,7 @@ def main(argv):
                           *fn.split("/")), "wb") as f:
      f.write(data)

  common.MakeRecoveryPatch(input_dir, output_sink, recovery_img, boot_img)
  MakeRecoveryPatch(input_dir, output_sink, recovery_img, boot_img)


if __name__ == '__main__':
Loading