AIDEGen: Replace the template files by using string in Python

Bug: 139036304
Test: 1. m aidegen;aidegen-dev Settings
      2. Confirm the modules.xml and vcs.xml under
         packages/apps/Settings/.idea/ are not changed.

Change-Id: I19c7c67823d18a04ff670f5f01d7db7e0f844888
diff --git a/aidegen/constant.py b/aidegen/constant.py
index edeae65..bda6c87 100644
--- a/aidegen/constant.py
+++ b/aidegen/constant.py
@@ -61,7 +61,7 @@
 BLUEPRINT_JSONFILE_NAME = 'module_bp_java_deps.json'
 
 # Content of iml file.
-FILE_IML = '''<?xml version="1.0" encoding="UTF-8"?>
+FILE_IML = """<?xml version="1.0" encoding="UTF-8"?>
 <module type="JAVA_MODULE" version="4">
 @FACETS@
     <component name="NewModuleRootManager" inherit-compiler-output="true">
@@ -73,4 +73,25 @@
         <orderEntry type="inheritedJdk" />
     </component>
 </module>
-'''
+"""
+
+# IDEA XML templates
+# The template content of modules.xml.
+MODULES_XML = """<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+    <component name="ProjectModuleManager">
+        <modules>
+@MODULES@
+@ENABLE_DEBUGGER_MODULE@
+        </modules>
+    </component>
+</project>
+"""
+# The template content of vcs.xml.
+VCS_XML = """<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+    <component name="VcsDirectoryMappings">
+@VCS@
+    </component>
+</project>
+"""
diff --git a/aidegen/lib/project_file_gen.py b/aidegen/lib/project_file_gen.py
index 4ee270b..b442255 100644
--- a/aidegen/lib/project_file_gen.py
+++ b/aidegen/lib/project_file_gen.py
@@ -64,8 +64,6 @@
 _IDEA_FOLDER = '.idea'
 _MODULES_XML = 'modules.xml'
 _VCS_XML = 'vcs.xml'
-_TEMPLATE_MODULES_PATH = os.path.join(_IDEA_DIR, _MODULES_XML)
-_TEMPLATE_VCS_PATH = os.path.join(_IDEA_DIR, _VCS_XML)
 _DEPENDENCIES_IML = 'dependencies.iml'
 _COPYRIGHT_FOLDER = 'copyright'
 _CODE_STYLE_FOLDER = 'codeStyles'
@@ -493,7 +491,6 @@
             iml_path_list: A list of submodule iml paths.
         """
         module_path = self.project_info.project_absolute_path
-        content = common_util.read_file_content(_TEMPLATE_MODULES_PATH)
 
         # b/121256503: Prevent duplicated iml names from breaking IDEA.
         module_name = self.get_unique_iml_name(module_path)
@@ -510,16 +507,33 @@
             module_list = [
                 _MODULE_SECTION % (module_name, module_name)
             ]
-            # Sub projects don't need to be filled in the enable debugger module
-            # so we remove the token here. For the main project, the enable
-            # debugger module will be appended if it exists at the time
-            # launching IDE.
-            content = content.replace(_ENABLE_DEBUGGER_MODULE_TOKEN, '')
         module = '\n'.join(module_list)
+        content = self._remove_debugger_token(constant.MODULES_XML)
         content = content.replace(_MODULE_TOKEN, module)
         target_path = os.path.join(module_path, _IDEA_FOLDER, _MODULES_XML)
         common_util.file_generate(target_path, content)
 
+    def _remove_debugger_token(self, content):
+        """Remove the token _ENABLE_DEBUGGER_MODULE_TOKEN.
+
+        Remove the token _ENABLE_DEBUGGER_MODULE_TOKEN in 2 cases:
+        1. Sub projects don't need to be filled in the enable debugger module
+           so we remove the token here. For the main project, the enable
+           debugger module will be appended if it exists at the time launching
+           IDE.
+        2. When there is no need to launch IDE.
+
+        Args:
+            content: The content of module.xml.
+
+        Returns:
+            String: The content of module.xml.
+        """
+        if (not self.project_info.config.is_launch_ide or
+                not self.project_info.is_main_project):
+            content = content.replace(_ENABLE_DEBUGGER_MODULE_TOKEN, '')
+        return content
+
     def _get_project_git_path(self):
         """Get the project's git path.
 
@@ -611,8 +625,7 @@
         git_paths: A list of git path.
     """
     _vcs_content = '\n'.join([_VCS_SECTION % p for p in git_paths if p])
-    content = common_util.read_file_content(_TEMPLATE_VCS_PATH)
-    content = content.replace(_VCS_TOKEN, _vcs_content)
+    content = constant.VCS_XML.replace(_VCS_TOKEN, _vcs_content)
     target_path = os.path.join(module_path, _IDEA_FOLDER, _VCS_XML)
     common_util.file_generate(target_path, content)