From fa17afef53771ba04711827b85d109b31210c9f2 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Tue, 16 Oct 2018 11:00:04 +0900 Subject: [PATCH] android.test.{base|mock} are added as optional libraries. The two java shared libraries do not exist in the pre-P devices. Therefore, marking the dependencies to the libraries as optional so that an app is still installable to the old devices. This is safe because the classes in the java shared libs exist in other shared libraries (bootclasspath or android.test.runner). Bug: 113800422 Test: run aapt dump badging on the built GtsBackupHostTestCases uses-library tags for android.test.base|mock are with android:required=false, while the same tag for other libs are without the attribute. Change-Id: I266c8efb9686e8975be37f31aea0dc22f82370c3 --- scripts/manifest_fixer.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/manifest_fixer.py b/scripts/manifest_fixer.py index 05bd66ed9..9256cb29e 100755 --- a/scripts/manifest_fixer.py +++ b/scripts/manifest_fixer.py @@ -56,7 +56,9 @@ def parse_args(): parser.add_argument('--library', dest='library', action='store_true', help='manifest is for a static library') parser.add_argument('--uses-library', dest='uses_libraries', action='append', - help='specify additional tag to add') + help='specify additional tag to add. android:requred is set to true') + parser.add_argument('--optional-uses-library', dest='optional_uses_libraries', action='append', + help='specify additional tag to add. android:requred is set to false') 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') @@ -190,12 +192,13 @@ def raise_min_sdk_version(doc, min_sdk_version, target_sdk_version, library): element.setAttributeNode(target_attr) -def add_uses_libraries(doc, new_uses_libraries): - """Add additional tags with android:required=false. +def add_uses_libraries(doc, new_uses_libraries, required): + """Add additional tags Args: doc: The XML document. May be modified by this function. new_uses_libraries: The names of libraries to be added by this function. + required: The value of android:required attribute. Can be true or false. Raises: RuntimeError: Invalid manifest """ @@ -227,7 +230,7 @@ def add_uses_libraries(doc, new_uses_libraries): ul = doc.createElement('uses-library') ul.setAttributeNS(android_ns, 'android:name', name) - ul.setAttributeNS(android_ns, 'android:required', 'false') + ul.setAttributeNS(android_ns, 'android:required', str(required).lower()) application.insertBefore(doc.createTextNode(indent), last) application.insertBefore(ul, last) @@ -285,7 +288,10 @@ def main(): raise_min_sdk_version(doc, args.min_sdk_version, args.target_sdk_version, args.library) if args.uses_libraries: - add_uses_libraries(doc, args.uses_libraries) + add_uses_libraries(doc, args.uses_libraries, True) + + if args.optional_uses_libraries: + add_uses_libraries(doc, args.optional_uses_libraries, False) if args.uses_non_sdk_api: add_uses_non_sdk_api(doc)