diff options
author | David Brazdil <dbrazdil@google.com> | 2018-08-28 12:41:01 +0100 |
---|---|---|
committer | David Brazdil <dbrazdil@google.com> | 2018-08-28 12:41:01 +0100 |
commit | d5b74996be65b6628549c18b838b1d6cffc6231e (patch) | |
tree | e2f309c52f0e6903dd09650c7f8cef053aa1d310 /scripts/manifest_fixer.py | |
parent | 4bd15d36e75a783ed305a8bf1cc2e90fdfb3d3cf (diff) | |
download | build_soong-d5b74996be65b6628549c18b838b1d6cffc6231e.tar.gz build_soong-d5b74996be65b6628549c18b838b1d6cffc6231e.tar.bz2 build_soong-d5b74996be65b6628549c18b838b1d6cffc6231e.zip |
Support setting android:usesNonSdkApi in manifest_fixer.py
Add new command line flag to manifest_fixer.py which will add
'android:usesNonSdkApi="true"' attribute to the <application> tag.
Bug: 113315999
Test: build/soong/scripts/manifest_fixer.py
Change-Id: If030c90a4ced3f5c5176727c579a87d0ecab6cf8
Diffstat (limited to 'scripts/manifest_fixer.py')
-rwxr-xr-x | scripts/manifest_fixer.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/manifest_fixer.py b/scripts/manifest_fixer.py index 25f96cda..db35c8d3 100755 --- a/scripts/manifest_fixer.py +++ b/scripts/manifest_fixer.py @@ -53,6 +53,8 @@ def parse_args(): help='manifest is for a static library') parser.add_argument('--uses-library', dest='uses_libraries', action='append', help='specify additional <uses-library> tag to add') + parser.add_argument('--uses-non-sdk-api', dest='uses_non_sdk_api', action='store_true', + help='manifest is for a package built against the platform') parser.add_argument('input', help='input AndroidManifest.xml file') parser.add_argument('output', help='output AndroidManifest.xml file') return parser.parse_args() @@ -226,6 +228,33 @@ def add_uses_libraries(doc, new_uses_libraries): indent = get_indent(application.previousSibling, 1) application.appendChild(doc.createTextNode(indent)) +def add_uses_non_sdk_api(doc): + """Add android:usesNonSdkApi=true attribute to <application>. + + Args: + doc: The XML document. May be modified by this function. + Raises: + RuntimeError: Invalid manifest + """ + + manifest = parse_manifest(doc) + elems = get_children_with_tag(manifest, 'application') + application = elems[0] if len(elems) == 1 else None + if len(elems) > 1: + raise RuntimeError('found multiple <application> tags') + elif not elems: + application = doc.createElement('application') + indent = get_indent(manifest.firstChild, 1) + first = manifest.firstChild + manifest.insertBefore(doc.createTextNode(indent), first) + manifest.insertBefore(application, first) + + attr = application.getAttributeNodeNS(android_ns, 'usesNonSdkApi') + if attr is None: + attr = doc.createAttributeNS(android_ns, 'android:usesNonSdkApi') + attr.value = 'true' + application.setAttributeNode(attr) + def write_xml(f, doc): f.write('<?xml version="1.0" encoding="utf-8"?>\n') @@ -248,6 +277,9 @@ def main(): if args.uses_libraries: add_uses_libraries(doc, args.uses_libraries) + if args.uses_non_sdk_api: + add_uses_non_sdk_api(doc) + with open(args.output, 'wb') as f: write_xml(f, doc) |