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

Commit 58ba36c9 authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "[HostStubGen] Tweak "filter reason" handling on..." into main

parents de15ef1e 2581b7e8
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -20,6 +20,12 @@ import com.android.hoststubgen.utils.Trie

/**
 * Filter to apply a policy to classes inside a package, either directly or indirectly.
 *
 * Note, because package-wide policies are defined in the policy file, it takes precedence
 * over annotations. However, if a class has both a package policy and other (lower-priority)
 * policies such as an annotation-based policy and if they're the same, we use the other policy's
 * "reason" instead. This allows us to differentiate "APIs that are enabled with an annotation"
 * from "APIs that are enabled by a package policy (which is usually used during development)".
 */
class PackageFilter(
    fallback: OutputFilter
@@ -55,7 +61,19 @@ class PackageFilter(
    }

    override fun getPolicyForClass(className: String): FilterPolicyWithReason {
        return mPackagePolicies[getPackageKeyFromClass(className)]
            ?: super.getPolicyForClass(className)
        val packageWidePolicy = mPackagePolicies[getPackageKeyFromClass(className)]
        val origPolicy = super.getPolicyForClass(className)

        // If there's no package-wide policy, just fall-back.
        if (packageWidePolicy == null) {
            return origPolicy
        }

        // Otherwise, see if the package wide policy is different from the fallback policy.
        // If they're the same, use the fallback one.
        if (packageWidePolicy.policy == origPolicy.policy) {
            return origPolicy
        }
        return packageWidePolicy
    }
}
+51 −1
Original line number Diff line number Diff line
@@ -3463,7 +3463,7 @@ public class com.android.hoststubgen.test.tinyframework.packagetest.A
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/packagetest/A
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 1, attributes: 1
  interfaces: 0, fields: 0, methods: 2, attributes: 1
Constant pool:
{
  public com.android.hoststubgen.test.tinyframework.packagetest.A();
@@ -3478,6 +3478,17 @@ Constant pool:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/A;

  public void foo();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=0, locals=1, args_size=1
         x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       1     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/A;
}
SourceFile: "A.java"
## Class: com/android/hoststubgen/test/tinyframework/packagetest/B.class
@@ -3505,6 +3516,45 @@ Constant pool:
            0       5     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/B;
}
SourceFile: "B.java"
## Class: com/android/hoststubgen/test/tinyframework/packagetest/C.class
  Compiled from "C.java"
public class com.android.hoststubgen.test.tinyframework.packagetest.C
  minor version: 0
  major version: 65
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/packagetest/C
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 2, attributes: 2
Constant pool:
{
  public com.android.hoststubgen.test.tinyframework.packagetest.C();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         x: aload_0
         x: invokespecial #x                  // Method java/lang/Object."<init>":()V
         x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/C;

  public void foo();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=0, locals=1, args_size=1
         x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       1     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/C;
}
SourceFile: "C.java"
RuntimeInvisibleAnnotations:
  x: #x()
    android.hosttest.annotation.HostSideTestWholeClassKeep
## Class: com/android/hoststubgen/test/tinyframework/packagetest/sub/A.class
  Compiled from "A.java"
public class com.android.hoststubgen.test.tinyframework.packagetest.sub.A
+105 −2
Original line number Diff line number Diff line
@@ -4058,9 +4058,42 @@ public class com.android.hoststubgen.test.tinyframework.packagetest.A
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/packagetest/A
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 0, attributes: 2
  interfaces: 0, fields: 0, methods: 2, attributes: 2
