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

Commit 4c2182d4 authored by John Wu's avatar John Wu
Browse files

[HostStubGen] Support ignore policy on more methods

Ignore policy used to only support methods that return void. Let's
extend support to all types, and return each type's default value.
Calling ignored methods will not crash and result in no-op at runtime,
however these methods are not considered as "supported".

Also add ignore support to text policy, and text policy only, as
annotations are reserved for supported classes.

Flag: EXEMPT host side test change only
Bug: 292141694
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh
Change-Id: Ida3e939b26e1a637b0a54f8e88fd6202ab0502c2
parent 18364887
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ enum class FilterPolicy {
        get() = this == SubstituteAndStub || this == SubstituteAndKeep

    val needsInStub: Boolean
        get() = this == Stub || this == StubClass || this == SubstituteAndStub
        get() = this == Stub || this == StubClass || this == SubstituteAndStub || this == Ignore

    val needsInImpl: Boolean
        get() = this != Remove
+1 −0
Original line number Diff line number Diff line
@@ -330,6 +330,7 @@ private fun parsePolicy(s: String): FilterPolicy {
        "r", "remove" -> FilterPolicy.Remove
        "sc", "stubclass" -> FilterPolicy.StubClass
        "kc", "keepclass" -> FilterPolicy.KeepClass
        "i", "ignore" -> FilterPolicy.Ignore
        else -> {
            if (s.startsWith("@")) {
                FilterPolicy.SubstituteAndStub
+30 −14
Original line number Diff line number Diff line
@@ -211,18 +211,11 @@ class ImplGeneratingAdapter(
            }

            if (policy.policy == FilterPolicy.Ignore) {
                when (Type.getReturnType(descriptor)) {
                    Type.VOID_TYPE -> {
                log.v("Making method ignored...")
                return IgnoreMethodAdapter(
                    access, name, descriptor, signature, exceptions, innerVisitor)
                    .withAnnotation(HostStubGenProcessedAsIgnore.CLASS_DESCRIPTOR)
            }
                    else -> {
                        throw RuntimeException("Ignored policy only allowed for void methods")
                    }
                }
            }
        }
        if (substituted) {
            innerVisitor?.withAnnotation(HostStubGenProcessedAsSubstitute.CLASS_DESCRIPTOR)
@@ -290,14 +283,37 @@ class ImplGeneratingAdapter(
     */
    private inner class IgnoreMethodAdapter(
            access: Int,
            val name: String,
            descriptor: String,
            name: String,
            val descriptor: String,
            signature: String?,
            exceptions: Array<String>?,
            next: MethodVisitor?
    ) : BodyReplacingMethodVisitor(access, name, descriptor, signature, exceptions, next) {
        override fun emitNewCode() {
            visitInsn(Opcodes.RETURN)
            when (Type.getReturnType(descriptor)) {
                Type.VOID_TYPE -> visitInsn(Opcodes.RETURN)
                Type.BOOLEAN_TYPE, Type.BYTE_TYPE, Type.CHAR_TYPE, Type.SHORT_TYPE,
                Type.INT_TYPE -> {
                    visitInsn(Opcodes.ICONST_0)
                    visitInsn(Opcodes.IRETURN)
                }
                Type.LONG_TYPE -> {
                    visitInsn(Opcodes.LCONST_0)
                    visitInsn(Opcodes.LRETURN)
                }
                Type.FLOAT_TYPE -> {
                    visitInsn(Opcodes.FCONST_0)
                    visitInsn(Opcodes.FRETURN)
                }
                Type.DOUBLE_TYPE -> {
                    visitInsn(Opcodes.DCONST_0)
                    visitInsn(Opcodes.DRETURN)
                }
                else -> {
                    visitInsn(Opcodes.ACONST_NULL)
                    visitInsn(Opcodes.ARETURN)
                }
            }
            visitMaxs(0, 0) // We let ASM figure them out.
        }
    }
+127 −1
Original line number Diff line number Diff line
@@ -1436,7 +1436,7 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPoli
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 3, methods: 10, attributes: 1
  interfaces: 0, fields: 3, methods: 19, attributes: 1
  public int stub;
    descriptor: I
    flags: (0x0001) ACC_PUBLIC
@@ -1513,6 +1513,132 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPoli
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;
            0       8     1   foo   Ljava/lang/String;

  public java.lang.String toBeIgnoredObj();
    descriptor: ()Ljava/lang/String;
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public void toBeIgnoredV();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public boolean toBeIgnoredZ();
    descriptor: ()Z
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public byte toBeIgnoredB();
    descriptor: ()B
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public char toBeIgnoredC();
    descriptor: ()C
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public short toBeIgnoredS();
    descriptor: ()S
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public int toBeIgnoredI();
    descriptor: ()I
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public float toBeIgnoredF();
    descriptor: ()F
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public double toBeIgnoredD();
    descriptor: ()D
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":()V
         x: athrow
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy;

  public int addTwo(int);
    descriptor: (I)I
    flags: (0x0001) ACC_PUBLIC
+145 −1
Original line number Diff line number Diff line
@@ -1197,7 +1197,7 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPoli
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 1, methods: 5, attributes: 2
  interfaces: 0, fields: 1, methods: 14, attributes: 2
  public int stub;
    descriptor: I
    flags: (0x0001) ACC_PUBLIC
@@ -1239,6 +1239,150 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPoli
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public java.lang.String toBeIgnoredObj();
    descriptor: ()Ljava/lang/String;
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public void toBeIgnoredV();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public boolean toBeIgnoredZ();
    descriptor: ()Z
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public byte toBeIgnoredB();
    descriptor: ()B
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public char toBeIgnoredC();
    descriptor: ()C
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public short toBeIgnoredS();
    descriptor: ()S
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public int toBeIgnoredI();
    descriptor: ()I
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public float toBeIgnoredF();
    descriptor: ()F
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public double toBeIgnoredD();
    descriptor: ()D
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         x: new           #x                 // class java/lang/RuntimeException
         x: dup
         x: ldc           #x                 // String Stub!
         x: invokespecial #x                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
         x: athrow
    RuntimeVisibleAnnotations:
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInStub
      x: #x()
        com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl

  public int addTwo(int);
    descriptor: (I)I
    flags: (0x0001) ACC_PUBLIC
Loading