aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Faust <colefaust@google.com>2021-08-31 16:56:07 -0700
committerRam Parameswaran <rampara@google.com>2021-10-20 20:57:04 +0000
commitd9e95cb7f2aae6a5fc151d34d8c10eb5f2f9d5d5 (patch)
tree8c8bf63883063689b7e029ff3ea3d51017a9a8b1
parent417642546b0595d50ea6a2fffff0fda16c3a7521 (diff)
downloadtests-d9e95cb7f2aae6a5fc151d34d8c10eb5f2f9d5d5.tar.gz
Add generate-overlays.pyandroid12L-dev
Similar to generate-overlayable.py, but for the <overlay> entry. This assumes that the resources that the RRO uses to replace app resources are named exactly the same as the app's resources. The user can also supply the app's res folder to the script, in which case it will know to ignore any resources that are not also present in the app. Fixes: 169707403 Test: Manually Change-Id: I33340f8f711fefa0166c7d775881eab82d1f8907 (cherry picked from commit 38cb3702eda83b7977e78690a635b8a7079e2caf) Merged-In: I33340f8f711fefa0166c7d775881eab82d1f8907
-rwxr-xr-xtools/rro/generate-overlays.py80
-rw-r--r--tools/rro/resource_utils.py55
2 files changed, 135 insertions, 0 deletions
diff --git a/tools/rro/generate-overlays.py b/tools/rro/generate-overlays.py
new file mode 100755
index 0000000..5ba4cda
--- /dev/null
+++ b/tools/rro/generate-overlays.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python3
+# Copyright (C) 2021 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.
+
+import argparse
+import sys
+from resource_utils import get_all_resources, get_androidx_resources, Resource
+from datetime import datetime
+import lxml.etree as etree
+if sys.version_info[0] != 3:
+ print("Must use python 3")
+ sys.exit(1)
+
+COPYRIGHT_STR = """ Copyright (C) %s 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.""" % (datetime.today().strftime("%Y"))
+
+AUTOGENERATION_NOTICE_STR = """
+THIS FILE WAS AUTO GENERATED, DO NOT EDIT MANUALLY.
+REGENERATE USING packages/apps/Car/tests/tools/rro/generate-overlays.py
+"""
+
+"""
+Script used to update the 'overlayable.xml' file.
+"""
+def main():
+ parser = argparse.ArgumentParser(description="Generate overlayable.xml. This script assumes that all the RRO resources have the exact same name as the app resource they're overlaying.")
+ parser.add_argument('-o', '--outputFile', default='', help='Output file path. If empty, output to stdout')
+ parser.add_argument('-a', '--appResources', help="Path to the app's resource folder. If given, will be used to exclude any rro-specific resources from overlays.xml.")
+ required_args = parser.add_argument_group('Required arguments')
+ required_args.add_argument('-r', '--resourcePath', help="Path to the RRO's resource directory", required=True)
+ args = parser.parse_args()
+
+ resources = get_all_resources(args.resourcePath)
+ try:
+ resources.remove(Resource('overlays', 'xml'))
+ except KeyError:
+ pass
+
+ if args.appResources:
+ resources = resources.intersection(
+ get_all_resources(args.appResources).union(get_androidx_resources()))
+ generate_overlays_file(resources, args.outputFile)
+
+def generate_overlays_file(resources, output_file):
+ resources = sorted(resources, key=lambda x: x.type + x.name)
+ root = etree.Element('overlay')
+ root.addprevious(etree.Comment(COPYRIGHT_STR))
+ root.addprevious(etree.Comment(AUTOGENERATION_NOTICE_STR))
+ for resource in resources:
+ item = etree.SubElement(root, 'item')
+ item.set('target', f'{resource.type}/{resource.name}')
+ item.set('value', f'@{resource.type}/{resource.name}')
+ rootTree = etree.ElementTree(root)
+ if not output_file:
+ print(etree.tostring(rootTree, pretty_print=True, xml_declaration=True).decode())
+ else:
+ with open(output_file, 'wb') as f:
+ rootTree.write(f, pretty_print=True, xml_declaration=True, encoding='utf-8')
+
+if __name__ == '__main__':
+ main()
diff --git a/tools/rro/resource_utils.py b/tools/rro/resource_utils.py
index 11e8edc..5f35e1a 100644
--- a/tools/rro/resource_utils.py
+++ b/tools/rro/resource_utils.py
@@ -149,3 +149,58 @@ def add_resource_to_set(resourceset, resource):
def merge_resources(set1, set2):
for resource in set2:
add_resource_to_set(set1, resource)
+
+def get_androidx_resources():
+ # source: https://android.googlesource.com/platform/frameworks/opt/sherpa/+/studio-3.0/constraintlayout/src/main/res/values/attrs.xml
+ resources = set()
+ add_resource_to_set(resources, Resource('layout_optimizationLevel', 'attr'))
+ add_resource_to_set(resources, Resource('constraintSet', 'attr'))
+ add_resource_to_set(resources, Resource('barrierDirection', 'attr'))
+ add_resource_to_set(resources, Resource('constraint_referenced_ids', 'attr'))
+ add_resource_to_set(resources, Resource('chainUseRtl', 'attr'))
+ add_resource_to_set(resources, Resource('title', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintGuide_begin', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintGuide_end', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintGuide_percent', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintLeft_toLeftOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintLeft_toRightOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintRight_toLeftOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintRight_toRightOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintTop_toTopOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintTop_toBottomOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintBottom_toTopOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintBottom_toBottomOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintBaseline_toBaselineOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintStart_toEndOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintStart_toStartOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintEnd_toStartOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintEnd_toEndOf', 'attr'))
+ add_resource_to_set(resources, Resource('layout_goneMarginLeft', 'attr'))
+ add_resource_to_set(resources, Resource('layout_goneMarginTop', 'attr'))
+ add_resource_to_set(resources, Resource('layout_goneMarginRight', 'attr'))
+ add_resource_to_set(resources, Resource('layout_goneMarginBottom', 'attr'))
+ add_resource_to_set(resources, Resource('layout_goneMarginStart', 'attr'))
+ add_resource_to_set(resources, Resource('layout_goneMarginEnd', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintHorizontal_bias', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintVertical_bias', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintWidth_default', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintHeight_default', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintWidth_min', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintWidth_max', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintWidth_percent', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintHeight_min', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintHeight_max', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintHeight_percent', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintLeft_creator', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintTop_creator', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintRight_creator', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintBottom_creator', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintBaseline_creator', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintDimensionRatio', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintHorizontal_weight', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintVertical_weight', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintHorizontal_chainStyle', 'attr'))
+ add_resource_to_set(resources, Resource('layout_constraintVertical_chainStyle', 'attr'))
+ add_resource_to_set(resources, Resource('layout_editor_absoluteX', 'attr'))
+ add_resource_to_set(resources, Resource('layout_editor_absoluteY', 'attr'))
+ return resources