| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. | 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 """Creates an AndroidManifest.xml for an incremental APK. | 6 """Creates an AndroidManifest.xml for an incremental APK. |
| 7 | 7 |
| 8 Given the manifest file for the real APK, generates an AndroidManifest.xml with | 8 Given the manifest file for the real APK, generates an AndroidManifest.xml with |
| 9 the application class changed to IncrementalApplication. | 9 the application class changed to IncrementalApplication. |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 import argparse | 12 import argparse |
| 13 import os | 13 import os |
| 14 import sys | 14 import sys |
| 15 from xml.etree import ElementTree | 15 from xml.etree import ElementTree |
| 16 | 16 |
| 17 sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir, 'gyp')) | 17 sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir, 'gyp')) |
| 18 from util import build_utils | 18 from util import build_utils |
| 19 | 19 |
| 20 _ANDROID_NAMESPACE = 'http://schemas.android.com/apk/res/android' | 20 _ANDROID_NAMESPACE = 'http://schemas.android.com/apk/res/android' |
| 21 ElementTree.register_namespace('android', _ANDROID_NAMESPACE) | 21 ElementTree.register_namespace('android', _ANDROID_NAMESPACE) |
| 22 | 22 |
| 23 _INCREMENTAL_APP_NAME = 'org.chromium.incrementalinstall.BootstrapApplication' | 23 _INCREMENTAL_APP_NAME = 'org.chromium.incrementalinstall.BootstrapApplication' |
| 24 _META_DATA_APP_NAME = 'incremental-install-real-app' | 24 _META_DATA_APP_NAME = 'incremental-install-real-app' |
| 25 _META_DATA_INSTRUMENTATION_NAME = 'incremental-install-real-instrumentation' | |
| 26 _DEFAULT_APPLICATION_CLASS = 'android.app.Application' | 25 _DEFAULT_APPLICATION_CLASS = 'android.app.Application' |
| 27 _DEFAULT_INSTRUMENTATION_CLASS = 'android.app.Instrumentation' | 26 _META_DATA_INSTRUMENTATION_NAMES = [ |
| 27 'incremental-install-real-instrumentation-0', |
| 28 'incremental-install-real-instrumentation-1', |
| 29 ] |
| 30 _INCREMENTAL_INSTRUMENTATION_CLASSES = [ |
| 31 'android.app.Instrumentation', |
| 32 'org.chromium.incrementalinstall.SecondInstrumentation', |
| 33 ] |
| 28 | 34 |
| 29 | 35 |
| 30 def _AddNamespace(name): | 36 def _AddNamespace(name): |
| 31 """Adds the android namespace prefix to the given identifier.""" | 37 """Adds the android namespace prefix to the given identifier.""" |
| 32 return '{%s}%s' % (_ANDROID_NAMESPACE, name) | 38 return '{%s}%s' % (_ANDROID_NAMESPACE, name) |
| 33 | 39 |
| 34 def _ParseArgs(): | 40 def _ParseArgs(): |
| 35 parser = argparse.ArgumentParser() | 41 parser = argparse.ArgumentParser() |
| 36 build_utils.AddDepfileOption(parser) | 42 build_utils.AddDepfileOption(parser) |
| 37 parser.add_argument('--src-manifest', | 43 parser.add_argument('--src-manifest', |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 if app_node is None: | 83 if app_node is None: |
| 78 app_node = ElementTree.SubElement(doc, 'application') | 84 app_node = ElementTree.SubElement(doc, 'application') |
| 79 | 85 |
| 80 real_app_class = app_node.get(_AddNamespace('name'), | 86 real_app_class = app_node.get(_AddNamespace('name'), |
| 81 _DEFAULT_APPLICATION_CLASS) | 87 _DEFAULT_APPLICATION_CLASS) |
| 82 app_node.set(_AddNamespace('name'), _INCREMENTAL_APP_NAME) | 88 app_node.set(_AddNamespace('name'), _INCREMENTAL_APP_NAME) |
| 83 _CreateMetaData(app_node, _META_DATA_APP_NAME, real_app_class) | 89 _CreateMetaData(app_node, _META_DATA_APP_NAME, real_app_class) |
| 84 | 90 |
| 85 # Seems to be a bug in ElementTree, as doc.find() doesn't work here. | 91 # Seems to be a bug in ElementTree, as doc.find() doesn't work here. |
| 86 instrumentation_nodes = doc.findall('instrumentation') | 92 instrumentation_nodes = doc.findall('instrumentation') |
| 87 if instrumentation_nodes: | 93 assert len(instrumentation_nodes) <= 2, ( |
| 88 instrumentation_node = instrumentation_nodes[0] | 94 'Need to update incremental install to support >2 <instrumentation> tags') |
| 95 for i, instrumentation_node in enumerate(instrumentation_nodes): |
| 89 real_instrumentation_class = instrumentation_node.get(_AddNamespace('name')) | 96 real_instrumentation_class = instrumentation_node.get(_AddNamespace('name')) |
| 90 instrumentation_node.set(_AddNamespace('name'), | 97 instrumentation_node.set(_AddNamespace('name'), |
| 91 _DEFAULT_INSTRUMENTATION_CLASS) | 98 _INCREMENTAL_INSTRUMENTATION_CLASSES[i]) |
| 92 _CreateMetaData(app_node, _META_DATA_INSTRUMENTATION_NAME, | 99 _CreateMetaData(app_node, _META_DATA_INSTRUMENTATION_NAMES[i], |
| 93 real_instrumentation_class) | 100 real_instrumentation_class) |
| 94 | 101 |
| 95 return ElementTree.tostring(doc, encoding='UTF-8') | 102 return ElementTree.tostring(doc, encoding='UTF-8') |
| 96 | 103 |
| 97 | 104 |
| 98 def main(): | 105 def main(): |
| 99 options = _ParseArgs() | 106 options = _ParseArgs() |
| 100 with open(options.src_manifest) as f: | 107 with open(options.src_manifest) as f: |
| 101 main_manifest_data = f.read() | 108 main_manifest_data = f.read() |
| 102 new_manifest_data = _ProcessManifest(main_manifest_data, | 109 new_manifest_data = _ProcessManifest(main_manifest_data, |
| 103 options.disable_isolated_processes) | 110 options.disable_isolated_processes) |
| 104 with open(options.out_manifest, 'w') as f: | 111 with open(options.out_manifest, 'w') as f: |
| 105 f.write(new_manifest_data) | 112 f.write(new_manifest_data) |
| 106 | 113 |
| 107 if options.depfile: | 114 if options.depfile: |
| 108 deps = [options.src_manifest] | 115 deps = [options.src_manifest] |
| 109 build_utils.WriteDepfile(options.depfile, options.out_manifest, deps) | 116 build_utils.WriteDepfile(options.depfile, options.out_manifest, deps) |
| 110 | 117 |
| 111 | 118 |
| 112 if __name__ == '__main__': | 119 if __name__ == '__main__': |
| 113 main() | 120 main() |
| OLD | NEW |