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

Commit 54de11bc authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Rename a couple things to reduce confusion

- "ClassFilter" was confusing because we already use the word "filter" for something else.
Changed it to "ClassPredicate".

- "framework-policy-override.txt" was confusing because it's not actually for the
real framework code. It's only for the "test framework" classes.

Flag: EXEMPT host test change only
Bug: 292141694
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh
Change-Id: Ic93f7e7516aea74b70d3b46a324552a25f93ab7a
parent a1870a4f
Loading
Loading
Loading
Loading
+4 −27
Original line number Original line Diff line number Diff line
# --------------------------------------------------------------------------------------------------
# *************************************************************************************************
# This file contains rules to process `framework-all.jar` to generate the host side test "stub" and
# This file contains "policies" for HostStubGen used by its automated tests.
# "impl" jars, without using Java annotations.
# For the "real" Ravenwood policies, see the frameworks/base/ravenwood/texts/ directory.
#
# *************************************************************************************************
# Useful when:
# - The class is auto-generated and annotations can't be added.
#   (We need to figure out what to do on auto-generated classes.)
# - Want to quickly change filter rules without having to rebuild framework.jar.
#
# Using this file, one can control the visibility of APIs on a per-class, per-field and per-method
# basis, but in most cases, per-class directives would be sufficient. That is:
#
# - To put the entire class, including its members and nested classes, in the "stub" jar,
#   so that the test / target code can use the API, use `stubclass`.
#
# class package.class	stubclass
#
# - To put the entire class, including its members and nested classes, in the "impl" jar,
#   but not in the "stub" jar, use `keepclass`. Use this when you don't want to expose an API to
#   tests/target directly, but it's still needed at runtime, because it's used by other "stub" APIs
#   directly or indirectly.
#
# class package.class	keepclass
#
# All other classes will be removed from both the stub jar and impl jar.
#
# --------------------------------------------------------------------------------------------------


