Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ffdff85 authored by Paul Duffin's avatar Paul Duffin
Browse files

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
parent 8f34b0e1
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -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):
+5 −2
Original line number Diff line number Diff line
@@ -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)