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

Commit 8f273069 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add more information in the filter reason" into main

parents b31c65d8 5748fde3
Loading
Loading
Loading
Loading
+40 −33
Original line number Diff line number Diff line
@@ -49,14 +49,12 @@ fun printAsTextPolicy(pw: PrintWriter, cn: ClassNode) {
    }
}

/** "Reason" string for policies set by a policy file. */
private const val FILTER_REASON = "file-override"
private const val FILTER_REASON_BASE = "file-override"

/**
 * "file-override" + an inline comment string (in the policy file).
 */
private fun reasonWithComment(inlineComment: String): String {
    return if (inlineComment.isEmpty()) { FILTER_REASON } else {"$FILTER_REASON ($inlineComment)" }
private fun reason(description: String, inlineComment: String = ""): String {
    val baseReason = "$FILTER_REASON_BASE [$description]"

    return if (inlineComment.isEmpty()) { baseReason } else {"$baseReason (#$inlineComment)" }
}

enum class SpecialClass {
@@ -150,7 +148,8 @@ class TextFileFilterPolicyBuilder(
    val annotationAllowedMembersFilter: OutputFilter
        get() = annotationAllowedInMemoryFilter

    private val annotationAllowedPolicy = FilterPolicy.AnnotationAllowed.withReason(FILTER_REASON)
    private val annotationAllowedPolicy = FilterPolicy.AnnotationAllowed.withReason(
        "text-policy")

    init {
        // Create a filter that checks "partial allowlisting".
@@ -280,7 +279,8 @@ class TextFileFilterPolicyBuilder(
                className,
                targetName,
                methodDesc,
                FilterPolicy.Keep.withReason(reasonWithComment(parser.currentInlineComment))
                FilterPolicy.Keep.withReason(
                    "in-class-replace - ${policy.reason}")
            )
            // Set up the rename.
            imf.setRenameTo(className, targetName, methodDesc, methodName)
@@ -294,7 +294,8 @@ class TextFileFilterPolicyBuilder(
        ) {
            // Keep the source method, because the target method may call it.
            imf.setPolicyForMethod(className, methodName, methodDesc,
                FilterPolicy.Keep.withReason(reasonWithComment(parser.currentInlineComment)))
                FilterPolicy.Keep.withReason(
                    reason("out-class-replace", parser.currentInlineComment)))
            imf.setMethodCallReplaceSpec(replaceSpec)
        }
    }
@@ -460,7 +461,8 @@ class TextFileFilterPolicyParser {
        if (!policy.isUsableWithClasses) {
            throw ParseException("Package can't have policy '$policy'")
        }
        processor.onPackage(name, policy.withReason(reasonWithComment(currentInlineComment)))
        processor.onPackage(name, policy.withReason(
            reason("package - '$rawPolicy'", currentInlineComment)))
    }

    private fun parseClass(fields: Array<String>) {
@@ -475,9 +477,9 @@ class TextFileFilterPolicyParser {
        // :aidl, etc?
        val classType = resolveSpecialClass(className)

        val policyStr = if (fields.size > 2) { fields[2] } else { "" }
        val rawPolicy = if (fields.size > 2) { fields[2] } else { "" }

        if (policyStr.startsWith("!")) {
        if (rawPolicy.startsWith("!")) {
            if (classType != SpecialClass.NotSpecial) {
                // We could support it, but not needed at least for now.
                throw ParseException(
@@ -485,12 +487,12 @@ class TextFileFilterPolicyParser {
                )
            }
            // It's a redirection class.
            val toClass = policyStr.substring(1)
            val toClass = rawPolicy.substring(1)

            currentClassName = className
            processor.onClassStart(className)
            processor.onRedirectionClass(className, toClass)
        } else if (policyStr.startsWith("~")) {
        } else if (rawPolicy.startsWith("~")) {
            if (classType != SpecialClass.NotSpecial) {
                // We could support it, but not needed at least for now.
                throw ParseException(
@@ -498,7 +500,7 @@ class TextFileFilterPolicyParser {
                )
            }
            // It's a class-load hook
            val callback = policyStr.substring(1)
            val callback = rawPolicy.substring(1)

            currentClassName = className
            processor.onClassStart(className)
@@ -507,7 +509,7 @@ class TextFileFilterPolicyParser {
            // Special case: if it's a class directive with no policy, then it encloses
            // members, but we don't apply any policy to the class itself.
            // This is only allowed in a not-special case.
            if (policyStr == "") {
            if (rawPolicy == "") {
                if (classType == SpecialClass.NotSpecial && superClass == null) {
                    currentClassName = className
                    return
@@ -515,7 +517,7 @@ class TextFileFilterPolicyParser {
                throw ParseException("Special class or subclass directive must have a policy")
            }

            val policy = parsePolicy(policyStr)
            val policy = parsePolicy(rawPolicy)
            if (!policy.isUsableWithClasses) {
                throw ParseException("Class can't have policy '$policy'")
            }
@@ -527,11 +529,13 @@ class TextFileFilterPolicyParser {
                        currentClassName = className
                        processor.onClassStart(className)
                        processor.onSimpleClassPolicy(className,
                            policy.withReason(reasonWithComment(currentInlineComment)))
                            policy.withReason(
                                reason("class - '$rawPolicy'", currentInlineComment)))
                    } else {
                        processor.onSubClassPolicy(
                            superClass,
                            policy.withReason("extends $superClass"),
                            policy.withReason(
                                reason("subclass of $superClass - '$rawPolicy'", currentInlineComment)),
                        )
                    }
                }
@@ -542,7 +546,7 @@ class TextFileFilterPolicyParser {
                        )
                    }
                    val p = policy.withReason(
                        "$FILTER_REASON (special-class AIDL)",
                        reason("special-class: AIDL - '$rawPolicy'", currentInlineComment),
                        StatsLabel.SupportedButBoring,
                    )
                    processor.onSpecialClassPolicy(classType, p)
@@ -556,7 +560,7 @@ class TextFileFilterPolicyParser {
                        )
                    }
                    val p = policy.withReason(
                        "$FILTER_REASON (special-class feature flags)",
                        reason("special-class: flags - '$rawPolicy'", currentInlineComment),
                        StatsLabel.SupportedButBoring,
                    )
                    processor.onSpecialClassPolicy(classType, p)
@@ -570,7 +574,7 @@ class TextFileFilterPolicyParser {
                        )
                    }
                    val p = policy.withReason(
                        "$FILTER_REASON (special-class sysprops)",
                        reason("special-class: sysprops - '$rawPolicy'", currentInlineComment),
                        StatsLabel.SupportedButBoring,
                    )
                    processor.onSpecialClassPolicy(classType, p)
@@ -584,7 +588,7 @@ class TextFileFilterPolicyParser {
                        )
                    }
                    val p = policy.withReason(
                        "$FILTER_REASON (special-class R file)",
                        reason("special-class: R - '$rawPolicy'", currentInlineComment),
                        StatsLabel.SupportedButBoring,
                    )
                    processor.onSpecialClassPolicy(classType, p)
@@ -599,14 +603,16 @@ class TextFileFilterPolicyParser {
            throw ParseException("Field ('f') expects 2 fields.")
        }
        val name = fields[1]
        val policy = parsePolicy(fields[2])
        val rawPolicy = fields[2]
        val policy = parsePolicy(rawPolicy)
        if (!policy.isUsableWithFields) {
            throw ParseException("Field can't have policy '$policy'")
        }

        // TODO: Duplicate check, etc
        processor.onField(currentClassName!!, name,
            policy.withReason(reasonWithComment(currentInlineComment)))
            policy.withReason(
                reason("field - '$rawPolicy'", currentInlineComment)))
    }

    private fun parseMethod(fields: Array<String>) {
@@ -615,16 +621,16 @@ class TextFileFilterPolicyParser {
        }
        val methodName = fields[1]
        val signature: String
        val policyStr: String
        val rawPolicy: String
        if (fields.size <= 3) {
            signature = "*"
            policyStr = fields[2]
            rawPolicy = fields[2]
        } else {
            signature = fields[2]
            policyStr = fields[3]
            rawPolicy = fields[3]
        }

        val policy = parsePolicy(policyStr)
        val policy = parsePolicy(rawPolicy)

        if (!policy.isUsableWithMethods) {
            throw ParseException("Method can't have policy '$policy'")
@@ -632,11 +638,12 @@ class TextFileFilterPolicyParser {

        val className = currentClassName!!

        val policyWithReason = policy.withReason(reasonWithComment(currentInlineComment))
        val policyWithReason = policy.withReason(
            reason("method - '$rawPolicy'", currentInlineComment))
        if (policy != FilterPolicy.Substitute) {
            processor.onSimpleMethodPolicy(className, methodName, signature, policyWithReason)
        } else {
            val targetName = policyStr.substring(1)
            val targetName = rawPolicy.substring(1)

            if (targetName == methodName) {
                throw ParseException(
+71 −71

File changed.

Preview size limit exceeded, changes collapsed.

+39 −39
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ com.android.hoststubgen.test.tinyframework
  <init>()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl [inner-reason: file-override (special-class AIDL)]]
  class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl [inner-reason: file-override [special-class: AIDL - 'keepclass']]]
  1
  1
com.android.hoststubgen.test.tinyframework
@@ -28,7 +28,7 @@ com.android.hoststubgen.test.tinyframework
  addOne(I)I
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl [inner-reason: file-override (special-class AIDL)]]
  class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl [inner-reason: file-override [special-class: AIDL - 'keepclass']]]
  1
  1
com.android.hoststubgen.test.tinyframework
@@ -39,7 +39,7 @@ com.android.hoststubgen.test.tinyframework
  <init>()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub$Proxy [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl [inner-reason: file-override (special-class AIDL)]]]
  class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub$Proxy [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl [inner-reason: file-override [special-class: AIDL - 'keepclass']]]]
  1
  1
com.android.hoststubgen.test.tinyframework
@@ -50,7 +50,7 @@ com.android.hoststubgen.test.tinyframework
  addTwo(I)I
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub$Proxy [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl [inner-reason: file-override (special-class AIDL)]]]
  class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub$Proxy [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl$Stub [inner-reason: class-wide in com/android/hoststubgen/test/tinyframework/IPretendingAidl [inner-reason: file-override [special-class: AIDL - 'keepclass']]]]
  1
  1
com.android.hoststubgen.test.tinyframework
@@ -61,7 +61,7 @@ com.android.hoststubgen.test.tinyframework
  <init>()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/R [inner-reason: file-override (special-class R file)]
  class-wide in com/android/hoststubgen/test/tinyframework/R [inner-reason: file-override [special-class: R - 'keepclass']]
  1
  1
com.android.hoststubgen.test.tinyframework
@@ -72,7 +72,7 @@ com.android.hoststubgen.test.tinyframework
  <clinit>()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/R$Nested [inner-reason: file-override (special-class R file)]
  class-wide in com/android/hoststubgen/test/tinyframework/R$Nested [inner-reason: file-override [special-class: R - 'keepclass']]
  1
  1
com.android.hoststubgen.test.tinyframework
@@ -83,7 +83,7 @@ com.android.hoststubgen.test.tinyframework
  <init>()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/R$Nested [inner-reason: file-override (special-class R file)]
  class-wide in com/android/hoststubgen/test/tinyframework/R$Nested [inner-reason: file-override [special-class: R - 'keepclass']]
  1
  1
com.android.hoststubgen.test.tinyframework
@@ -325,7 +325,7 @@ com.android.hoststubgen.test.tinyframework
  <init>()V
  0
  Experimental
  class-wide in com/android/hoststubgen/test/tinyframework/TinyFrameworkExperimental [inner-reason: file-override]
  class-wide in com/android/hoststubgen/test/tinyframework/TinyFrameworkExperimental [inner-reason: file-override [class - 'experimental']]
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -369,7 +369,7 @@ com.android.hoststubgen.test.tinyframework
  simple()V
  0
  Experimental
  class-wide in com/android/hoststubgen/test/tinyframework/TinyFrameworkExperimental [inner-reason: file-override]
  class-wide in com/android/hoststubgen/test/tinyframework/TinyFrameworkExperimental [inner-reason: file-override [class - 'experimental']]
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -380,7 +380,7 @@ com.android.hoststubgen.test.tinyframework
  unsupported()V
  0
  Experimental
  file-override
  file-override [method - 'experimental']
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -391,7 +391,7 @@ com.android.hoststubgen.test.tinyframework
  <clinit>()V
  1
  Keep
  file-override (Keep static initializer)
  file-override [method - 'keep'] (#Keep static initializer)
  1
  1
com.android.hoststubgen.test.tinyframework
@@ -402,7 +402,7 @@ com.android.hoststubgen.test.tinyframework
  <init>()V
  1
  Keep
  file-override (Keep implicit ctor)
  file-override [method - 'keep'] (#Keep implicit ctor)
  1
  1
com.android.hoststubgen.test.tinyframework
@@ -413,7 +413,7 @@ com.android.hoststubgen.test.tinyframework
  foo(Ljava/lang/String;Ljava/lang/Object;)V
  1
  Keep
  file-override (keep multi-arg method)
  file-override [method - 'keep'] (#keep multi-arg method)
  0
  2
com.android.hoststubgen.test.tinyframework
@@ -424,7 +424,7 @@ com.android.hoststubgen.test.tinyframework
  bar()V
  1
  Keep
  file-override
  file-override [method - 'keep']
  0
  2
com.android.hoststubgen.test.tinyframework
@@ -435,7 +435,7 @@ com.android.hoststubgen.test.tinyframework
  baz()V
  1
  Keep
  file-override
  file-override [method - 'keep']
  0
  2
com.android.hoststubgen.test.tinyframework
@@ -446,7 +446,7 @@ com.android.hoststubgen.test.tinyframework
  <init>()V
  1
  Keep
  file-override (test keep policy on ctor)
  file-override [method - 'keep'] (#test keep policy on ctor)
  1
  1
com.android.hoststubgen.test.tinyframework
@@ -457,7 +457,7 @@ com.android.hoststubgen.test.tinyframework
  addFour(I)I
  0
  Experimental
  file-override
  file-override [method - 'experimental']
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -468,7 +468,7 @@ com.android.hoststubgen.test.tinyframework
  addOne(I)I
  1
  Keep
  file-override (test keep policy on method)
  file-override [method - 'keep'] (#test keep policy on method)
  0
  2
com.android.hoststubgen.test.tinyframework
@@ -479,7 +479,7 @@ com.android.hoststubgen.test.tinyframework
  nativeAddThree(I)I
  1
  Keep
  file-override
  in-class-replace - file-override [method - '@addThree_host']
  0
  2
com.android.hoststubgen.test.tinyframework
@@ -490,7 +490,7 @@ com.android.hoststubgen.test.tinyframework
  addTwo(I)I
  1
  Substitute
  file-override
  file-override [method - '@addTwo_host']
  0
  2
com.android.hoststubgen.test.tinyframework
@@ -501,7 +501,7 @@ com.android.hoststubgen.test.tinyframework
  addTwo(I)I
  1
  Keep
  file-override
  in-class-replace - file-override [method - '@addTwo_host']
  0
  2
com.android.hoststubgen.test.tinyframework
@@ -512,7 +512,7 @@ com.android.hoststubgen.test.tinyframework
  nativeAddThree(I)I
  1
  Substitute
  file-override
  file-override [method - '@addThree_host']
  0
  2
com.android.hoststubgen.test.tinyframework
@@ -523,7 +523,7 @@ com.android.hoststubgen.test.tinyframework
  toBeIgnoredB()B
  0
  Ignore
  file-override
  file-override [method - 'ignore']
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -534,7 +534,7 @@ com.android.hoststubgen.test.tinyframework
  toBeIgnoredC()C
  0
  Ignore
  file-override
  file-override [method - 'ignore']
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -545,7 +545,7 @@ com.android.hoststubgen.test.tinyframework
  toBeIgnoredD()D
  0
  Ignore
  file-override
  file-override [method - 'ignore']
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -556,7 +556,7 @@ com.android.hoststubgen.test.tinyframework
  toBeIgnoredF()F
  0
  Ignore
  file-override
  file-override [method - 'ignore']
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -567,7 +567,7 @@ com.android.hoststubgen.test.tinyframework
  toBeIgnoredI()I
  0
  Ignore
  file-override
  file-override [method - 'ignore']
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -578,7 +578,7 @@ com.android.hoststubgen.test.tinyframework
  toBeIgnoredObj()Ljava/lang/String;
  0
  Ignore
  file-override
  file-override [method - 'ignore']
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -589,7 +589,7 @@ com.android.hoststubgen.test.tinyframework
  toBeIgnoredS()S
  0
  Ignore
  file-override
  file-override [method - 'ignore']
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -600,7 +600,7 @@ com.android.hoststubgen.test.tinyframework
  toBeIgnoredV()V
  0
  Ignore
  file-override (test ignore policy)
  file-override [method - 'ignore'] (#test ignore policy)
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -611,7 +611,7 @@ com.android.hoststubgen.test.tinyframework
  toBeIgnoredZ()Z
  0
  Ignore
  file-override
  file-override [method - 'ignore']
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -622,7 +622,7 @@ com.android.hoststubgen.test.tinyframework
  unsupportedMethod()Ljava/lang/String;
  0
  Throw
  file-override
  file-override [method - 'throw']
  0
  0
com.android.hoststubgen.test.tinyframework
@@ -1282,7 +1282,7 @@ com.android.hoststubgen.test.tinyframework.exp
  <init>()V
  0
  Experimental
  class-wide in com/android/hoststubgen/test/tinyframework/exp/A [inner-reason: file-override (test-package-policy)]
  class-wide in com/android/hoststubgen/test/tinyframework/exp/A [inner-reason: file-override [package - 'experimental'] (#test-package-policy)]
  0
  0
com.android.hoststubgen.test.tinyframework.exp
@@ -1293,7 +1293,7 @@ com.android.hoststubgen.test.tinyframework.exp
  foo()V
  0
  Experimental
  class-wide in com/android/hoststubgen/test/tinyframework/exp/A [inner-reason: file-override (test-package-policy)]
  class-wide in com/android/hoststubgen/test/tinyframework/exp/A [inner-reason: file-override [package - 'experimental'] (#test-package-policy)]
  0
  0
com.android.hoststubgen.test.tinyframework.exp
@@ -1326,7 +1326,7 @@ com.android.hoststubgen.test.tinyframework.exp.sub
  <init>()V
  0
  Experimental
  class-wide in com/android/hoststubgen/test/tinyframework/exp/sub/A [inner-reason: file-override (test-package-policy)]
  class-wide in com/android/hoststubgen/test/tinyframework/exp/sub/A [inner-reason: file-override [package - 'experimental'] (#test-package-policy)]
  0
  0
com.android.hoststubgen.test.tinyframework.exp.sub
@@ -1337,7 +1337,7 @@ com.android.hoststubgen.test.tinyframework.exp.sub
  foo()V
  0
  Experimental
  class-wide in com/android/hoststubgen/test/tinyframework/exp/sub/A [inner-reason: file-override (test-package-policy)]
  class-wide in com/android/hoststubgen/test/tinyframework/exp/sub/A [inner-reason: file-override [package - 'experimental'] (#test-package-policy)]
  0
  0
com.android.hoststubgen.test.tinyframework.packagetest
@@ -1348,7 +1348,7 @@ com.android.hoststubgen.test.tinyframework.packagetest
  <init>()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/packagetest/A [inner-reason: file-override (test-package-policy)]
  class-wide in com/android/hoststubgen/test/tinyframework/packagetest/A [inner-reason: file-override [package - 'keepclass'] (#test-package-policy)]
  1
  1
com.android.hoststubgen.test.tinyframework.packagetest
@@ -1359,7 +1359,7 @@ com.android.hoststubgen.test.tinyframework.packagetest
  foo()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/packagetest/A [inner-reason: file-override (test-package-policy)]
  class-wide in com/android/hoststubgen/test/tinyframework/packagetest/A [inner-reason: file-override [package - 'keepclass'] (#test-package-policy)]
  0
  2
com.android.hoststubgen.test.tinyframework.packagetest
@@ -1392,7 +1392,7 @@ com.android.hoststubgen.test.tinyframework.packagetest.sub
  <init>()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/packagetest/sub/A [inner-reason: file-override (test-package-policy)]
  class-wide in com/android/hoststubgen/test/tinyframework/packagetest/sub/A [inner-reason: file-override [package - 'keepclass'] (#test-package-policy)]
  1
  1
com.supported