Constant pool:
{
  public com.android.hoststubgen.test.tinyframework.packagetest.A();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         x: aload_0
         x: invokespecial #x                 // Method java/lang/Object."<init>":()V
         x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/A;
    RuntimeVisibleAnnotations:
      x: #x(#x=s#x)
        com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
          reason="class-wide in com/android/hoststubgen/test/tinyframework/packagetest/A [inner-reason: file-override (test-package-policy)]"
        )

  public void foo();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=0, locals=1, args_size=1
         x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       1     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/A;
    RuntimeVisibleAnnotations:
      x: #x(#x=s#x)
        com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
          reason="class-wide in com/android/hoststubgen/test/tinyframework/packagetest/A [inner-reason: file-override (test-package-policy)]"
        )
}
SourceFile: "A.java"
RuntimeVisibleAnnotations:
@@ -4068,6 +4101,59 @@ RuntimeVisibleAnnotations:
    com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
      reason="file-override (test-package-policy)"
    )
## Class: com/android/hoststubgen/test/tinyframework/packagetest/C.class
  Compiled from "C.java"
public class com.android.hoststubgen.test.tinyframework.packagetest.C
  minor version: 0
  major version: 65
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/packagetest/C
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 2, attributes: 2
Constant pool:
{
  public com.android.hoststubgen.test.tinyframework.packagetest.C();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         x: aload_0
         x: invokespecial #x                 // Method java/lang/Object."<init>":()V
         x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/C;
    RuntimeVisibleAnnotations:
      x: #x(#x=s#x)
        com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
          reason="class-wide in com/android/hoststubgen/test/tinyframework/packagetest/C [inner-reason: class-annotation]"
        )

  public void foo();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=0, locals=1, args_size=1
         x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       1     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/C;
    RuntimeVisibleAnnotations:
      x: #x(#x=s#x)
        com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
          reason="class-wide in com/android/hoststubgen/test/tinyframework/packagetest/C [inner-reason: class-annotation]"
        )
}
SourceFile: "C.java"
RuntimeVisibleAnnotations:
  x: #x(#x=s#x)
    com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
      reason="class-annotation"
    )
  x: #x()
    android.hosttest.annotation.HostSideTestWholeClassKeep
## Class: com/android/hoststubgen/test/tinyframework/packagetest/sub/A.class
  Compiled from "A.java"
public class com.android.hoststubgen.test.tinyframework.packagetest.sub.A
@@ -4076,9 +4162,26 @@ public class com.android.hoststubgen.test.tinyframework.packagetest.sub.A
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/packagetest/sub/A
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 0, attributes: 2
  interfaces: 0, fields: 0, methods: 1, attributes: 2
Constant pool:
{
  public com.android.hoststubgen.test.tinyframework.packagetest.sub.A();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         x: aload_0
         x: invokespecial #x                 // Method java/lang/Object."<init>":()V
         x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/sub/A;
    RuntimeVisibleAnnotations:
      x: #x(#x=s#x)
        com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
          reason="class-wide in com/android/hoststubgen/test/tinyframework/packagetest/sub/A [inner-reason: file-override (test-package-policy)]"
        )
}
SourceFile: "A.java"
RuntimeVisibleAnnotations:
+142 −2
Original line number Diff line number Diff line
@@ -4982,7 +4982,7 @@ public class com.android.hoststubgen.test.tinyframework.packagetest.A
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/packagetest/A
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 1, attributes: 2
  interfaces: 0, fields: 0, methods: 3, attributes: 2
