def CustomizeXML(app_info, description, icon_dict, manifest, permissions): app_version = app_info.app_version app_versionCode = app_info.app_versionCode name = app_info.android_name orientation = app_info.orientation package = app_info.package app_name = app_info.app_name app_dir = GetBuildDir(name) # Chinese character with unicode get from 'manifest.json' will cause # 'UnicodeEncodeError' when finally wrote to 'AndroidManifest.xml'. app_name = EncodingUnicodeValue(app_name) # If string start with '@' or '?', it will be treated as Android resource, # which will cause 'No resource found' error, # append a space before '@' or '?' to fix that. if app_name.startswith('@') or app_name.startswith('?'): app_name = ' ' + app_name manifest_path = os.path.join(app_dir, 'AndroidManifest.xml') if not os.path.isfile(manifest_path): print('Please make sure AndroidManifest.xml' ' exists under template folder.') sys.exit(6) CustomizeStringXML(name, description) CustomizeThemeXML(name, app_info.fullscreen_flag, manifest) xmldoc = minidom.parse(manifest_path) EditElementAttribute(xmldoc, 'manifest', 'package', package) if app_versionCode: EditElementAttribute(xmldoc, 'manifest', 'android:versionCode', str(app_versionCode)) if app_version: EditElementAttribute(xmldoc, 'manifest', 'android:versionName', app_version) if description: EditElementAttribute(xmldoc, 'manifest', 'android:description', "@string/description") HandlePermissions(permissions, xmldoc) EditElementAttribute(xmldoc, 'application', 'android:label', app_name) activity_name = package + '.' + name + 'Activity' EditElementAttribute(xmldoc, 'activity', 'android:name', activity_name) EditElementAttribute(xmldoc, 'activity', 'android:label', app_name) if orientation: EditElementAttribute(xmldoc, 'activity', 'android:screenOrientation', orientation) icon_name = CustomizeIcon(name, app_info.app_root, app_info.icon, icon_dict) if icon_name: EditElementAttribute(xmldoc, 'application', 'android:icon', '@drawable/%s' % icon_name) file_handle = open(os.path.join(app_dir, 'AndroidManifest.xml'), 'w') xmldoc.writexml(file_handle, encoding='utf-8') file_handle.close()
def CustomizeXML(options, sanitized_name): manifest_path = os.path.join(sanitized_name, 'AndroidManifest.xml') if not os.path.isfile(manifest_path): print( 'Please make sure AndroidManifest.xml' ' exists under app_src folder.') sys.exit(6) CustomizeStringXML(options, sanitized_name) xmldoc = minidom.parse(manifest_path) EditElementAttribute(xmldoc, 'manifest', 'package', options.package) if options.app_version: EditElementAttribute(xmldoc, 'manifest', 'android:versionName', options.app_version) if options.description: EditElementAttribute(xmldoc, 'manifest', 'android:description', "@string/description") HandlePermissions(options, xmldoc) EditElementAttribute(xmldoc, 'application', 'android:label', options.name) activity_name = options.package + '.' + sanitized_name + 'Activity' EditElementAttribute(xmldoc, 'activity', 'android:name', activity_name) EditElementAttribute(xmldoc, 'activity', 'android:label', options.name) if options.orientation: EditElementAttribute(xmldoc, 'activity', 'android:screenOrientation', options.orientation) if options.fullscreen: AddThemeStyle(xmldoc, 'activity', 'android:theme', 'Fullscreen') else: RemoveThemeStyle(xmldoc, 'activity', 'android:theme', 'Fullscreen') if options.icon and os.path.isfile(options.icon): drawable_path = os.path.join(sanitized_name, 'res', 'drawable') if not os.path.exists(drawable_path): os.makedirs(drawable_path) icon_file = os.path.basename(options.icon) icon_file = ReplaceInvalidChars(icon_file) shutil.copyfile(options.icon, os.path.join(drawable_path, icon_file)) icon_name = os.path.splitext(icon_file)[0] EditElementAttribute(xmldoc, 'application', 'android:icon', '@drawable/%s' % icon_name) elif options.icon and (not os.path.isfile(options.icon)): print('Please make sure the icon file does exist!') sys.exit(6) file_handle = open(os.path.join(sanitized_name, 'AndroidManifest.xml'), 'wb') xmldoc.writexml(file_handle) file_handle.close()
def CustomizeXML(app_info, description, icon_dict, app_manifest, permissions): app_version = app_info.app_version app_versionCode = app_info.app_versionCode name = app_info.name orientation = app_info.orientation package = app_info.package original_name = app_info.original_name manifest_path = os.path.join(name, 'AndroidManifest.xml') if not os.path.isfile(manifest_path): print('Please make sure AndroidManifest.xml' ' exists under app_src folder.') sys.exit(6) CustomizeStringXML(name, description) CustomizeThemeXML(name, app_info.fullscreen_flag, app_manifest) xmldoc = minidom.parse(manifest_path) EditElementAttribute(xmldoc, 'manifest', 'package', package) if app_versionCode: EditElementAttribute(xmldoc, 'manifest', 'android:versionCode', str(app_versionCode)) if app_version: EditElementAttribute(xmldoc, 'manifest', 'android:versionName', app_version) if description: EditElementAttribute(xmldoc, 'manifest', 'android:description', "@string/description") HandlePermissions(permissions, xmldoc) EditElementAttribute(xmldoc, 'application', 'android:label', original_name) activity_name = package + '.' + name + 'Activity' EditElementAttribute(xmldoc, 'activity', 'android:name', activity_name) EditElementAttribute(xmldoc, 'activity', 'android:label', original_name) if orientation: EditElementAttribute(xmldoc, 'activity', 'android:screenOrientation', orientation) icon_name = CustomizeIcon(name, app_info.app_root, app_info.icon, icon_dict) if icon_name: EditElementAttribute(xmldoc, 'application', 'android:icon', '@drawable/%s' % icon_name) file_handle = open(os.path.join(name, 'AndroidManifest.xml'), 'w') xmldoc.writexml(file_handle, encoding='utf-8') file_handle.close()
def CustomizeXML(app_info, description, icon_dict, manifest, permissions): app_version = app_info.app_version app_versionCode = app_info.app_versionCode name = app_info.android_name orientation = app_info.orientation package = app_info.package app_name = app_info.app_name app_dir = GetBuildDir(name) # Chinese character with unicode get from 'manifest.json' will cause # 'UnicodeEncodeError' when finally wrote to 'AndroidManifest.xml'. app_name = EncodingUnicodeValue(app_name) # If string start with '@' or '?', it will be treated as Android resource, # which will cause 'No resource found' error, # append a space before '@' or '?' to fix that. if app_name.startswith('@') or app_name.startswith('?'): app_name = ' ' + app_name manifest_path = os.path.join(app_dir, 'AndroidManifest.xml') if not os.path.isfile(manifest_path): print('Please make sure AndroidManifest.xml' ' exists under template folder.') sys.exit(6) CustomizeStringXML(name, description) CustomizeThemeXML(name, app_info.fullscreen_flag, manifest) xmldoc = minidom.parse(manifest_path) EditElementAttribute(xmldoc, 'manifest', 'package', package) if app_versionCode: EditElementAttribute(xmldoc, 'manifest', 'android:versionCode', str(app_versionCode)) if app_version: EditElementAttribute(xmldoc, 'manifest', 'android:versionName', app_version) if description: EditElementAttribute(xmldoc, 'manifest', 'android:description', "@string/description") HandlePermissions(permissions, xmldoc) if app_info.mode == 'download': AddElementAttribute( xmldoc, 'uses-permission', 'android:name', 'android.permission.DOWNLOAD_WITHOUT_NOTIFICATION') EditElementAttribute(xmldoc, 'application', 'android:label', app_name) activity_name = package + '.' + name + 'Activity' EditElementAttribute(xmldoc, 'activity', 'android:name', activity_name) EditElementAttribute(xmldoc, 'activity', 'android:label', app_name) if orientation: EditElementAttribute(xmldoc, 'activity', 'android:screenOrientation', orientation) icon_name = CustomizeIcon(name, app_info.app_root, app_info.icon, icon_dict) if icon_name: EditElementAttribute(xmldoc, 'application', 'android:icon', '@drawable/%s' % icon_name) if app_info.xwalk_apk_url: meta_data = xmldoc.createElement('meta-data') meta_data.setAttribute('android:name', 'xwalk_apk_url') meta_data.setAttribute('android:value', app_info.xwalk_apk_url) app_node = xmldoc.getElementsByTagName('application')[0] comment = 'The download URL of Crosswalk runtime library APK. \n\ Default updater use the Android download manager to fetch the url' app_node.appendChild(xmldoc.createComment(comment)) app_node.appendChild(meta_data) if app_info.mode == 'download': meta_data = xmldoc.createElement('meta-data') meta_data.setAttribute('android:name', 'xwalk_enable_download_mode') meta_data.setAttribute('android:value', 'enable') comment = 'Make application run in silent download mode.' app_node.appendChild(xmldoc.createComment(comment)) app_node.appendChild(meta_data) file_handle = open(os.path.join(app_dir, 'AndroidManifest.xml'), 'w') xmldoc.writexml(file_handle, encoding='utf-8') file_handle.close()