diff options
author | 2024-09-11 13:28:16 -0700 | |
---|---|---|
committer | 2024-09-13 11:20:21 -0700 | |
commit | e1ab849b391c6d5c7fbf57310701c99cad88ba21 (patch) | |
tree | 558714e1e6952e7c6509e36b5d259e153b655c52 /scripts/manifest.py | |
parent | 6cb462b38c07507e0fc1518762ac2b579a3ede8c (diff) |
Support multiple <application> or <uses-sdk> elements in manifest_*.py
Manifests may now have multiple copies of elements if they are
disambiguated with android:featureFlag attributes. Remove the
restrictions on duplicate elements from manifest_check.py and
manifest_fixer.py, and instead iterate over all matching elements.
Test: manifest_check_test.py, manifest_fixer_test.py
Bug: 365170653
Flag: EXEMPT bugfix
Change-Id: Ib577439d03a808a20a5fcc3e15a3117e0970d729
Diffstat (limited to 'scripts/manifest.py')
-rwxr-xr-x | scripts/manifest.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/manifest.py b/scripts/manifest.py index 8cd53dfc4..32603e869 100755 --- a/scripts/manifest.py +++ b/scripts/manifest.py @@ -23,6 +23,37 @@ from xml.dom import minidom android_ns = 'http://schemas.android.com/apk/res/android' +def get_or_create_applications(doc, manifest): + """Get all <application> tags from the manifest, or create one if none exist. + Multiple <application> tags may exist when manifest feature flagging is used. + """ + applications = get_children_with_tag(manifest, 'application') + if len(applications) == 0: + application = doc.createElement('application') + indent = get_indent(manifest.firstChild, 1) + first = manifest.firstChild + manifest.insertBefore(doc.createTextNode(indent), first) + manifest.insertBefore(application, first) + applications.append(application) + return applications + + +def get_or_create_uses_sdks(doc, manifest): + """Get all <uses-sdk> tags from the manifest, or create one if none exist. + Multiple <uses-sdk> tags may exist when manifest feature flagging is used. + """ + uses_sdks = get_children_with_tag(manifest, 'uses-sdk') + if len(uses_sdks) == 0: + uses_sdk = doc.createElement('uses-sdk') + indent = get_indent(manifest.firstChild, 1) + manifest.insertBefore(uses_sdk, manifest.firstChild) + + # Insert an indent before uses-sdk to line it up with the indentation of the + # other children of the <manifest> tag. + manifest.insertBefore(doc.createTextNode(indent), manifest.firstChild) + uses_sdks.append(uses_sdk) + return uses_sdks + def get_children_with_tag(parent, tag_name): children = [] for child in parent.childNodes: |