# --------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------
# Directions on auto-generated classes, where we can't use Java annotations (yet).
# Directions on auto-generated classes, where we can't use Java annotations (yet).
+3 −3
Original line number Original line Diff line number Diff line
@@ -29,7 +29,7 @@ import com.android.hoststubgen.filters.OutputFilter
import com.android.hoststubgen.filters.SanitizationFilter
import com.android.hoststubgen.filters.SanitizationFilter
import com.android.hoststubgen.filters.TextFileFilterPolicyBuilder
import com.android.hoststubgen.filters.TextFileFilterPolicyBuilder
import com.android.hoststubgen.filters.printAsTextPolicy
import com.android.hoststubgen.filters.printAsTextPolicy
import com.android.hoststubgen.utils.ClassFilter
import com.android.hoststubgen.utils.ClassPredicate
import com.android.hoststubgen.visitors.BaseAdapter
import com.android.hoststubgen.visitors.BaseAdapter
import com.android.hoststubgen.visitors.PackageRedirectRemapper
import com.android.hoststubgen.visitors.PackageRedirectRemapper
import java.io.BufferedInputStream
import java.io.BufferedInputStream
@@ -152,9 +152,9 @@ class HostStubGen(val options: HostStubGenOptions) {


        val annotationAllowedClassesFilter = options.annotationAllowedClassesFile.get.let { file ->
        val annotationAllowedClassesFilter = options.annotationAllowedClassesFile.get.let { file ->
            if (file == null) {
            if (file == null) {
                ClassFilter.newNullFilter(true) // Allow all classes
                ClassPredicate.newConstantPredicate(true) // Allow all classes
            } else {
            } else {
                ClassFilter.loadFromFile(file, false)
                ClassPredicate.loadFromFile(file, false)
            }
            }
        }
        }


+2 −2
Original line number Original line Diff line number Diff line
@@ -31,7 +31,7 @@ import com.android.hoststubgen.asm.toHumanReadableClassName
import com.android.hoststubgen.asm.toHumanReadableMethodName
import com.android.hoststubgen.asm.toHumanReadableMethodName
import com.android.hoststubgen.asm.toJvmClassName
import com.android.hoststubgen.asm.toJvmClassName
import com.android.hoststubgen.log
import com.android.hoststubgen.log
import com.android.hoststubgen.utils.ClassFilter
import com.android.hoststubgen.utils.ClassPredicate
import org.objectweb.asm.tree.AnnotationNode
import org.objectweb.asm.tree.AnnotationNode
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.ClassNode


@@ -54,7 +54,7 @@ class AnnotationBasedFilter(
    redirectionClassAnnotations_: Set<String>,
    redirectionClassAnnotations_: Set<String>,
    classLoadHookAnnotations_: Set<String>,
    classLoadHookAnnotations_: Set<String>,
    keepStaticInitializerAnnotations_: Set<String>,
    keepStaticInitializerAnnotations_: Set<String>,
    private val annotationAllowedClassesFilter: ClassFilter,
    private val annotationAllowedClassesFilter: ClassPredicate,
    fallback: OutputFilter,
    fallback: OutputFilter,
) : DelegatingFilter(fallback) {
) : DelegatingFilter(fallback) {
    private val keepAnnotations = convertToInternalNames(keepAnnotations_)
    private val keepAnnotations = convertToInternalNames(keepAnnotations_)
+7 −7
Original line number Original line Diff line number Diff line
@@ -24,7 +24,7 @@ import java.io.File
/**
/**
 * General purpose filter for class names.
 * General purpose filter for class names.
 */
 */
class ClassFilter private constructor(
class ClassPredicate private constructor(
    private val defaultResult: Boolean,
    private val defaultResult: Boolean,
) {
) {
    private enum class MatchType {
    private enum class MatchType {
@@ -81,14 +81,14 @@ class ClassFilter private constructor(


    companion object {
    companion object {
        /**
        /**
         * Return a filter that alawys returns true or false.
         * Return a filter that always returns true or false.
         */
         */
        fun newNullFilter(defaultResult: Boolean): ClassFilter {
        fun newConstantPredicate(defaultResult: Boolean): ClassPredicate {
            return ClassFilter(defaultResult)
            return ClassPredicate(defaultResult)
        }
        }


        /** Build a filter from a file. */
        /** Build a filter from a file. */
        fun loadFromFile(filename: String, defaultResult: Boolean): ClassFilter {
        fun loadFromFile(filename: String, defaultResult: Boolean): ClassPredicate {
            return buildFromString(File(filename).readText(), defaultResult, filename)
            return buildFromString(File(filename).readText(), defaultResult, filename)
        }
        }


@@ -97,8 +97,8 @@ class ClassFilter private constructor(
            filterString: String,
            filterString: String,
            defaultResult: Boolean,
            defaultResult: Boolean,
            filenameForErrorMessage: String
            filenameForErrorMessage: String
        ): ClassFilter {
        ): ClassPredicate {
            val ret = ClassFilter(defaultResult)
            val ret = ClassPredicate(defaultResult)


            var lineNo = 0
            var lineNo = 0
            filterString.split('\n').forEach { s ->
            filterString.split('\n').forEach { s ->
+8 −8
Original line number Original line Diff line number Diff line
@@ -20,22 +20,22 @@ import com.google.common.truth.Truth.assertThat
import org.junit.Assert.fail
import org.junit.Assert.fail
import org.junit.Test
import org.junit.Test


class ClassFilterTest {
class ClassPredicateTest {
    @Test
    @Test
    fun testDefaultTrue() {
    fun testDefaultTrue() {
        val f = ClassFilter.newNullFilter(true)
        val f = ClassPredicate.newConstantPredicate(true)
        assertThat(f.matches("a/b/c")).isEqualTo(true)
        assertThat(f.matches("a/b/c")).isEqualTo(true)
    }
    }


    @Test
    @Test
    fun testDefaultFalse() {
    fun testDefaultFalse() {
        val f = ClassFilter.newNullFilter(false)
        val f = ClassPredicate.newConstantPredicate(false)
        assertThat(f.matches("a/b/c")).isEqualTo(false)
        assertThat(f.matches("a/b/c")).isEqualTo(false)
    }
    }


    @Test
    @Test
    fun testComplex1() {
    fun testComplex1() {
        val f = ClassFilter.buildFromString("""
        val f = ClassPredicate.buildFromString("""
            # ** this is a comment **
            # ** this is a comment **
            a.b.c       # allow
            a.b.c       # allow
            !a.b.d      # disallow
            !a.b.d      # disallow
@@ -57,7 +57,7 @@ class ClassFilterTest {


    @Test
    @Test
    fun testComplex2() {
    fun testComplex2() {
        val f = ClassFilter.buildFromString("""
        val f = ClassPredicate.buildFromString("""
            a.b.c       # allow
            a.b.c       # allow
            !a.*        # disallow everything else in package "a".
            !a.*        # disallow everything else in package "a".
            !d.e.f      # disallow d.e.f.
            !d.e.f      # disallow d.e.f.
@@ -75,7 +75,7 @@ class ClassFilterTest {


    @Test
    @Test
    fun testNestedClass() {
    fun testNestedClass() {
        val f = ClassFilter.buildFromString("a.b.c\nm.n.o\$p\n", false, "X")
        val f = ClassPredicate.buildFromString("a.b.c\nm.n.o\$p\n", false, "X")
        assertThat(f.matches("a/b/c")).isEqualTo(true)
        assertThat(f.matches("a/b/c")).isEqualTo(true)
        assertThat(f.matches("a/b/c\$d")).isEqualTo(true)
        assertThat(f.matches("a/b/c\$d")).isEqualTo(true)
        assertThat(f.matches("a/b/c\$d\$e")).isEqualTo(true)
        assertThat(f.matches("a/b/c\$d\$e")).isEqualTo(true)
@@ -88,7 +88,7 @@ class ClassFilterTest {
    @Test
    @Test
    fun testBadFilter1() {
    fun testBadFilter1() {
        try {
        try {
            ClassFilter.buildFromString("""
            ClassPredicate.buildFromString("""
                a*
                a*
                """.trimIndent(), true, "FILENAME")
                """.trimIndent(), true, "FILENAME")
            fail("ParseException didn't happen")
            fail("ParseException didn't happen")
@@ -101,7 +101,7 @@ class ClassFilterTest {


    @Test
    @Test
    fun testSuffix() {
    fun testSuffix() {
        val f = ClassFilter.buildFromString("""
        val f = ClassPredicate.buildFromString("""
            *.Abc       # allow
            *.Abc       # allow
            !*          # Disallow by default
            !*          # Disallow by default
            """.trimIndent(), true, "X")
            """.trimIndent(), true, "X")
Loading