Exemplo n.º 1
0
 def process_func(filename, data):
   if filename == 'resources.pb':
     table = Resources_pb2.ResourceTable()
     table.ParseFromString(data)
     _HardcodeInTable(table, is_bundle_module, shared_resources_allowlist)
     data = table.SerializeToString()
   elif filename.endswith('.xml') and not filename.startswith('res/raw'):
     xml_node = Resources_pb2.XmlNode()
     xml_node.ParseFromString(data)
     _ProcessProtoXmlNode(xml_node)
     data = xml_node.SerializeToString()
   return data
Exemplo n.º 2
0
def _HardcodeSharedLibraryDynamicAttributes(zip_path):
    """Hardcodes the package IDs of dynamic attributes to 0x02.

  This is a workaround for b/147674078, which affects Android versions pre-N.

  Args:
    zip_path: Path to proto APK file.
  """
    with build_utils.TempDir() as tmp_dir:
        build_utils.ExtractAll(zip_path, path=tmp_dir)

        # First process the resources file.
        table = Resources_pb2.ResourceTable()
        with open(os.path.join(tmp_dir, 'resources.pb')) as f:
            table.ParseFromString(f.read())

        for package in table.package:
            for _type in package.type:
                for entry in _type.entry:
                    for config_value in entry.config_value:
                        _ProcessProtoValue(config_value.value)

        with open(os.path.join(tmp_dir, 'resources.pb'), 'w') as f:
            f.write(table.SerializeToString())

        # Next process all the XML files.
        xml_files = build_utils.FindInDirectory(tmp_dir, '*.xml')
        for xml_file in xml_files:
            xml_node = Resources_pb2.XmlNode()
            with open(xml_file) as f:
                xml_node.ParseFromString(f.read())

            _ProcessProtoXmlNode(xml_node)

            with open(xml_file, 'w') as f:
                f.write(xml_node.SerializeToString())

        # Overwrite the original zip file.
        build_utils.ZipDir(zip_path, tmp_dir)