• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"""
17Utility to generate the Android manifest file of runtime resource overlay
18package for source module.
19"""
20from xml.dom.minidom import parseString
21import argparse
22import os
23import sys
24
25ANDROID_MANIFEST_TEMPLATE="""<manifest xmlns:android="http://schemas.android.com/apk/res/android"
26    package="%s.auto_generated_rro_%s__"
27    android:versionCode="1"
28    android:versionName="1.0">
29    <overlay android:targetPackage="%s" android:priority="%s" android:isStatic="true"/>
30</manifest>
31"""
32
33
34def 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(
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(
49        '-o', '--output', required=True,
50        help='Output manifest file path.')
51    return parser.parse_args()
52
53
54def main(argv):
55  args = get_args()
56
57  partition = args.partition
58  priority = args.priority
59  if args.use_package_name:
60    package_name = args.package_info
61  else:
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:
69    f.write(ANDROID_MANIFEST_TEMPLATE % (package_name, partition, package_name, priority))
70    f.close()
71
72
73if __name__ == "__main__":
74  main(sys.argv)
75