Example #1
0
def ComputeRuntimeBuildInfos(default_build_info, boot_variable_values):
    """Returns a set of build info objects that may exist during runtime."""

    build_info_set = {default_build_info}
    if not boot_variable_values:
        return build_info_set

    # Calculate all possible combinations of the values for the boot variables.
    keys = boot_variable_values.keys()
    value_list = boot_variable_values.values()
    combinations = [
        dict(zip(keys, values)) for values in itertools.product(*value_list)
    ]
    for placeholder_values in combinations:
        # Reload the info_dict as some build properties may change their values
        # based on the value of ro.boot* properties.
        info_dict = copy.deepcopy(default_build_info.info_dict)
        for partition in PARTITIONS_WITH_BUILD_PROP:
            partition_prop_key = "{}.build.prop".format(partition)
            input_file = info_dict[partition_prop_key].input_file
            if isinstance(input_file, zipfile.ZipFile):
                with zipfile.ZipFile(input_file.filename,
                                     allowZip64=True) as input_zip:
                    info_dict[partition_prop_key] = \
                        PartitionBuildProps.FromInputFile(input_zip, partition,
                                                          placeholder_values)
            else:
                info_dict[partition_prop_key] = \
                    PartitionBuildProps.FromInputFile(input_file, partition,
                                                      placeholder_values)
        info_dict["build.prop"] = info_dict["system.build.prop"]
        build_info_set.add(BuildInfo(info_dict, default_build_info.oem_dicts))

    return build_info_set
Example #2
0
def GetBootImageTimestamp(boot_img):
    """
  Get timestamp from ramdisk within the boot image

  Args:
    boot_img: the boot image file. Ramdisk must be compressed with lz4 format.

  Return:
    An integer that corresponds to the timestamp of the boot image, or None
    if file has unknown format. Raise exception if an unexpected error has
    occurred.
  """

    tmp_dir = MakeTempDir('boot_', suffix='.img')
    try:
        RunAndCheckOutput(
            ['unpack_bootimg', '--boot_img', boot_img, '--out', tmp_dir])
        ramdisk = os.path.join(tmp_dir, 'ramdisk')
        if not os.path.isfile(ramdisk):
            logger.warning(
                'Unable to get boot image timestamp: no ramdisk in boot')
            return None
        uncompressed_ramdisk = os.path.join(tmp_dir, 'uncompressed_ramdisk')
        RunAndCheckOutput(['lz4', '-d', ramdisk, uncompressed_ramdisk])

        abs_uncompressed_ramdisk = os.path.abspath(uncompressed_ramdisk)
        extracted_ramdisk = MakeTempDir('extracted_ramdisk')
        # Use "toybox cpio" instead of "cpio" because the latter invokes cpio from
        # the host environment.
        RunAndCheckOutput(
            ['toybox', 'cpio', '-F', abs_uncompressed_ramdisk, '-i'],
            cwd=extracted_ramdisk)

        prop_file = None
        for search_path in RAMDISK_BUILD_PROP_REL_PATHS:
            prop_file = os.path.join(extracted_ramdisk, search_path)
            if os.path.isfile(prop_file):
                break
            logger.warning(
                'Unable to get boot image timestamp: no %s in ramdisk',
                search_path)

        if not prop_file:
            return None

        props = PartitionBuildProps.FromBuildPropFile('boot', prop_file)
        timestamp = props.GetProp('ro.bootimage.build.date.utc')
        if timestamp:
            return int(timestamp)
        logger.warning(
            'Unable to get boot image timestamp: ro.bootimage.build.date.utc is undefined'
        )
        return None

    except ExternalError as e:
        logger.warning('Unable to get boot image timestamp: %s', e)
        return None
Example #3
0
def CalculateRuntimeDevicesAndFingerprints(build_info, boot_variable_values):
    """Returns a tuple of sets for runtime devices and fingerprints"""

    device_names = {build_info.device}
    fingerprints = {build_info.fingerprint}

    if not boot_variable_values:
        return device_names, fingerprints

    # Calculate all possible combinations of the values for the boot variables.
    keys = boot_variable_values.keys()
    value_list = boot_variable_values.values()
    combinations = [
        dict(zip(keys, values)) for values in itertools.product(*value_list)
    ]
    for placeholder_values in combinations:
        # Reload the info_dict as some build properties may change their values
        # based on the value of ro.boot* properties.
        info_dict = copy.deepcopy(build_info.info_dict)
        for partition in PARTITIONS_WITH_CARE_MAP:
            partition_prop_key = "{}.build.prop".format(partition)
            input_file = info_dict[partition_prop_key].input_file
            if isinstance(input_file, zipfile.ZipFile):
                with zipfile.ZipFile(input_file.filename) as input_zip:
                    info_dict[partition_prop_key] = \
                        PartitionBuildProps.FromInputFile(input_zip, partition,
                                                          placeholder_values)
            else:
                info_dict[partition_prop_key] = \
                    PartitionBuildProps.FromInputFile(input_file, partition,
                                                      placeholder_values)
        info_dict["build.prop"] = info_dict["system.build.prop"]

        new_build_info = BuildInfo(info_dict, build_info.oem_dicts)
        device_names.add(new_build_info.device)
        fingerprints.add(new_build_info.fingerprint)
    return device_names, fingerprints