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

Commit b4ed857b authored by Makoto Onuki's avatar Makoto Onuki
Browse files

[HostStubGen] Now method descriptor is optional in policy files

Originally, I wanted to avoid over-exposing unnecessary methods, so
I made this check strict.

However, policy files are basically for prototyping, and we should prefer
annotations anyway, so the strictness is just unnecessary.

Flag: EXEMPT host test change only
Bug: 292141694
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh
Change-Id: I0d7ec4e5f06f048842892c809a8a5646512f6616
parent 22113b5f
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ class :r keepclass

# Support APIs not available in standard JRE
class java.io.FileDescriptor keep
    method getInt$ ()I @com.android.ravenwood.RavenwoodJdkPatch.getInt$
    method setInt$ (I)V @com.android.ravenwood.RavenwoodJdkPatch.setInt$
    method getInt$ @com.android.ravenwood.RavenwoodJdkPatch.getInt$
    method setInt$ @com.android.ravenwood.RavenwoodJdkPatch.setInt$
class java.util.LinkedHashMap keep
    method eldest ()Ljava/util/Map$Entry; @com.android.ravenwood.RavenwoodJdkPatch.eldest
    method eldest @com.android.ravenwood.RavenwoodJdkPatch.eldest
+7 −2
Original line number Diff line number Diff line
@@ -66,6 +66,9 @@ class InMemoryOutputFilter(
        methodName: String,
        descriptor: String
    ) {
        if (descriptor == "*") {
            return
        }
        if (classes.findMethod(className, methodName, descriptor) == null) {
            log.w("Unknown method $className.$methodName$descriptor")
        }
@@ -92,6 +95,7 @@ class InMemoryOutputFilter(
            descriptor: String,
            ): FilterPolicyWithReason {
        return mPolicies[getMethodKey(className, methodName, descriptor)]
            ?: mPolicies[getMethodKey(className, methodName, "*")]
            ?: super.getPolicyForMethod(className, methodName, descriptor)
    }

@@ -107,6 +111,7 @@ class InMemoryOutputFilter(

    override fun getRenameTo(className: String, methodName: String, descriptor: String): String? {
        return mRenames[getMethodKey(className, methodName, descriptor)]
            ?: mRenames[getMethodKey(className, methodName, "*")]
            ?: super.getRenameTo(className, methodName, descriptor)
    }

+14 −5
Original line number Diff line number Diff line
@@ -303,12 +303,21 @@ class TextFileFilterPolicyParser(
    }

    private fun parseMethod(fields: Array<String>) {
        if (fields.size < 4) {
            throw ParseException("Method ('m') expects 3 fields.")
        if (fields.size < 3 || fields.size > 4) {
            throw ParseException("Method ('m') expects 3 or 4 fields.")
        }
        val name = fields[1]
        val signature = fields[2]
        val policy = parsePolicy(fields[3])
        val signature: String
        val policyStr: String
        if (fields.size <= 3) {
            signature = "*"
            policyStr = fields[2]
        } else {
            signature = fields[2]
            policyStr = fields[3]
        }

        val policy = parsePolicy(policyStr)

        if (!policy.isUsableWithMethods) {
            throw ParseException("Method can't have policy '$policy'")
@@ -321,7 +330,7 @@ class TextFileFilterPolicyParser(
            policy.withReason(FILTER_REASON)
        )
        if (policy == FilterPolicy.Substitute) {
            val fromName = fields[3].substring(1)
            val fromName = policyStr.substring(1)

            if (fromName == name) {
                throw ParseException(
+4 −3
Original line number Diff line number Diff line
@@ -48,12 +48,13 @@ class TextFilePolicyMethodReplaceFilter(
        // Maybe use 'Tri' if we end up having too many replacements.
        spec.forEach {
            if (className == it.fromClass &&
                methodName == it.fromMethod &&
                descriptor == it.fromDescriptor
                methodName == it.fromMethod
                ) {
                if (it.fromDescriptor == "*" || descriptor == it.fromDescriptor) {
                    return MethodReplaceTarget(it.toClass, it.toMethod)
                }
            }
        }
        return null
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -3,11 +3,11 @@ class com/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy keep
  # field remove	remove # Implicitly remove
  method <init>	()V	            keep
  method addOne	(I)I	        keep
  method addOneInner	(I)I	keep
  method addOneInner	keep
  method toBeRemoved	(Ljava/lang/String;)V	remove
  method addTwo	(I)I	        @addTwo_host
  # method addTwo_host	(I)I	# used as a substitute
  method nativeAddThree	(I)I	@addThree_host
  method nativeAddThree	        @addThree_host
  # method addThree_host	(I)I	# used as a substitute
  method unsupportedMethod	()Ljava/lang/String;	throw
  method visibleButUsesUnsupportedMethod	()Ljava/lang/String;	keep