1# Copyright (C) 2024 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import re 16import os 17 18""" 19Script used to filter a file for public static final string values that match the provided format. 20""" 21def filter_javadoc_fields(file_path, format, exclude_hidden): 22 try: 23 with open(file_path, 'r') as file: 24 content = file.read() 25 26 pattern = fr'/\*\*(.*?)\*/\s*(.*?)public static final String\s+({format}\w+)\s*=\s*"(.*?)";' 27 matches = re.findall(pattern, content, re.DOTALL) 28 results = [] 29 30 for match in matches: 31 java_doc, tag, field_name, value = match 32 if (exclude_hidden and "@hide" not in java_doc) or not exclude_hidden: 33 results.append(value) 34 return results 35 36 except FileNotFoundError: 37 print(f"Error: File '{file_path}' not found.") 38 except Exception as e: 39 print(f"An error occurred: {e}") 40 41def main(): 42 file_path = os.environ.get('ANDROID_BUILD_TOP') + '/frameworks/base/core/java/android/provider/Settings.java' 43 results = filter_javadoc_fields(file_path, "ACTION_", True) 44 45if __name__ == '__main__': 46 main() 47