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

Commit 755f3741 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Rename a couple things to reduce confusion" into main

parents 228ccb46 54de11bc
Loading
Loading
Loading
Loading
+4 −27
Original line number Diff line number Diff line
# --------------------------------------------------------------------------------------------------
# This file contains rules to process `framework-all.jar` to generate the host side test "stub" and
# "impl" jars, without using Java annotations.
#
# 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.
#
# --------------------------------------------------------------------------------------------------
# *************************************************************************************************
# This file contains "policies" for HostStubGen used by its automated tests.
# For the "real" Ravenwood policies, see the frameworks/base/ravenwood/texts/ directory.
# *************************************************************************************************

# --------------------------------------------------------------------------------------------------
# Directions on auto-generated classes, where we can't use Java annotations (yet).
+3 −3
Original line number 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.TextFileFilterPolicyBuilder
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.PackageRedirectRemapper
import java.io.BufferedInputStream
@@ -153,9 +153,9 @@ class HostStubGen(val options: HostStubGenOptions) {

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

+2 −2
Original line number 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.toJvmClassName
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.ClassNode

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

    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 {
            return ClassFilter(defaultResult)
        fun newConstantPredicate(defaultResult: Boolean): ClassPredicate {
            return ClassPredicate(defaultResult)
        }

        /** 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)
        }

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

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

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

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

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

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

    @Test
    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\$d")).isEqualTo(true)
        assertThat(f.matches("a/b/c\$d\$e")).isEqualTo(true)
@@ -88,7 +88,7 @@ class ClassFilterTest {
    @Test
    fun testBadFilter1() {
        try {
            ClassFilter.buildFromString("""
            ClassPredicate.buildFromString("""
                a*
                """.trimIndent(), true, "FILENAME")
            fail("ParseException didn't happen")
@@ -101,7 +101,7 @@ class ClassFilterTest {

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