diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py index eaf6c078b..2b6987f56 100755 --- a/tools/releasetools/ota_from_target_files.py +++ b/tools/releasetools/ota_from_target_files.py @@ -250,12 +250,14 @@ class BuildInfo(object): def __init__(self, info_dict, oem_dicts): """Initializes a BuildInfo instance with the given dicts. + Note that it only wraps up the given dicts, without making copies. + Arguments: info_dict: The build-time info dict. oem_dicts: A list of OEM dicts (which is parsed from --oem_settings). Note that it always uses the first dict to calculate the fingerprint or the device name. The rest would be used for asserting OEM properties only - (e.g. one package can be installed on one of these devices). + (e.g. one package can be installed on one of these devices). """ self.info_dict = info_dict self.oem_dicts = oem_dicts @@ -289,9 +291,15 @@ class BuildInfo(object): def __getitem__(self, key): return self.info_dict[key] + def __setitem__(self, key, value): + self.info_dict[key] = value + def get(self, key, default=None): return self.info_dict.get(key, default) + def items(self): + return self.info_dict.items() + def GetBuildProp(self, prop): """Returns the inquired build property.""" try: diff --git a/tools/releasetools/test_ota_from_target_files.py b/tools/releasetools/test_ota_from_target_files.py index e472363ad..7c34b7e99 100644 --- a/tools/releasetools/test_ota_from_target_files.py +++ b/tools/releasetools/test_ota_from_target_files.py @@ -190,6 +190,16 @@ class BuildInfoTest(unittest.TestCase): self.assertRaises(KeyError, lambda: target_info['build.prop']['ro.build.foo']) + def test___setitem__(self): + target_info = BuildInfo(copy.deepcopy(self.TEST_INFO_DICT), None) + self.assertEqual('value1', target_info['property1']) + target_info['property1'] = 'value2' + self.assertEqual('value2', target_info['property1']) + + self.assertEqual('build-foo', target_info['build.prop']['ro.build.foo']) + target_info['build.prop']['ro.build.foo'] = 'build-bar' + self.assertEqual('build-bar', target_info['build.prop']['ro.build.foo']) + def test_get(self): target_info = BuildInfo(self.TEST_INFO_DICT, None) self.assertEqual('value1', target_info.get('property1')) @@ -209,6 +219,12 @@ class BuildInfoTest(unittest.TestCase): self.assertRaises(KeyError, lambda: target_info.get('build.prop')['ro.build.foo']) + def test_items(self): + target_info = BuildInfo(self.TEST_INFO_DICT, None) + items = target_info.items() + self.assertIn(('property1', 'value1'), items) + self.assertIn(('property2', 4096), items) + def test_GetBuildProp(self): target_info = BuildInfo(self.TEST_INFO_DICT, None) self.assertEqual('build-foo', target_info.GetBuildProp('ro.build.foo'))