Move more non-AB code to separate files

non-AB has different lifetime and development cycles from AB. To avoid
accidentally breaking each other when making changes, put non-AB code in
its own files.

Test: local non-AB OTA generation
Bug: 296485685

Merged-In: I0736ecef343834c746464666a454a8bfcd4a20ea

Change-Id: I0736ecef343834c746464666a454a8bfcd4a20ea
This commit is contained in:
Kelvin Zhang
2023-10-27 13:27:07 -07:00
parent 4fd3b11018
commit 513b86e5c2
8 changed files with 1260 additions and 1237 deletions

View File

@@ -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):
"""