| Jaekyun Seok | 3070610 | 2017-02-02 00:44:58 +0900 | [diff] [blame] | 1 | #!/usr/bin/env python | 
|  | 2 | # | 
|  | 3 | # Copyright (C) 2017 The Android Open Source Project | 
|  | 4 | # | 
|  | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 6 | # you may not use this file except in compliance with the License. | 
|  | 7 | # You may obtain a copy of the License at | 
|  | 8 | # | 
|  | 9 | #      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 10 | # | 
|  | 11 | # Unless required by applicable law or agreed to in writing, software | 
|  | 12 | # distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 14 | # See the License for the specific language governing permissions and | 
|  | 15 | # limitations under the License. | 
|  | 16 | """ | 
|  | 17 | Utility to generate the Android manifest file of runtime resource overlay | 
|  | 18 | package for source module. | 
|  | 19 | """ | 
|  | 20 | from xml.dom.minidom import parseString | 
|  | 21 | import argparse | 
|  | 22 | import os | 
|  | 23 | import sys | 
|  | 24 |  | 
|  | 25 | ANDROID_MANIFEST_TEMPLATE="""<manifest xmlns:android="http://schemas.android.com/apk/res/android" | 
| Anton Hansson | cb8276f | 2019-03-18 11:43:30 +0000 | [diff] [blame] | 26 | package="%s.auto_generated_rro_%s__" | 
| Jaekyun Seok | 3070610 | 2017-02-02 00:44:58 +0900 | [diff] [blame] | 27 | android:versionCode="1" | 
|  | 28 | android:versionName="1.0"> | 
| Anton Hansson | cb8276f | 2019-03-18 11:43:30 +0000 | [diff] [blame] | 29 | <overlay android:targetPackage="%s" android:priority="%s" android:isStatic="true"/> | 
| Jaekyun Seok | 3070610 | 2017-02-02 00:44:58 +0900 | [diff] [blame] | 30 | </manifest> | 
|  | 31 | """ | 
|  | 32 |  | 
|  | 33 |  | 
|  | 34 | def get_args(): | 
|  | 35 | parser = argparse.ArgumentParser() | 
|  | 36 | parser.add_argument( | 
|  | 37 | '-u', '--use-package-name', action='store_true', | 
|  | 38 | help='Indicate that --package-info is a package name.') | 
|  | 39 | parser.add_argument( | 
|  | 40 | '-p', '--package-info', required=True, | 
|  | 41 | help='Manifest package name or manifest file path of source module.') | 
|  | 42 | parser.add_argument( | 
| Anton Hansson | cb8276f | 2019-03-18 11:43:30 +0000 | [diff] [blame] | 43 | '--partition', required=True, | 
|  | 44 | help='The partition this RRO package is installed on.') | 
|  | 45 | parser.add_argument( | 
|  | 46 | '--priority', required=True, | 
|  | 47 | help='The priority for the <overlay>.') | 
|  | 48 | parser.add_argument( | 
| Jaekyun Seok | 3070610 | 2017-02-02 00:44:58 +0900 | [diff] [blame] | 49 | '-o', '--output', required=True, | 
|  | 50 | help='Output manifest file path.') | 
|  | 51 | return parser.parse_args() | 
|  | 52 |  | 
|  | 53 |  | 
|  | 54 | def main(argv): | 
|  | 55 | args = get_args() | 
|  | 56 |  | 
| Anton Hansson | cb8276f | 2019-03-18 11:43:30 +0000 | [diff] [blame] | 57 | partition = args.partition | 
|  | 58 | priority = args.priority | 
| Anton Hansson | 08231e1 | 2019-03-18 14:09:47 +0000 | [diff] [blame] | 59 | if args.use_package_name: | 
|  | 60 | package_name = args.package_info | 
|  | 61 | else: | 
| Jaekyun Seok | 3070610 | 2017-02-02 00:44:58 +0900 | [diff] [blame] | 62 | with open(args.package_info) as f: | 
|  | 63 | data = f.read() | 
|  | 64 | f.close() | 
|  | 65 | dom = parseString(data) | 
|  | 66 | package_name = dom.documentElement.getAttribute('package') | 
|  | 67 |  | 
|  | 68 | with open(args.output, 'w+') as f: | 
| Anton Hansson | cb8276f | 2019-03-18 11:43:30 +0000 | [diff] [blame] | 69 | f.write(ANDROID_MANIFEST_TEMPLATE % (package_name, partition, package_name, priority)) | 
| Jaekyun Seok | 3070610 | 2017-02-02 00:44:58 +0900 | [diff] [blame] | 70 | f.close() | 
|  | 71 |  | 
|  | 72 |  | 
|  | 73 | if __name__ == "__main__": | 
|  | 74 | main(sys.argv) |