Constant pool:
{
  private static {};
@@ -4994,6 +4994,50 @@ Constant pool:
         x: ldc           #x                 // String com.android.hoststubgen.hosthelper.HostTestUtils.logClassLoaded
         x: invokestatic  #x                 // Method com/android/hoststubgen/hosthelper/HostTestUtils.onClassLoaded:(Ljava/lang/Class;Ljava/lang/String;)V
         x: return

  public com.android.hoststubgen.test.tinyframework.packagetest.A();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=4, locals=1, args_size=1
         x: ldc           #x                  // class com/android/hoststubgen/test/tinyframework/packagetest/A
         x: ldc           #x                 // String <init>
         x: ldc           #x                 // String ()V
         x: ldc           #x                 // String com.android.hoststubgen.hosthelper.HostTestUtils.logMethodCall
         x: invokestatic  #x                 // Method com/android/hoststubgen/hosthelper/HostTestUtils.callMethodCallHook:(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
        x: aload_0
        x: invokespecial #x                 // Method java/lang/Object."<init>":()V
        x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
           11       5     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/A;
    RuntimeVisibleAnnotations:
      x: #x(#x=s#x)
        com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
          reason="class-wide in com/android/hoststubgen/test/tinyframework/packagetest/A [inner-reason: file-override (test-package-policy)]"
        )

  public void foo();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=4, locals=1, args_size=1
         x: ldc           #x                  // class com/android/hoststubgen/test/tinyframework/packagetest/A
         x: ldc           #x                 // String foo
         x: ldc           #x                 // String ()V
         x: ldc           #x                 // String com.android.hoststubgen.hosthelper.HostTestUtils.logMethodCall
         x: invokestatic  #x                 // Method com/android/hoststubgen/hosthelper/HostTestUtils.callMethodCallHook:(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
        x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
           11       1     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/A;
    RuntimeVisibleAnnotations:
      x: #x(#x=s#x)
        com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
          reason="class-wide in com/android/hoststubgen/test/tinyframework/packagetest/A [inner-reason: file-override (test-package-policy)]"
        )
}
SourceFile: "A.java"
RuntimeVisibleAnnotations:
@@ -5001,6 +5045,79 @@ RuntimeVisibleAnnotations:
    com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
      reason="file-override (test-package-policy)"
    )
## Class: com/android/hoststubgen/test/tinyframework/packagetest/C.class
  Compiled from "C.java"
public class com.android.hoststubgen.test.tinyframework.packagetest.C
  minor version: 0
  major version: 65
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/packagetest/C
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 3, attributes: 2
Constant pool:
{
  private static {};
    descriptor: ()V
    flags: (0x000a) ACC_PRIVATE, ACC_STATIC
    Code:
      stack=2, locals=0, args_size=0
         x: ldc           #x                  // class com/android/hoststubgen/test/tinyframework/packagetest/C
         x: ldc           #x                 // String com.android.hoststubgen.hosthelper.HostTestUtils.logClassLoaded
         x: invokestatic  #x                 // Method com/android/hoststubgen/hosthelper/HostTestUtils.onClassLoaded:(Ljava/lang/Class;Ljava/lang/String;)V
         x: return

  public com.android.hoststubgen.test.tinyframework.packagetest.C();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=4, locals=1, args_size=1
         x: ldc           #x                  // class com/android/hoststubgen/test/tinyframework/packagetest/C
         x: ldc           #x                 // String <init>
         x: ldc           #x                 // String ()V
         x: ldc           #x                 // String com.android.hoststubgen.hosthelper.HostTestUtils.logMethodCall
         x: invokestatic  #x                 // Method com/android/hoststubgen/hosthelper/HostTestUtils.callMethodCallHook:(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
        x: aload_0
        x: invokespecial #x                 // Method java/lang/Object."<init>":()V
        x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
           11       5     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/C;
    RuntimeVisibleAnnotations:
      x: #x(#x=s#x)
        com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
          reason="class-wide in com/android/hoststubgen/test/tinyframework/packagetest/C [inner-reason: class-annotation]"
        )

  public void foo();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=4, locals=1, args_size=1
         x: ldc           #x                  // class com/android/hoststubgen/test/tinyframework/packagetest/C
         x: ldc           #x                 // String foo
         x: ldc           #x                 // String ()V
         x: ldc           #x                 // String com.android.hoststubgen.hosthelper.HostTestUtils.logMethodCall
         x: invokestatic  #x                 // Method com/android/hoststubgen/hosthelper/HostTestUtils.callMethodCallHook:(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
        x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
           11       1     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/C;
    RuntimeVisibleAnnotations:
      x: #x(#x=s#x)
        com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
          reason="class-wide in com/android/hoststubgen/test/tinyframework/packagetest/C [inner-reason: class-annotation]"
        )
}
SourceFile: "C.java"
RuntimeVisibleAnnotations:
  x: #x(#x=s#x)
    com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
      reason="class-annotation"
    )
  x: #x()
    android.hosttest.annotation.HostSideTestWholeClassKeep
