Reland "Calculate the runtime fingerprint prefixes from build prop"
This reverts commit b21e48b499850bfb5ac9e6e155ed96e8e724c5c0.
In practice, some partners use the 'import' statement to override
the device fingerprint at runtime. The runtime fingerprint will
later add to the metadata of OTA package, so that the OTA server
can deliver the package to corresponding devices correctly.
This CL supports parsing a subset of import statement that the init
process recognizes. And we loose the restriction based on how the
dynamic fingerprint is used in practice. Right now, we only searches
for the override of brand, name and device. And the placeholder
format should be ${placeholder}, with its value supplied by the
script caller.
As part of the implementation, we generate all the possible
combinations of the input boot variables. And recalculate the
fingerprint for each of the combination. Though we load the
build.prop multiple times, the logic is easier to follow. Also,
it's more convenient to enhance the logic if we only want to
allow some of the boot variables combination later.
Bug: 152167826
Change-Id: I4a9fa35c7ac037ff1cf4f9a4bdff602beac3894b
Test: unittests pass
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index 92a46a2..47ad3d8 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -193,6 +193,8 @@
from __future__ import print_function
import collections
+import copy
+import itertools
import logging
import multiprocessing
import os.path
@@ -229,6 +231,7 @@
OPTIONS.no_signing = False
OPTIONS.block_based = True
OPTIONS.updater_binary = None
+OPTIONS.oem_dicts = None
OPTIONS.oem_source = None
OPTIONS.oem_no_mount = False
OPTIONS.full_radio = False
@@ -247,6 +250,7 @@
OPTIONS.skip_compatibility_check = False
OPTIONS.output_metadata_path = None
OPTIONS.disable_fec_computation = False
+OPTIONS.boot_variable_values = None
METADATA_NAME = 'META-INF/com/android/metadata'
@@ -1959,6 +1963,36 @@
output_file)
+def CalculateRuntimeFingerprints():
+ """Returns a set of runtime fingerprints based on the boot variables."""
+
+ build_info = common.BuildInfo(OPTIONS.info_dict, OPTIONS.oem_dicts)
+ fingerprints = {build_info.fingerprint}
+
+ if not OPTIONS.boot_variable_values:
+ return fingerprints
+
+ # Calculate all possible combinations of the values for the boot variables.
+ keys = OPTIONS.boot_variable_values.keys()
+ value_list = OPTIONS.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(OPTIONS.info_dict)
+ for partition in common.PARTITIONS_WITH_CARE_MAP:
+ partition_prop_key = "{}.build.prop".format(partition)
+ old_props = info_dict[partition_prop_key]
+ info_dict[partition_prop_key] = common.PartitionBuildProps.FromInputFile(
+ old_props.input_file, partition, placeholder_values)
+ info_dict["build.prop"] = info_dict["system.build.prop"]
+
+ build_info = common.BuildInfo(info_dict, OPTIONS.oem_dicts)
+ fingerprints.add(build_info.fingerprint)
+ return fingerprints
+
+
def main(argv):
def option_handler(o, a):