releasetools: Skip on empty care_map.
common.GetCareMap() may return an empty list on unavailable care_map
since the change in commit 8bdfb990ea
.
Caller needs to handle such a case accordingly. This CL fixes the caller
in add_img_to_target_files.py, and changes the return value to None to
break legacy callers loudly.
Fixes: 131794385
Test: `atest releasetools_test`
Change-Id: I7c94f456064199237e84ef75732bdd10ebe31736
This commit is contained in:
@@ -113,7 +113,7 @@ def GetCareMap(which, imgname):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(which, care_map_ranges): care_map_ranges is the raw string of the care_map
|
(which, care_map_ranges): care_map_ranges is the raw string of the care_map
|
||||||
RangeSet; or an empty list.
|
RangeSet; or None.
|
||||||
"""
|
"""
|
||||||
assert which in common.PARTITIONS_WITH_CARE_MAP
|
assert which in common.PARTITIONS_WITH_CARE_MAP
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ def GetCareMap(which, imgname):
|
|||||||
# invalid reads.
|
# invalid reads.
|
||||||
image_size = OPTIONS.info_dict.get(which + "_image_size")
|
image_size = OPTIONS.info_dict.get(which + "_image_size")
|
||||||
if not image_size:
|
if not image_size:
|
||||||
return []
|
return None
|
||||||
|
|
||||||
image_blocks = int(image_size) / 4096 - 1
|
image_blocks = int(image_size) / 4096 - 1
|
||||||
assert image_blocks > 0, "blocks for {} must be positive".format(which)
|
assert image_blocks > 0, "blocks for {} must be positive".format(which)
|
||||||
@@ -592,7 +592,11 @@ def AddCareMapForAbOta(output_zip, ab_partitions, image_paths):
|
|||||||
OPTIONS.info_dict.get(avb_hashtree_enable) == "true"):
|
OPTIONS.info_dict.get(avb_hashtree_enable) == "true"):
|
||||||
image_path = image_paths[partition]
|
image_path = image_paths[partition]
|
||||||
assert os.path.exists(image_path)
|
assert os.path.exists(image_path)
|
||||||
care_map_list += GetCareMap(partition, image_path)
|
|
||||||
|
care_map = GetCareMap(partition, image_path)
|
||||||
|
if not care_map:
|
||||||
|
continue
|
||||||
|
care_map_list += care_map
|
||||||
|
|
||||||
# adds fingerprint field to the care_map
|
# adds fingerprint field to the care_map
|
||||||
build_props = OPTIONS.info_dict.get(partition + ".build.prop", {})
|
build_props = OPTIONS.info_dict.get(partition + ".build.prop", {})
|
||||||
|
@@ -283,6 +283,35 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
|
|||||||
|
|
||||||
self._verifyCareMap(expected, care_map_file)
|
self._verifyCareMap(expected, care_map_file)
|
||||||
|
|
||||||
|
@test_utils.SkipIfExternalToolsUnavailable()
|
||||||
|
def test_AddCareMapForAbOta_skipPartition(self):
|
||||||
|
image_paths = self._test_AddCareMapForAbOta()
|
||||||
|
|
||||||
|
# Remove vendor_image_size to invalidate the care_map for vendor.img.
|
||||||
|
del OPTIONS.info_dict['vendor_image_size']
|
||||||
|
|
||||||
|
AddCareMapForAbOta(None, ['system', 'vendor'], image_paths)
|
||||||
|
|
||||||
|
care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.pb')
|
||||||
|
expected = ['system', RangeSet("0-5 10-15").to_string_raw(),
|
||||||
|
"ro.system.build.fingerprint",
|
||||||
|
"google/sailfish/12345:user/dev-keys"]
|
||||||
|
|
||||||
|
self._verifyCareMap(expected, care_map_file)
|
||||||
|
|
||||||
|
@test_utils.SkipIfExternalToolsUnavailable()
|
||||||
|
def test_AddCareMapForAbOta_skipAllPartitions(self):
|
||||||
|
image_paths = self._test_AddCareMapForAbOta()
|
||||||
|
|
||||||
|
# Remove the image_size properties for all the partitions.
|
||||||
|
del OPTIONS.info_dict['system_image_size']
|
||||||
|
del OPTIONS.info_dict['vendor_image_size']
|
||||||
|
|
||||||
|
AddCareMapForAbOta(None, ['system', 'vendor'], image_paths)
|
||||||
|
|
||||||
|
self.assertFalse(
|
||||||
|
os.path.exists(os.path.join(OPTIONS.input_tmp, 'META', 'care_map.pb')))
|
||||||
|
|
||||||
def test_AddCareMapForAbOta_verityNotEnabled(self):
|
def test_AddCareMapForAbOta_verityNotEnabled(self):
|
||||||
"""No care_map.pb should be generated if verity not enabled."""
|
"""No care_map.pb should be generated if verity not enabled."""
|
||||||
image_paths = self._test_AddCareMapForAbOta()
|
image_paths = self._test_AddCareMapForAbOta()
|
||||||
|
Reference in New Issue
Block a user