diff options
10 files changed, 173 insertions, 254 deletions
diff --git a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/HostStubGenClassProcessor.kt b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/HostStubGenClassProcessor.kt index 530429865040..98f96a89d889 100644 --- a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/HostStubGenClassProcessor.kt +++ b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/HostStubGenClassProcessor.kt @@ -30,12 +30,15 @@ import com.android.hoststubgen.filters.TextFileFilterPolicyBuilder import com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep import com.android.hoststubgen.utils.ClassPredicate import com.android.hoststubgen.visitors.BaseAdapter +import com.android.hoststubgen.visitors.ImplGeneratingAdapter import com.android.hoststubgen.visitors.PackageRedirectRemapper +import java.io.PrintWriter import org.objectweb.asm.ClassReader import org.objectweb.asm.ClassVisitor import org.objectweb.asm.ClassWriter import org.objectweb.asm.commons.ClassRemapper import org.objectweb.asm.util.CheckClassAdapter +import org.objectweb.asm.util.TraceClassVisitor /** * This class implements bytecode transformation of HostStubGen. @@ -133,21 +136,10 @@ class HostStubGenClassProcessor( return filter } - fun processClassBytecode(bytecode: ByteArray): ByteArray { - val cr = ClassReader(bytecode) - - // If the class was already processed previously, skip - val clz = allClasses.getClass(cr.className) - if (clz.findAnyAnnotation(processedAnnotation) != null) { - return bytecode - } - - // COMPUTE_FRAMES wouldn't be happy if code uses - val flags = ClassWriter.COMPUTE_MAXS // or ClassWriter.COMPUTE_FRAMES - val cw = ClassWriter(flags) + private fun buildVisitor(base: ClassVisitor, className: String): ClassVisitor { + // Connect to the base visitor + var outVisitor: ClassVisitor = base - // Connect to the class writer - var outVisitor: ClassVisitor = cw if (options.enableClassChecker.get) { outVisitor = CheckClassAdapter(outVisitor) } @@ -158,15 +150,59 @@ class HostStubGenClassProcessor( val visitorOptions = BaseAdapter.Options( errors = errors, stats = stats, - enablePreTrace = options.enablePreTrace.get, - enablePostTrace = options.enablePostTrace.get, deleteClassFinals = options.deleteFinals.get, deleteMethodFinals = options.deleteFinals.get, ) - outVisitor = BaseAdapter.getVisitor( - cr.className, allClasses, outVisitor, filter, - packageRedirector, visitorOptions - ) + + val verbosePrinter = PrintWriter(log.getWriter(LogLevel.Verbose)) + + // Inject TraceClassVisitor for debugging. + if (options.enablePostTrace.get) { + outVisitor = TraceClassVisitor(outVisitor, verbosePrinter) + } + + // Handle --package-redirect + if (!packageRedirector.isEmpty) { + // Don't apply the remapper on redirect-from classes. + // Otherwise, if the target jar actually contains the "from" classes (which + // may or may not be the case) they'd be renamed. + // But we update all references in other places, so, a method call to a "from" class + // would be replaced with the "to" class. All type references (e.g. variable types) + // will be updated too. + if (!packageRedirector.isTarget(className)) { + outVisitor = ClassRemapper(outVisitor, packageRedirector) + } else { + log.v( + "Class $className is a redirect-from class, not applying" + + " --package-redirect" + ) + } + } + + outVisitor = ImplGeneratingAdapter(allClasses, outVisitor, filter, visitorOptions) + + // Inject TraceClassVisitor for debugging. + if (options.enablePreTrace.get) { + outVisitor = TraceClassVisitor(outVisitor, verbosePrinter) + } + + return outVisitor + } + + fun processClassBytecode(bytecode: ByteArray): ByteArray { + val cr = ClassReader(bytecode) + + // If the class was already processed previously, skip + val clz = allClasses.getClass(cr.className) + if (clz.findAnyAnnotation(processedAnnotation) != null) { + return bytecode + } + + // COMPUTE_FRAMES wouldn't be happy if code uses + val flags = ClassWriter.COMPUTE_MAXS // or ClassWriter.COMPUTE_FRAMES + val cw = ClassWriter(flags) + + val outVisitor = buildVisitor(cw, cr.className) cr.accept(outVisitor, ClassReader.EXPAND_FRAMES) return cw.toByteArray() diff --git a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/DelegatingFilter.kt b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/DelegatingFilter.kt index b8b0d8a31268..7f36aca33eee 100644 --- a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/DelegatingFilter.kt +++ b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/DelegatingFilter.kt @@ -19,9 +19,9 @@ package com.android.hoststubgen.filters * Base class for an [OutputFilter] that uses another filter as a fallback. */ abstract class DelegatingFilter( - // fallback shouldn't be used by subclasses directly, so make it private. - // They should instead be calling into `super` or `outermostFilter`. - private val fallback: OutputFilter + // fallback shouldn't be used by subclasses directly, so make it private. + // They should instead be calling into `super` or `outermostFilter`. + private val fallback: OutputFilter ) : OutputFilter() { init { fallback.outermostFilter = this @@ -50,24 +50,24 @@ abstract class DelegatingFilter( } override fun getPolicyForField( - className: String, - fieldName: String + className: String, + fieldName: String ): FilterPolicyWithReason { return fallback.getPolicyForField(className, fieldName) } override fun getPolicyForMethod( - className: String, - methodName: String, - descriptor: String + className: String, + methodName: String, + descriptor: String ): FilterPolicyWithReason { return fallback.getPolicyForMethod(className, methodName, descriptor) } override fun getRenameTo( - className: String, - methodName: String, - descriptor: String + className: String, + methodName: String, + descriptor: String ): String? { return fallback.getRenameTo(className, methodName, descriptor) } @@ -97,13 +97,12 @@ abstract class DelegatingFilter( } override fun getMethodCallReplaceTo( - callerClassName: String, - callerMethodName: String, className: String, methodName: String, descriptor: String, ): MethodReplaceTarget? { return fallback.getMethodCallReplaceTo( - callerClassName, callerMethodName, className, methodName, descriptor) + className, methodName, descriptor + ) } } diff --git a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/InMemoryOutputFilter.kt b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/InMemoryOutputFilter.kt index fc885d6f463b..59da3da99ea5 100644 --- a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/InMemoryOutputFilter.kt +++ b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/InMemoryOutputFilter.kt @@ -28,10 +28,12 @@ class InMemoryOutputFilter( private val classes: ClassNodes, fallback: OutputFilter, ) : DelegatingFilter(fallback) { - private val mPolicies: MutableMap<String, FilterPolicyWithReason> = mutableMapOf() - private val mRenames: MutableMap<String, String> = mutableMapOf() - private val mRedirectionClasses: MutableMap<String, String> = mutableMapOf() - private val mClassLoadHooks: MutableMap<String, String> = mutableMapOf() + private val mPolicies = mutableMapOf<String, FilterPolicyWithReason>() + private val mRenames = mutableMapOf<String, String>() + private val mRedirectionClasses = mutableMapOf<String, String>() + private val mClassLoadHooks = mutableMapOf<String, String>() + private val mMethodCallReplaceSpecs = mutableListOf<MethodCallReplaceSpec>() + private val mTypeRenameSpecs = mutableListOf<TypeRenameSpec>() private fun getClassKey(className: String): String { return className.toHumanReadableClassName() @@ -45,10 +47,6 @@ class InMemoryOutputFilter( return getClassKey(className) + "." + methodName + ";" + signature } - override fun getPolicyForClass(className: String): FilterPolicyWithReason { - return mPolicies[getClassKey(className)] ?: super.getPolicyForClass(className) - } - private fun checkClass(className: String) { if (classes.findClass(className) == null) { log.w("Unknown class $className") @@ -74,6 +72,10 @@ class InMemoryOutputFilter( } } + override fun getPolicyForClass(className: String): FilterPolicyWithReason { + return mPolicies[getClassKey(className)] ?: super.getPolicyForClass(className) + } + fun setPolicyForClass(className: String, policy: FilterPolicyWithReason) { checkClass(className) mPolicies[getClassKey(className)] = policy @@ -81,7 +83,7 @@ class InMemoryOutputFilter( override fun getPolicyForField(className: String, fieldName: String): FilterPolicyWithReason { return mPolicies[getFieldKey(className, fieldName)] - ?: super.getPolicyForField(className, fieldName) + ?: super.getPolicyForField(className, fieldName) } fun setPolicyForField(className: String, fieldName: String, policy: FilterPolicyWithReason) { @@ -90,21 +92,21 @@ class InMemoryOutputFilter( } override fun getPolicyForMethod( - className: String, - methodName: String, - descriptor: String, - ): FilterPolicyWithReason { + className: String, + methodName: String, + descriptor: String, + ): FilterPolicyWithReason { return mPolicies[getMethodKey(className, methodName, descriptor)] ?: mPolicies[getMethodKey(className, methodName, "*")] ?: super.getPolicyForMethod(className, methodName, descriptor) } fun setPolicyForMethod( - className: String, - methodName: String, - descriptor: String, - policy: FilterPolicyWithReason, - ) { + className: String, + methodName: String, + descriptor: String, + policy: FilterPolicyWithReason, + ) { checkMethod(className, methodName, descriptor) mPolicies[getMethodKey(className, methodName, descriptor)] = policy } @@ -123,7 +125,7 @@ class InMemoryOutputFilter( override fun getRedirectionClass(className: String): String? { return mRedirectionClasses[getClassKey(className)] - ?: super.getRedirectionClass(className) + ?: super.getRedirectionClass(className) } fun setRedirectionClass(from: String, to: String) { @@ -135,11 +137,52 @@ class InMemoryOutputFilter( } override fun getClassLoadHooks(className: String): List<String> { - return addNonNullElement(super.getClassLoadHooks(className), - mClassLoadHooks[getClassKey(className)]) + return addNonNullElement( + super.getClassLoadHooks(className), + mClassLoadHooks[getClassKey(className)] + ) } fun setClassLoadHook(className: String, methodName: String) { mClassLoadHooks[getClassKey(className)] = methodName.toHumanReadableMethodName() } + + override fun hasAnyMethodCallReplace(): Boolean { + return mMethodCallReplaceSpecs.isNotEmpty() || super.hasAnyMethodCallReplace() + } + + override fun getMethodCallReplaceTo( + className: String, + methodName: String, + descriptor: String, + ): MethodReplaceTarget? { + // Maybe use 'Tri' if we end up having too many replacements. + mMethodCallReplaceSpecs.forEach { + if (className == it.fromClass && + methodName == it.fromMethod + ) { + if (it.fromDescriptor == "*" || descriptor == it.fromDescriptor) { + return MethodReplaceTarget(it.toClass, it.toMethod) + } + } + } + return super.getMethodCallReplaceTo(className, methodName, descriptor) + } + + fun setMethodCallReplaceSpec(spec: MethodCallReplaceSpec) { + mMethodCallReplaceSpecs.add(spec) + } + + override fun remapType(className: String): String? { + mTypeRenameSpecs.forEach { + if (it.typeInternalNamePattern.matcher(className).matches()) { + return it.typeInternalNamePrefix + className + } + } + return super.remapType(className) + } + + fun setRemapTypeSpec(spec: TypeRenameSpec) { + mTypeRenameSpecs.add(spec) + } } diff --git a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/OutputFilter.kt b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/OutputFilter.kt index f99ce906240a..c47bb302920f 100644 --- a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/OutputFilter.kt +++ b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/OutputFilter.kt @@ -41,10 +41,10 @@ abstract class OutputFilter { abstract fun getPolicyForField(className: String, fieldName: String): FilterPolicyWithReason abstract fun getPolicyForMethod( - className: String, - methodName: String, - descriptor: String, - ): FilterPolicyWithReason + className: String, + methodName: String, + descriptor: String, + ): FilterPolicyWithReason /** * If a given method is a substitute-from method, return the substitute-to method name. @@ -108,8 +108,6 @@ abstract class OutputFilter { * If a method call should be forwarded to another method, return the target's class / method. */ open fun getMethodCallReplaceTo( - callerClassName: String, - callerMethodName: String, className: String, methodName: String, descriptor: String, diff --git a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/TextFileFilterPolicyParser.kt b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/TextFileFilterPolicyParser.kt index 2c75e68306cd..97fc35302528 100644 --- a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/TextFileFilterPolicyParser.kt +++ b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/TextFileFilterPolicyParser.kt @@ -58,6 +58,23 @@ enum class SpecialClass { RFile, } +data class MethodCallReplaceSpec( + val fromClass: String, + val fromMethod: String, + val fromDescriptor: String, + val toClass: String, + val toMethod: String, +) + +/** + * When a package name matches [typeInternalNamePattern], we prepend [typeInternalNamePrefix] + * to it. + */ +data class TypeRenameSpec( + val typeInternalNamePattern: Pattern, + val typeInternalNamePrefix: String, +) + /** * This receives [TextFileFilterPolicyBuilder] parsing result. */ @@ -99,7 +116,7 @@ interface PolicyFileProcessor { className: String, methodName: String, methodDesc: String, - replaceSpec: TextFilePolicyMethodReplaceFilter.MethodCallReplaceSpec, + replaceSpec: MethodCallReplaceSpec, ) } @@ -116,9 +133,6 @@ class TextFileFilterPolicyBuilder( private var featureFlagsPolicy: FilterPolicyWithReason? = null private var syspropsPolicy: FilterPolicyWithReason? = null private var rFilePolicy: FilterPolicyWithReason? = null - private val typeRenameSpec = mutableListOf<TextFilePolicyRemapperFilter.TypeRenameSpec>() - private val methodReplaceSpec = - mutableListOf<TextFilePolicyMethodReplaceFilter.MethodCallReplaceSpec>() /** * Fields for a filter chain used for "partial allowlisting", which are used by @@ -126,17 +140,14 @@ class TextFileFilterPolicyBuilder( */ private val annotationAllowedInMemoryFilter: InMemoryOutputFilter val annotationAllowedMembersFilter: OutputFilter + get() = annotationAllowedInMemoryFilter private val annotationAllowedPolicy = FilterPolicy.AnnotationAllowed.withReason(FILTER_REASON) init { // Create a filter that checks "partial allowlisting". - var aaf: OutputFilter = ConstantFilter(FilterPolicy.Remove, "default disallowed") - - aaf = InMemoryOutputFilter(classes, aaf) - annotationAllowedInMemoryFilter = aaf - - annotationAllowedMembersFilter = annotationAllowedInMemoryFilter + val filter = ConstantFilter(FilterPolicy.Remove, "default disallowed") + annotationAllowedInMemoryFilter = InMemoryOutputFilter(classes, filter) } /** @@ -153,20 +164,10 @@ class TextFileFilterPolicyBuilder( * Generate the resulting [OutputFilter]. */ fun createOutputFilter(): OutputFilter { - var ret: OutputFilter = imf - if (typeRenameSpec.isNotEmpty()) { - ret = TextFilePolicyRemapperFilter(typeRenameSpec, ret) - } - if (methodReplaceSpec.isNotEmpty()) { - ret = TextFilePolicyMethodReplaceFilter(methodReplaceSpec, classes, ret) - } - // Wrap the in-memory-filter with AHF. - ret = AndroidHeuristicsFilter( - classes, aidlPolicy, featureFlagsPolicy, syspropsPolicy, rFilePolicy, ret + return AndroidHeuristicsFilter( + classes, aidlPolicy, featureFlagsPolicy, syspropsPolicy, rFilePolicy, imf ) - - return ret } private inner class Processor : PolicyFileProcessor { @@ -180,9 +181,7 @@ class TextFileFilterPolicyBuilder( } override fun onRename(pattern: Pattern, prefix: String) { - typeRenameSpec += TextFilePolicyRemapperFilter.TypeRenameSpec( - pattern, prefix - ) + imf.setRemapTypeSpec(TypeRenameSpec(pattern, prefix)) } override fun onClassStart(className: String) { @@ -284,12 +283,12 @@ class TextFileFilterPolicyBuilder( className: String, methodName: String, methodDesc: String, - replaceSpec: TextFilePolicyMethodReplaceFilter.MethodCallReplaceSpec, + replaceSpec: MethodCallReplaceSpec, ) { // Keep the source method, because the target method may call it. imf.setPolicyForMethod(className, methodName, methodDesc, FilterPolicy.Keep.withReason(FILTER_REASON)) - methodReplaceSpec.add(replaceSpec) + imf.setMethodCallReplaceSpec(replaceSpec) } } } @@ -630,13 +629,13 @@ class TextFileFilterPolicyParser { if (classAndMethod != null) { // If the substitution target contains a ".", then // it's a method call redirect. - val spec = TextFilePolicyMethodReplaceFilter.MethodCallReplaceSpec( - currentClassName!!.toJvmClassName(), - methodName, - signature, - classAndMethod.first.toJvmClassName(), - classAndMethod.second, - ) + val spec = MethodCallReplaceSpec( + className.toJvmClassName(), + methodName, + signature, + classAndMethod.first.toJvmClassName(), + classAndMethod.second, + ) processor.onMethodOutClassReplace( className, methodName, diff --git a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/TextFilePolicyMethodReplaceFilter.kt b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/TextFilePolicyMethodReplaceFilter.kt deleted file mode 100644 index a3f934cacc2c..000000000000 --- a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/TextFilePolicyMethodReplaceFilter.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.hoststubgen.filters - -import com.android.hoststubgen.asm.ClassNodes - -/** - * Filter used by TextFileFilterPolicyParser for "method call relacement". - */ -class TextFilePolicyMethodReplaceFilter( - val spec: List<MethodCallReplaceSpec>, - val classes: ClassNodes, - val fallback: OutputFilter, -) : DelegatingFilter(fallback) { - - data class MethodCallReplaceSpec( - val fromClass: String, - val fromMethod: String, - val fromDescriptor: String, - val toClass: String, - val toMethod: String, - ) - - override fun hasAnyMethodCallReplace(): Boolean { - return true - } - - override fun getMethodCallReplaceTo( - callerClassName: String, - callerMethodName: String, - className: String, - methodName: String, - descriptor: String, - ): MethodReplaceTarget? { - // Maybe use 'Tri' if we end up having too many replacements. - spec.forEach { - if (className == it.fromClass && - methodName == it.fromMethod - ) { - if (it.fromDescriptor == "*" || descriptor == it.fromDescriptor) { - return MethodReplaceTarget(it.toClass, it.toMethod) - } - } - } - return null - } -} diff --git a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/TextFilePolicyRemapperFilter.kt b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/TextFilePolicyRemapperFilter.kt deleted file mode 100644 index bc90d1248322..000000000000 --- a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/filters/TextFilePolicyRemapperFilter.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.hoststubgen.filters - -import java.util.regex.Pattern - -/** - * A filter that provides a simple "jarjar" functionality via [mapType] - */ -class TextFilePolicyRemapperFilter( - val typeRenameSpecs: List<TypeRenameSpec>, - fallback: OutputFilter, -) : DelegatingFilter(fallback) { - /** - * When a package name matches [typeInternalNamePattern], we prepend [typeInternalNamePrefix] - * to it. - */ - data class TypeRenameSpec( - val typeInternalNamePattern: Pattern, - val typeInternalNamePrefix: String, - ) - - override fun remapType(className: String): String? { - typeRenameSpecs.forEach { - if (it.typeInternalNamePattern.matcher(className).matches()) { - return it.typeInternalNamePrefix + className - } - } - return null - } -} diff --git a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/visitors/BaseAdapter.kt b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/visitors/BaseAdapter.kt index a08d1d605949..769b769d7a20 100644 --- a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/visitors/BaseAdapter.kt +++ b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/visitors/BaseAdapter.kt @@ -17,7 +17,6 @@ package com.android.hoststubgen.visitors import com.android.hoststubgen.HostStubGenErrors import com.android.hoststubgen.HostStubGenStats -import com.android.hoststubgen.LogLevel import com.android.hoststubgen.asm.ClassNodes import com.android.hoststubgen.asm.UnifiedVisitor import com.android.hoststubgen.asm.getPackageNameFromFullClassName @@ -26,13 +25,10 @@ import com.android.hoststubgen.filters.FilterPolicyWithReason import com.android.hoststubgen.filters.OutputFilter import com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep import com.android.hoststubgen.log -import java.io.PrintWriter import org.objectweb.asm.ClassVisitor import org.objectweb.asm.FieldVisitor import org.objectweb.asm.MethodVisitor import org.objectweb.asm.Opcodes -import org.objectweb.asm.commons.ClassRemapper -import org.objectweb.asm.util.TraceClassVisitor const val OPCODE_VERSION = Opcodes.ASM9 @@ -49,8 +45,6 @@ abstract class BaseAdapter( data class Options( val errors: HostStubGenErrors, val stats: HostStubGenStats?, - val enablePreTrace: Boolean, - val enablePostTrace: Boolean, val deleteClassFinals: Boolean, val deleteMethodFinals: Boolean, // We don't remove finals from fields, because final fields have a stronger memory @@ -253,50 +247,4 @@ abstract class BaseAdapter( substituted: Boolean, superVisitor: MethodVisitor?, ): MethodVisitor? - - companion object { - fun getVisitor( - classInternalName: String, - classes: ClassNodes, - nextVisitor: ClassVisitor, - filter: OutputFilter, - packageRedirector: PackageRedirectRemapper, - options: Options, - ): ClassVisitor { - var next = nextVisitor - - val verbosePrinter = PrintWriter(log.getWriter(LogLevel.Verbose)) - - // Inject TraceClassVisitor for debugging. - if (options.enablePostTrace) { - next = TraceClassVisitor(next, verbosePrinter) - } - - // Handle --package-redirect - if (!packageRedirector.isEmpty) { - // Don't apply the remapper on redirect-from classes. - // Otherwise, if the target jar actually contains the "from" classes (which - // may or may not be the case) they'd be renamed. - // But we update all references in other places, so, a method call to a "from" class - // would be replaced with the "to" class. All type references (e.g. variable types) - // will be updated too. - if (!packageRedirector.isTarget(classInternalName)) { - next = ClassRemapper(next, packageRedirector) - } else { - log.v( - "Class $classInternalName is a redirect-from class, not applying" + - " --package-redirect" - ) - } - } - - next = ImplGeneratingAdapter(classes, next, filter, options) - - // Inject TraceClassVisitor for debugging. - if (options.enablePreTrace) { - next = TraceClassVisitor(next, verbosePrinter) - } - return next - } - } } diff --git a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/visitors/ImplGeneratingAdapter.kt b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/visitors/ImplGeneratingAdapter.kt index b8a357668c2b..617385ad438e 100644 --- a/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/visitors/ImplGeneratingAdapter.kt +++ b/ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/visitors/ImplGeneratingAdapter.kt @@ -396,7 +396,7 @@ class ImplGeneratingAdapter( } val to = filter.getMethodCallReplaceTo( - currentClassName, callerMethodName, owner, name, descriptor + owner, name, descriptor ) if (to == null diff --git a/ravenwood/tools/ravenhelper/src/com/android/platform/test/ravenwood/ravenhelper/policytoannot/PtaProcessor.kt b/ravenwood/tools/ravenhelper/src/com/android/platform/test/ravenwood/ravenhelper/policytoannot/PtaProcessor.kt index fd6f732a06ce..5ce9a23e6e05 100644 --- a/ravenwood/tools/ravenhelper/src/com/android/platform/test/ravenwood/ravenhelper/policytoannot/PtaProcessor.kt +++ b/ravenwood/tools/ravenhelper/src/com/android/platform/test/ravenwood/ravenhelper/policytoannot/PtaProcessor.kt @@ -19,10 +19,10 @@ import com.android.hoststubgen.LogLevel import com.android.hoststubgen.asm.CLASS_INITIALIZER_NAME import com.android.hoststubgen.asm.toJvmClassName import com.android.hoststubgen.filters.FilterPolicyWithReason +import com.android.hoststubgen.filters.MethodCallReplaceSpec import com.android.hoststubgen.filters.PolicyFileProcessor import com.android.hoststubgen.filters.SpecialClass import com.android.hoststubgen.filters.TextFileFilterPolicyParser -import com.android.hoststubgen.filters.TextFilePolicyMethodReplaceFilter import com.android.hoststubgen.log import com.android.hoststubgen.utils.ClassPredicate import com.android.platform.test.ravenwood.ravenhelper.SubcommandHandler @@ -448,7 +448,7 @@ private class TextPolicyToAnnotationConverter( className: String, methodName: String, methodDesc: String, - replaceSpec: TextFilePolicyMethodReplaceFilter.MethodCallReplaceSpec, + replaceSpec: MethodCallReplaceSpec, ) { // This can't be converted to an annotation. classHasMember = true |