## Class: com/android/hoststubgen/test/tinyframework/packagetest/sub/A.class
  Compiled from "A.java"
public class com.android.hoststubgen.test.tinyframework.packagetest.sub.A
@@ -5009,7 +5126,7 @@ public class com.android.hoststubgen.test.tinyframework.packagetest.sub.A
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #x                          // com/android/hoststubgen/test/tinyframework/packagetest/sub/A
  super_class: #x                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 1, attributes: 2
  interfaces: 0, fields: 0, methods: 2, attributes: 2
Constant pool:
{
  private static {};
@@ -5021,6 +5138,29 @@ Constant pool:
         x: ldc           #x                 // String com.android.hoststubgen.hosthelper.HostTestUtils.logClassLoaded
         x: invokestatic  #x                 // Method com/android/hoststubgen/hosthelper/HostTestUtils.onClassLoaded:(Ljava/lang/Class;Ljava/lang/String;)V
         x: return

  public com.android.hoststubgen.test.tinyframework.packagetest.sub.A();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=4, locals=1, args_size=1
         x: ldc           #x                  // class com/android/hoststubgen/test/tinyframework/packagetest/sub/A
         x: ldc           #x                 // String <init>
         x: ldc           #x                 // String ()V
         x: ldc           #x                 // String com.android.hoststubgen.hosthelper.HostTestUtils.logMethodCall
         x: invokestatic  #x                 // Method com/android/hoststubgen/hosthelper/HostTestUtils.callMethodCallHook:(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
        x: aload_0
        x: invokespecial #x                 // Method java/lang/Object."<init>":()V
        x: return
      LineNumberTable:
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
           11       5     0  this   Lcom/android/hoststubgen/test/tinyframework/packagetest/sub/A;
    RuntimeVisibleAnnotations:
      x: #x(#x=s#x)
        com.android.hoststubgen.hosthelper.HostStubGenProcessedAsKeep(
          reason="class-wide in com/android/hoststubgen/test/tinyframework/packagetest/sub/A [inner-reason: file-override (test-package-policy)]"
        )
}
SourceFile: "A.java"
RuntimeVisibleAnnotations:
+55 −0
Original line number Diff line number Diff line
@@ -1164,6 +1164,61 @@ com.android.hoststubgen.test.tinyframework
  class-wide in com/android/hoststubgen/test/tinyframework/TinyFrameworkUnsupportedApiException [inner-reason: class-annotation]
  1
  1
com.android.hoststubgen.test.tinyframework.packagetest
  A
  0
  com.android.hoststubgen.test.tinyframework.packagetest.A
  <init>
  <init>()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/packagetest/A [inner-reason: file-override (test-package-policy)]
  1
  1
com.android.hoststubgen.test.tinyframework.packagetest
  A
  0
  com.android.hoststubgen.test.tinyframework.packagetest.A
  foo
  foo()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/packagetest/A [inner-reason: file-override (test-package-policy)]
  0
  2
com.android.hoststubgen.test.tinyframework.packagetest
  C
  0
  com.android.hoststubgen.test.tinyframework.packagetest.C
  <init>
  <init>()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/packagetest/C [inner-reason: class-annotation]
  1
  1
com.android.hoststubgen.test.tinyframework.packagetest
  C
  0
  com.android.hoststubgen.test.tinyframework.packagetest.C
  foo
  foo()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/packagetest/C [inner-reason: class-annotation]
  0
  2
com.android.hoststubgen.test.tinyframework.packagetest.sub
  A
  0
  com.android.hoststubgen.test.tinyframework.packagetest.sub.A
  <init>
  <init>()V
  1
  Keep
  class-wide in com/android/hoststubgen/test/tinyframework/packagetest/sub/A [inner-reason: file-override (test-package-policy)]
  1
  1
com.supported
  UnsupportedClass
  0
Loading