Loading tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/Exceptions.kt +4 −0 Original line number Diff line number Diff line Loading @@ -46,3 +46,7 @@ class UnknownApiException(message: String) : Exception(message), UserErrorExcept */ class InvalidAnnotationException(message: String) : Exception(message), UserErrorException /** * We use this for general "user" errors. */ class HostStubGenUserErrorException(message: String) : Exception(message), UserErrorException tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt +1 −1 Original line number Diff line number Diff line Loading @@ -128,7 +128,7 @@ class HostStubGen(val options: HostStubGenOptions) { } val end = System.currentTimeMillis() log.v("Done reading class structure in %.1f second(s).", (end - start) / 1000.0) log.i("Done reading class structure in %.1f second(s).", (end - start) / 1000.0) return allClasses } Loading tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenErrors.kt +4 −4 Original line number Diff line number Diff line Loading @@ -15,10 +15,10 @@ */ package com.android.hoststubgen class HostStubGenErrors { fun onErrorFound(message: String) { // For now, we just throw as soon as any error is found, but eventually we should keep open class HostStubGenErrors { open fun onErrorFound(message: String) { // TODO: For now, we just throw as soon as any error is found, but eventually we should keep // all errors and print them at the end. throw RuntimeException(message) throw HostStubGenUserErrorException(message) } } No newline at end of file tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/asm/AsmUtils.kt +40 −0 Original line number Diff line number Diff line Loading @@ -196,6 +196,29 @@ fun isVisibilityPrivateOrPackagePrivate(access: Int): Boolean { } } enum class Visibility { PRIVATE, PACKAGE_PRIVATE, PROTECTED, PUBLIC; companion object { fun fromAccess(access: Int): Visibility { if ((access and Opcodes.ACC_PUBLIC) != 0) { return PUBLIC } if ((access and Opcodes.ACC_PROTECTED) != 0) { return PROTECTED } if ((access and Opcodes.ACC_PRIVATE) != 0) { return PRIVATE } return PACKAGE_PRIVATE } } } fun ClassNode.isEnum(): Boolean { return (this.access and Opcodes.ACC_ENUM) != 0 } Loading @@ -212,6 +235,10 @@ fun MethodNode.isSynthetic(): Boolean { return (this.access and Opcodes.ACC_SYNTHETIC) != 0 } fun MethodNode.isStatic(): Boolean { return (this.access and Opcodes.ACC_STATIC) != 0 } fun FieldNode.isEnum(): Boolean { return (this.access and Opcodes.ACC_ENUM) != 0 } Loading @@ -220,6 +247,19 @@ fun FieldNode.isSynthetic(): Boolean { return (this.access and Opcodes.ACC_SYNTHETIC) != 0 } fun ClassNode.getVisibility(): Visibility { return Visibility.fromAccess(this.access) } fun MethodNode.getVisibility(): Visibility { return Visibility.fromAccess(this.access) } fun FieldNode.getVisibility(): Visibility { return Visibility.fromAccess(this.access) } /* Dump of the members of TinyFrameworkEnumSimple: Loading tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/visitors/BaseAdapter.kt +19 −7 Original line number Diff line number Diff line Loading @@ -17,8 +17,8 @@ package com.android.hoststubgen.visitors import com.android.hoststubgen.HostStubGenErrors import com.android.hoststubgen.LogLevel import com.android.hoststubgen.asm.UnifiedVisitor import com.android.hoststubgen.asm.ClassNodes import com.android.hoststubgen.asm.UnifiedVisitor import com.android.hoststubgen.asm.getPackageNameFromClassName import com.android.hoststubgen.asm.resolveClassName import com.android.hoststubgen.asm.toJvmClassName Loading Loading @@ -178,7 +178,9 @@ abstract class BaseAdapter ( log.d("visitMethod: %s%s [%x] [%s] Policy: %s", name, descriptor, access, signature, p) log.withIndent { // If it's a substitute-to method, then skip. // If it's a substitute-from method, then skip (== remove). // Instead of this method, we rename the substitute-to method with the original // name, in the "Maybe rename the method" part below. val policy = filter.getPolicyForMethod(currentClassName, name, descriptor) if (policy.policy.isSubstitute) { log.d("Skipping %s%s %s", name, descriptor, policy) Loading @@ -191,9 +193,19 @@ abstract class BaseAdapter ( // Maybe rename the method. val newName: String val substituteTo = filter.getRenameTo(currentClassName, name, descriptor) if (substituteTo != null) { newName = substituteTo val renameTo = filter.getRenameTo(currentClassName, name, descriptor) if (renameTo != null) { newName = renameTo // It's confusing, but here, `newName` is the original method name // (the one with the @substitute/replace annotation). // `name` is the name of the method we're currently visiting, so it's usually a // "...$ravewnwood" name. if (!checkSubstitutionMethodCompatibility( classes, currentClassName, newName, name, descriptor, options.errors)) { return null } log.v("Emitting %s.%s%s as %s %s", currentClassName, name, descriptor, newName, policy) } else { Loading @@ -203,12 +215,12 @@ abstract class BaseAdapter ( // Let subclass update the flag. // But note, we only use it when calling the super's method, // but not for visitMethodInner(), beucase when subclass wants to change access, // but not for visitMethodInner(), because when subclass wants to change access, // it can do so inside visitMethodInner(). val newAccess = updateAccessFlags(access, name, descriptor) val ret = visitMethodInner(access, newName, descriptor, signature, exceptions, policy, substituteTo != null, renameTo != null, super.visitMethod(newAccess, newName, descriptor, signature, exceptions)) ret?.let { Loading Loading
tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/Exceptions.kt +4 −0 Original line number Diff line number Diff line Loading @@ -46,3 +46,7 @@ class UnknownApiException(message: String) : Exception(message), UserErrorExcept */ class InvalidAnnotationException(message: String) : Exception(message), UserErrorException /** * We use this for general "user" errors. */ class HostStubGenUserErrorException(message: String) : Exception(message), UserErrorException
tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt +1 −1 Original line number Diff line number Diff line Loading @@ -128,7 +128,7 @@ class HostStubGen(val options: HostStubGenOptions) { } val end = System.currentTimeMillis() log.v("Done reading class structure in %.1f second(s).", (end - start) / 1000.0) log.i("Done reading class structure in %.1f second(s).", (end - start) / 1000.0) return allClasses } Loading
tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenErrors.kt +4 −4 Original line number Diff line number Diff line Loading @@ -15,10 +15,10 @@ */ package com.android.hoststubgen class HostStubGenErrors { fun onErrorFound(message: String) { // For now, we just throw as soon as any error is found, but eventually we should keep open class HostStubGenErrors { open fun onErrorFound(message: String) { // TODO: For now, we just throw as soon as any error is found, but eventually we should keep // all errors and print them at the end. throw RuntimeException(message) throw HostStubGenUserErrorException(message) } } No newline at end of file
tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/asm/AsmUtils.kt +40 −0 Original line number Diff line number Diff line Loading @@ -196,6 +196,29 @@ fun isVisibilityPrivateOrPackagePrivate(access: Int): Boolean { } } enum class Visibility { PRIVATE, PACKAGE_PRIVATE, PROTECTED, PUBLIC; companion object { fun fromAccess(access: Int): Visibility { if ((access and Opcodes.ACC_PUBLIC) != 0) { return PUBLIC } if ((access and Opcodes.ACC_PROTECTED) != 0) { return PROTECTED } if ((access and Opcodes.ACC_PRIVATE) != 0) { return PRIVATE } return PACKAGE_PRIVATE } } } fun ClassNode.isEnum(): Boolean { return (this.access and Opcodes.ACC_ENUM) != 0 } Loading @@ -212,6 +235,10 @@ fun MethodNode.isSynthetic(): Boolean { return (this.access and Opcodes.ACC_SYNTHETIC) != 0 } fun MethodNode.isStatic(): Boolean { return (this.access and Opcodes.ACC_STATIC) != 0 } fun FieldNode.isEnum(): Boolean { return (this.access and Opcodes.ACC_ENUM) != 0 } Loading @@ -220,6 +247,19 @@ fun FieldNode.isSynthetic(): Boolean { return (this.access and Opcodes.ACC_SYNTHETIC) != 0 } fun ClassNode.getVisibility(): Visibility { return Visibility.fromAccess(this.access) } fun MethodNode.getVisibility(): Visibility { return Visibility.fromAccess(this.access) } fun FieldNode.getVisibility(): Visibility { return Visibility.fromAccess(this.access) } /* Dump of the members of TinyFrameworkEnumSimple: Loading
tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/visitors/BaseAdapter.kt +19 −7 Original line number Diff line number Diff line Loading @@ -17,8 +17,8 @@ package com.android.hoststubgen.visitors import com.android.hoststubgen.HostStubGenErrors import com.android.hoststubgen.LogLevel import com.android.hoststubgen.asm.UnifiedVisitor import com.android.hoststubgen.asm.ClassNodes import com.android.hoststubgen.asm.UnifiedVisitor import com.android.hoststubgen.asm.getPackageNameFromClassName import com.android.hoststubgen.asm.resolveClassName import com.android.hoststubgen.asm.toJvmClassName Loading Loading @@ -178,7 +178,9 @@ abstract class BaseAdapter ( log.d("visitMethod: %s%s [%x] [%s] Policy: %s", name, descriptor, access, signature, p) log.withIndent { // If it's a substitute-to method, then skip. // If it's a substitute-from method, then skip (== remove). // Instead of this method, we rename the substitute-to method with the original // name, in the "Maybe rename the method" part below. val policy = filter.getPolicyForMethod(currentClassName, name, descriptor) if (policy.policy.isSubstitute) { log.d("Skipping %s%s %s", name, descriptor, policy) Loading @@ -191,9 +193,19 @@ abstract class BaseAdapter ( // Maybe rename the method. val newName: String val substituteTo = filter.getRenameTo(currentClassName, name, descriptor) if (substituteTo != null) { newName = substituteTo val renameTo = filter.getRenameTo(currentClassName, name, descriptor) if (renameTo != null) { newName = renameTo // It's confusing, but here, `newName` is the original method name // (the one with the @substitute/replace annotation). // `name` is the name of the method we're currently visiting, so it's usually a // "...$ravewnwood" name. if (!checkSubstitutionMethodCompatibility( classes, currentClassName, newName, name, descriptor, options.errors)) { return null } log.v("Emitting %s.%s%s as %s %s", currentClassName, name, descriptor, newName, policy) } else { Loading @@ -203,12 +215,12 @@ abstract class BaseAdapter ( // Let subclass update the flag. // But note, we only use it when calling the super's method, // but not for visitMethodInner(), beucase when subclass wants to change access, // but not for visitMethodInner(), because when subclass wants to change access, // it can do so inside visitMethodInner(). val newAccess = updateAccessFlags(access, name, descriptor) val ret = visitMethodInner(access, newName, descriptor, signature, exceptions, policy, substituteTo != null, renameTo != null, super.visitMethod(newAccess, newName, descriptor, signature, exceptions)) ret?.let { Loading