From 77a4aa0c064316fb8a8686542c8123940a54b189 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 1 May 2019 22:08:43 -0700 Subject: [PATCH] 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 --- tools/releasetools/add_img_to_target_files.py | 10 +++++-- .../test_add_img_to_target_files.py | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py index 4af10ca53d..99ffa31019 100755 --- a/tools/releasetools/add_img_to_target_files.py +++ b/tools/releasetools/add_img_to_target_files.py @@ -113,7 +113,7 @@ def GetCareMap(which, imgname): 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 @@ def GetCareMap(which, imgname): # 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 @@ def AddCareMapForAbOta(output_zip, ab_partitions, image_paths): 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 422262cdea..08e01907c0 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 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase): 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()