releasetools: Skip on empty care_map.
common.GetCareMap() may return an empty list on unavailable care_map
since the change in commit 8bdfb990ea978e0cf4e16fc0702dc7cb067856e8.
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
diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py
index 4af10ca..99ffa31 100755
--- a/tools/releasetools/add_img_to_target_files.py
+++ b/tools/releasetools/add_img_to_target_files.py
@@ -113,7 +113,7 @@
Returns:
(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
@@ -123,7 +123,7 @@
# invalid reads.
image_size = OPTIONS.info_dict.get(which + "_image_size")
if not image_size:
- return []
+ return None
image_blocks = int(image_size) / 4096 - 1
assert image_blocks > 0, "blocks for {} must be positive".format(which)
@@ -592,7 +592,11 @@
OPTIONS.info_dict.get(avb_hashtree_enable) == "true"):
image_path = image_paths[partition]
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
build_props = OPTIONS.info_dict.get(partition + ".build.prop", {})
diff --git a/tools/releasetools/test_add_img_to_target_files.py b/tools/releasetools/test_add_img_to_target_files.py
index 422262c..08e0190 100644
--- a/tools/releasetools/test_add_img_to_target_files.py
+++ b/tools/releasetools/test_add_img_to_target_files.py
@@ -283,6 +283,35 @@
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):
"""No care_map.pb should be generated if verity not enabled."""
image_paths = self._test_AddCareMapForAbOta()