summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2021-08-09 13:47:19 +0100
committer Paul Duffin <paulduffin@google.com> 2021-08-10 14:01:51 +0100
commit6ffdff853cdad69e4067cd014a5984303a3692ef (patch)
tree45f71c95659ecaf2e652e869a5ac265ffb050f9b
parent8f34b0e19d4bbfee7a904793ffdf17e43988f575 (diff)
Remove member signature and inner classes from signature-patterns.csv
Previously, the signature-patterns.csv file included a lot of implementation details, e.g. the signatures of dex members or inner classes that are not part of any API, including the hidden API. This change will remove all member signatures and inner class names from the file and replace them with just the outermost qualified class name. That will still leave some implementation details, e.g. the names of implementation only classes and packages. Bug: 194063708 Test: atest --host verify_overlaps_test signature_patterns_test m out/soong/hiddenapi/hiddenapi-flags.csv - manually change files to cause difference in flags to check that it detects the differences. Change-Id: I9de6a2a6129e875e19f7ded5fae578cbdb584660
-rwxr-xr-xscripts/hiddenapi/signature_patterns.py18
-rwxr-xr-xscripts/hiddenapi/signature_patterns_test.py7
2 files changed, 19 insertions, 6 deletions
diff --git a/scripts/hiddenapi/signature_patterns.py b/scripts/hiddenapi/signature_patterns.py
index 91328e60f..a7c5bb4f3 100755
--- a/scripts/hiddenapi/signature_patterns.py
+++ b/scripts/hiddenapi/signature_patterns.py
@@ -30,11 +30,21 @@ def produce_patterns_from_file(file):
return produce_patterns_from_stream(f)
def produce_patterns_from_stream(stream):
- patterns = []
- allFlagsReader = dict_reader(stream)
- for row in allFlagsReader:
+ # Read in all the signatures into a list and remove member names.
+ patterns = set()
+ for row in dict_reader(stream):
signature = row['signature']
- patterns.append(signature)
+ text = signature.removeprefix("L")
+ # Remove the class specific member signature
+ pieces = text.split(";->")
+ qualifiedClassName = pieces[0]
+ # Remove inner class names as they cannot be separated from the containing outer class.
+ pieces = qualifiedClassName.split("$", maxsplit=1)
+ pattern = pieces[0]
+ patterns.add(pattern)
+
+ patterns = list(patterns)
+ patterns.sort()
return patterns
def main(args):
diff --git a/scripts/hiddenapi/signature_patterns_test.py b/scripts/hiddenapi/signature_patterns_test.py
index 83c9db29c..0431f4501 100755
--- a/scripts/hiddenapi/signature_patterns_test.py
+++ b/scripts/hiddenapi/signature_patterns_test.py
@@ -28,12 +28,15 @@ class TestGeneratedPatterns(unittest.TestCase):
def test_generate(self):
patterns = self.produce_patterns_from_string('''
+Ljava/lang/ProcessBuilder$Redirect$1;-><init>()V,blocked
+Ljava/lang/Character$UnicodeScript;->of(I)Ljava/lang/Character$UnicodeScript;,public-api
Ljava/lang/Object;->hashCode()I,public-api,system-api,test-api
Ljava/lang/Object;->toString()Ljava/lang/String;,blocked
''')
expected = [
- "Ljava/lang/Object;->hashCode()I",
- "Ljava/lang/Object;->toString()Ljava/lang/String;",
+ "java/lang/Character",
+ "java/lang/Object",
+ "java/lang/ProcessBuilder",
]
self.assertEqual(expected, patterns)