2017-02-01 23:44:58 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2017 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
"""
|
|
|
|
Utility to generate the Android manifest file of runtime resource overlay
|
|
|
|
package for source module.
|
|
|
|
"""
|
|
|
|
from xml.dom.minidom import parseString
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
ANDROID_MANIFEST_TEMPLATE="""<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
2019-03-18 19:43:30 +08:00
|
|
|
package="%s.auto_generated_rro_%s__"
|
2017-02-01 23:44:58 +08:00
|
|
|
android:versionCode="1"
|
|
|
|
android:versionName="1.0">
|
2019-03-18 19:43:30 +08:00
|
|
|
<overlay android:targetPackage="%s" android:priority="%s" android:isStatic="true"/>
|
2017-02-01 23:44:58 +08:00
|
|
|
</manifest>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def get_args():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
'-u', '--use-package-name', action='store_true',
|
|
|
|
help='Indicate that --package-info is a package name.')
|
|
|
|
parser.add_argument(
|
|
|
|
'-p', '--package-info', required=True,
|
|
|
|
help='Manifest package name or manifest file path of source module.')
|
2019-03-18 19:43:30 +08:00
|
|
|
parser.add_argument(
|
|
|
|
'--partition', required=True,
|
|
|
|
help='The partition this RRO package is installed on.')
|
|
|
|
parser.add_argument(
|
|
|
|
'--priority', required=True,
|
|
|
|
help='The priority for the <overlay>.')
|
2017-02-01 23:44:58 +08:00
|
|
|
parser.add_argument(
|
|
|
|
'-o', '--output', required=True,
|
|
|
|
help='Output manifest file path.')
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
args = get_args()
|
|
|
|
|
2019-03-18 19:43:30 +08:00
|
|
|
partition = args.partition
|
|
|
|
priority = args.priority
|
2019-03-18 22:09:47 +08:00
|
|
|
if args.use_package_name:
|
|
|
|
package_name = args.package_info
|
|
|
|
else:
|
2017-02-01 23:44:58 +08:00
|
|
|
with open(args.package_info) as f:
|
|
|
|
data = f.read()
|
|
|
|
f.close()
|
|
|
|
dom = parseString(data)
|
|
|
|
package_name = dom.documentElement.getAttribute('package')
|
|
|
|
|
|
|
|
with open(args.output, 'w+') as f:
|
2019-03-18 19:43:30 +08:00
|
|
|
f.write(ANDROID_MANIFEST_TEMPLATE % (package_name, partition, package_name, priority))
|
2017-02-01 23:44:58 +08:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv)
|