diff options
| author | 2023-12-04 08:44:26 -0800 | |
|---|---|---|
| committer | 2023-12-04 10:41:11 -0800 | |
| commit | 39d2c720cd407481ebf9d348c7dcd5bc5df6cb8e (patch) | |
| tree | 9d4160f18f0c6a159968ab3eb080935f162e9c33 | |
| parent | 7812cce9adbe283cf84b18584fdd52eb4d703958 (diff) | |
HostStubGen: Allow @Throw on @NativeSubstitutionClass native methods
Bug: 292141694
Test: ./scripts/run-all-tests.sh
Change-Id: If16c9abaeeefbf68acac0f90d8ef394871ce542a
14 files changed, 262 insertions, 89 deletions
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java index 86628d95b25a..f2930fe45295 100644 --- a/core/java/android/os/Parcel.java +++ b/core/java/android/os/Parcel.java @@ -27,6 +27,10 @@ import android.annotation.SuppressLint; import android.annotation.TestApi; import android.app.AppOpsManager; import android.compat.annotation.UnsupportedAppUsage; +import android.ravenwood.annotation.RavenwoodKeepWholeClass; +import android.ravenwood.annotation.RavenwoodNativeSubstitutionClass; +import android.ravenwood.annotation.RavenwoodReplace; +import android.ravenwood.annotation.RavenwoodThrow; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; @@ -228,6 +232,8 @@ import java.util.function.IntFunction; * {@link #readMap(Map, ClassLoader, Class, Class)}, * {@link #readSparseArray(ClassLoader, Class)}. */ +@RavenwoodKeepWholeClass +@RavenwoodNativeSubstitutionClass("com.android.hoststubgen.nativesubstitution.Parcel_host") public final class Parcel { private static final boolean DEBUG_RECYCLE = false; @@ -382,8 +388,10 @@ public final class Parcel { @CriticalNative private static native void nativeMarkSensitive(long nativePtr); @FastNative + @RavenwoodThrow private static native void nativeMarkForBinder(long nativePtr, IBinder binder); @CriticalNative + @RavenwoodThrow private static native boolean nativeIsForRpc(long nativePtr); @CriticalNative private static native int nativeDataSize(long nativePtr); @@ -415,14 +423,17 @@ public final class Parcel { private static native int nativeWriteFloat(long nativePtr, float val); @CriticalNative private static native int nativeWriteDouble(long nativePtr, double val); + @RavenwoodThrow private static native void nativeSignalExceptionForError(int error); @FastNative private static native void nativeWriteString8(long nativePtr, String val); @FastNative private static native void nativeWriteString16(long nativePtr, String val); @FastNative + @RavenwoodThrow private static native void nativeWriteStrongBinder(long nativePtr, IBinder val); @FastNative + @RavenwoodThrow private static native void nativeWriteFileDescriptor(long nativePtr, FileDescriptor val); private static native byte[] nativeCreateByteArray(long nativePtr); @@ -441,8 +452,10 @@ public final class Parcel { @FastNative private static native String nativeReadString16(long nativePtr); @FastNative + @RavenwoodThrow private static native IBinder nativeReadStrongBinder(long nativePtr); @FastNative + @RavenwoodThrow private static native FileDescriptor nativeReadFileDescriptor(long nativePtr); private static native long nativeCreate(); @@ -452,7 +465,9 @@ public final class Parcel { private static native byte[] nativeMarshall(long nativePtr); private static native void nativeUnmarshall( long nativePtr, byte[] data, int offset, int length); + @RavenwoodThrow private static native int nativeCompareData(long thisNativePtr, long otherNativePtr); + @RavenwoodThrow private static native boolean nativeCompareDataInRange( long ptrA, int offsetA, long ptrB, int offsetB, int length); private static native void nativeAppendFrom( @@ -461,13 +476,17 @@ public final class Parcel { private static native boolean nativeHasFileDescriptors(long nativePtr); private static native boolean nativeHasFileDescriptorsInRange( long nativePtr, int offset, int length); + @RavenwoodThrow private static native void nativeWriteInterfaceToken(long nativePtr, String interfaceName); + @RavenwoodThrow private static native void nativeEnforceInterface(long nativePtr, String interfaceName); @CriticalNative + @RavenwoodThrow private static native boolean nativeReplaceCallingWorkSourceUid( long nativePtr, int workSourceUid); @CriticalNative + @RavenwoodThrow private static native int nativeReadCallingWorkSourceUid(long nativePtr); /** Last time exception with a stack trace was written */ @@ -476,6 +495,7 @@ public final class Parcel { private static final int WRITE_EXCEPTION_STACK_TRACE_THRESHOLD_MS = 1000; @CriticalNative + @RavenwoodThrow private static native long nativeGetOpenAshmemSize(long nativePtr); public final static Parcelable.Creator<String> STRING_CREATOR @@ -634,10 +654,12 @@ public final class Parcel { /** @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @RavenwoodThrow public static native long getGlobalAllocSize(); /** @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @RavenwoodThrow public static native long getGlobalAllocCount(); /** @@ -2918,6 +2940,7 @@ public final class Parcel { * @see #writeNoException * @see #readException */ + @RavenwoodReplace public final void writeException(@NonNull Exception e) { AppOpsManager.prefixParcelWithAppOpsIfNeeded(this); @@ -3017,6 +3040,7 @@ public final class Parcel { * @see #writeException * @see #readException */ + @RavenwoodReplace public final void writeNoException() { AppOpsManager.prefixParcelWithAppOpsIfNeeded(this); diff --git a/core/java/android/os/Parcelable.java b/core/java/android/os/Parcelable.java index f2b60a4e3988..b5c09bb09f46 100644 --- a/core/java/android/os/Parcelable.java +++ b/core/java/android/os/Parcelable.java @@ -19,6 +19,7 @@ package android.os; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.SystemApi; +import android.ravenwood.annotation.RavenwoodKeepWholeClass; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -86,6 +87,7 @@ import java.lang.annotation.RetentionPolicy; * } * }</pre></section></div></div> */ +@RavenwoodKeepWholeClass public interface Parcelable { /** @hide */ @IntDef(flag = true, prefix = { "PARCELABLE_" }, value = { diff --git a/ravenwood/framework-minus-apex-ravenwood-policies.txt b/ravenwood/framework-minus-apex-ravenwood-policies.txt index a75bba6a347f..6a6ae3876f6b 100644 --- a/ravenwood/framework-minus-apex-ravenwood-policies.txt +++ b/ravenwood/framework-minus-apex-ravenwood-policies.txt @@ -92,12 +92,6 @@ class com.android.internal.util.StringPool stubclass class com.android.internal.os.SomeArgs stubclass # Parcel -class android.os.Parcel stubclass - method writeException (Ljava/lang/Exception;)V @writeException$ravenwood - method writeNoException ()V @writeNoException$ravenwood -class android.os.Parcel !com.android.hoststubgen.nativesubstitution.Parcel_host - -class android.os.Parcelable stubclass class android.os.ParcelFormatException stubclass class android.os.BadParcelableException stubclass class android.os.BadTypeParcelableException stubclass diff --git a/ravenwood/ravenwood-annotation-allowed-classes.txt b/ravenwood/ravenwood-annotation-allowed-classes.txt index 72e9ba367bc9..290293234b34 100644 --- a/ravenwood/ravenwood-annotation-allowed-classes.txt +++ b/ravenwood/ravenwood-annotation-allowed-classes.txt @@ -23,6 +23,8 @@ android.os.IBinder android.os.Looper android.os.Message android.os.MessageQueue +android.os.Parcel +android.os.Parcelable android.os.Process android.os.SystemClock android.os.ThreadLocalWorkSource diff --git a/tools/hoststubgen/hoststubgen/helper-framework-runtime-src/framework/com/android/hoststubgen/nativesubstitution/Parcel_host.java b/tools/hoststubgen/hoststubgen/helper-framework-runtime-src/framework/com/android/hoststubgen/nativesubstitution/Parcel_host.java index 22553451e128..3bcabcb01c5e 100644 --- a/tools/hoststubgen/hoststubgen/helper-framework-runtime-src/framework/com/android/hoststubgen/nativesubstitution/Parcel_host.java +++ b/tools/hoststubgen/hoststubgen/helper-framework-runtime-src/framework/com/android/hoststubgen/nativesubstitution/Parcel_host.java @@ -15,9 +15,6 @@ */ package com.android.hoststubgen.nativesubstitution; -import android.os.IBinder; - -import java.io.FileDescriptor; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -143,12 +140,6 @@ public class Parcel_host { public static void nativeMarkSensitive(long nativePtr) { getInstance(nativePtr).mSensitive = true; } - public static void nativeMarkForBinder(long nativePtr, IBinder binder) { - throw new RuntimeException("Not implemented yet"); - } - public static boolean nativeIsForRpc(long nativePtr) { - throw new RuntimeException("Not implemented yet"); - } public static int nativeDataSize(long nativePtr) { return getInstance(nativePtr).mSize; } @@ -236,9 +227,6 @@ public class Parcel_host { public static int nativeWriteDouble(long nativePtr, double val) { return nativeWriteLong(nativePtr, Double.doubleToLongBits(val)); } - public static void nativeSignalExceptionForError(int error) { - throw new RuntimeException("Not implemented yet"); - } private static int align4(int val) { return ((val + 3) / 4) * 4; @@ -256,12 +244,6 @@ public class Parcel_host { // Just reuse String8 nativeWriteString8(nativePtr, val); } - public static void nativeWriteStrongBinder(long nativePtr, IBinder val) { - throw new RuntimeException("Not implemented yet"); - } - public static void nativeWriteFileDescriptor(long nativePtr, FileDescriptor val) { - throw new RuntimeException("Not implemented yet"); - } public static byte[] nativeCreateByteArray(long nativePtr) { return nativeReadBlob(nativePtr); @@ -348,12 +330,6 @@ public class Parcel_host { public static String nativeReadString16(long nativePtr) { return nativeReadString8(nativePtr); } - public static IBinder nativeReadStrongBinder(long nativePtr) { - throw new RuntimeException("Not implemented yet"); - } - public static FileDescriptor nativeReadFileDescriptor(long nativePtr) { - throw new RuntimeException("Not implemented yet"); - } public static byte[] nativeMarshall(long nativePtr) { var p = getInstance(nativePtr); @@ -367,13 +343,6 @@ public class Parcel_host { p.mPos += length; p.updateSize(); } - public static int nativeCompareData(long thisNativePtr, long otherNativePtr) { - throw new RuntimeException("Not implemented yet"); - } - public static boolean nativeCompareDataInRange( - long ptrA, int offsetA, long ptrB, int offsetB, int length) { - throw new RuntimeException("Not implemented yet"); - } public static void nativeAppendFrom( long thisNativePtr, long otherNativePtr, int srcOffset, int length) { var dst = getInstance(thisNativePtr); @@ -397,28 +366,4 @@ public class Parcel_host { // Assume false for now, because we don't support writing FDs yet. return false; } - public static void nativeWriteInterfaceToken(long nativePtr, String interfaceName) { - throw new RuntimeException("Not implemented yet"); - } - public static void nativeEnforceInterface(long nativePtr, String interfaceName) { - throw new RuntimeException("Not implemented yet"); - } - - public static boolean nativeReplaceCallingWorkSourceUid( - long nativePtr, int workSourceUid) { - throw new RuntimeException("Not implemented yet"); - } - public static int nativeReadCallingWorkSourceUid(long nativePtr) { - throw new RuntimeException("Not implemented yet"); - } - - public static long nativeGetOpenAshmemSize(long nativePtr) { - throw new RuntimeException("Not implemented yet"); - } - public static long getGlobalAllocSize() { - throw new RuntimeException("Not implemented yet"); - } - public static long getGlobalAllocCount() { - throw new RuntimeException("Not implemented yet"); - } } diff --git a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/visitors/ImplGeneratingAdapter.kt b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/visitors/ImplGeneratingAdapter.kt index 9274a96ed9f2..416b78242899 100644 --- a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/visitors/ImplGeneratingAdapter.kt +++ b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/visitors/ImplGeneratingAdapter.kt @@ -192,18 +192,24 @@ class ImplGeneratingAdapter( } log.withIndent { + var willThrow = false + if (policy.policy == FilterPolicy.Throw) { + log.v("Making method throw...") + willThrow = true + innerVisitor = ThrowingMethodAdapter( + access, name, descriptor, signature, exceptions, innerVisitor) + .withAnnotation(HostStubGenProcessedAsThrow.CLASS_DESCRIPTOR) + } if ((access and Opcodes.ACC_NATIVE) != 0 && nativeSubstitutionClass != null) { log.v("Rewriting native method...") return NativeSubstitutingMethodAdapter( access, name, descriptor, signature, exceptions, innerVisitor) .withAnnotation(HostStubGenProcessedAsSubstitute.CLASS_DESCRIPTOR) } - if (policy.policy == FilterPolicy.Throw) { - log.v("Making method throw...") - return ThrowingMethodAdapter( - access, name, descriptor, signature, exceptions, innerVisitor) - .withAnnotation(HostStubGenProcessedAsThrow.CLASS_DESCRIPTOR) + if (willThrow) { + return innerVisitor } + if (policy.policy == FilterPolicy.Ignore) { when (Type.getReturnType(descriptor)) { Type.VOID_TYPE -> { @@ -218,8 +224,8 @@ class ImplGeneratingAdapter( } } } - if (substituted && innerVisitor != null) { - innerVisitor.withAnnotation(HostStubGenProcessedAsSubstitute.CLASS_DESCRIPTOR) + if (substituted) { + innerVisitor?.withAnnotation(HostStubGenProcessedAsSubstitute.CLASS_DESCRIPTOR) } return innerVisitor @@ -309,13 +315,13 @@ class ImplGeneratingAdapter( next: MethodVisitor? ) : MethodVisitor(OPCODE_VERSION, next) { override fun visitCode() { - super.visitCode() - throw RuntimeException("NativeSubstitutingMethodVisitor should be called on " + " native method, where visitCode() shouldn't be called.") } override fun visitEnd() { + super.visitCode() + var targetDescriptor = descriptor var argOffset = 0 diff --git a/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/01-hoststubgen-test-tiny-framework-orig-dump.txt b/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/01-hoststubgen-test-tiny-framework-orig-dump.txt index 3956893ee7ed..70f56ae37a97 100644 --- a/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/01-hoststubgen-test-tiny-framework-orig-dump.txt +++ b/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/01-hoststubgen-test-tiny-framework-orig-dump.txt @@ -1817,7 +1817,7 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative flags: (0x0021) ACC_PUBLIC, ACC_SUPER this_class: #x // com/android/hoststubgen/test/tinyframework/TinyFrameworkNative super_class: #x // java/lang/Object - interfaces: 0, fields: 1, methods: 8, attributes: 2 + interfaces: 0, fields: 1, methods: 10, attributes: 2 int value; descriptor: I flags: (0x0000) @@ -1904,6 +1904,24 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative Start Length Slot Name Signature 0 6 0 this Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkNative; 0 6 1 arg I + + public static native void nativeStillNotSupported(); + descriptor: ()V + flags: (0x0109) ACC_PUBLIC, ACC_STATIC, ACC_NATIVE + RuntimeInvisibleAnnotations: + x: #x() + android.hosttest.annotation.HostSideTestThrow + + public static void nativeStillNotSupported_should_be_like_this(); + descriptor: ()V + flags: (0x0009) ACC_PUBLIC, ACC_STATIC + Code: + stack=2, locals=0, args_size=0 + x: new #x // class java/lang/RuntimeException + x: dup + x: invokespecial #x // Method java/lang/RuntimeException."<init>":()V + x: athrow + LineNumberTable: } SourceFile: "TinyFrameworkNative.java" RuntimeInvisibleAnnotations: diff --git a/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/02-hoststubgen-test-tiny-framework-host-stub-dump.txt b/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/02-hoststubgen-test-tiny-framework-host-stub-dump.txt index ebe14225a825..b0db48347d46 100644 --- a/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/02-hoststubgen-test-tiny-framework-host-stub-dump.txt +++ b/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/02-hoststubgen-test-tiny-framework-host-stub-dump.txt @@ -1538,7 +1538,7 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative flags: (0x0021) ACC_PUBLIC, ACC_SUPER this_class: #x // com/android/hoststubgen/test/tinyframework/TinyFrameworkNative super_class: #x // java/lang/Object - interfaces: 0, fields: 1, methods: 8, attributes: 3 + interfaces: 0, fields: 1, methods: 9, attributes: 3 int value; descriptor: I flags: (0x0000) @@ -1654,6 +1654,22 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative com.android.hoststubgen.hosthelper.HostStubGenKeptInStub x: #x() com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl + + public static void nativeStillNotSupported_should_be_like_this(); + descriptor: ()V + flags: (0x0009) ACC_PUBLIC, ACC_STATIC + Code: + stack=3, locals=0, args_size=0 + 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 } SourceFile: "TinyFrameworkNative.java" RuntimeVisibleAnnotations: diff --git a/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/03-hoststubgen-test-tiny-framework-host-impl-dump.txt b/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/03-hoststubgen-test-tiny-framework-host-impl-dump.txt index 4cb2a9f326f9..112f69e43c69 100644 --- a/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/03-hoststubgen-test-tiny-framework-host-impl-dump.txt +++ b/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/03-hoststubgen-test-tiny-framework-host-impl-dump.txt @@ -2220,7 +2220,7 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative flags: (0x0021) ACC_PUBLIC, ACC_SUPER this_class: #x // com/android/hoststubgen/test/tinyframework/TinyFrameworkNative super_class: #x // java/lang/Object - interfaces: 0, fields: 1, methods: 8, attributes: 3 + interfaces: 0, fields: 1, methods: 10, attributes: 3 int value; descriptor: I flags: (0x0000) @@ -2375,6 +2375,50 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative com.android.hoststubgen.hosthelper.HostStubGenKeptInStub x: #x() com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl + + public static void nativeStillNotSupported(); + descriptor: ()V + flags: (0x0009) ACC_PUBLIC, ACC_STATIC + Code: + stack=4, locals=0, args_size=0 + x: ldc #x // String com/android/hoststubgen/test/tinyframework/TinyFrameworkNative + x: ldc #x // String nativeStillNotSupported + x: ldc #x // String ()V + x: invokestatic #x // Method com/android/hoststubgen/hosthelper/HostTestUtils.getStackWalker:()Ljava/lang/StackWalker; + x: invokevirtual #x // Method java/lang/StackWalker.getCallerClass:()Ljava/lang/Class; + x: invokestatic #x // Method com/android/hoststubgen/hosthelper/HostTestUtils.onNonStubMethodCalled:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Class;)V + x: invokestatic #x // Method com/android/hoststubgen/hosthelper/HostTestUtils.onThrowMethodCalled:()V + x: new #x // class java/lang/RuntimeException + x: dup + x: ldc #x // String Unreachable + x: invokespecial #x // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V + x: athrow + RuntimeVisibleAnnotations: + x: #x() + com.android.hoststubgen.hosthelper.HostStubGenProcessedAsThrow + x: #x() + com.android.hoststubgen.hosthelper.HostStubGenProcessedAsSubstitute + x: #x() + com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl + RuntimeInvisibleAnnotations: + x: #x() + android.hosttest.annotation.HostSideTestThrow + + public static void nativeStillNotSupported_should_be_like_this(); + descriptor: ()V + flags: (0x0009) ACC_PUBLIC, ACC_STATIC + Code: + stack=2, locals=0, args_size=0 + x: new #x // class java/lang/RuntimeException + x: dup + x: invokespecial #x // Method java/lang/RuntimeException."<init>":()V + x: athrow + LineNumberTable: + RuntimeVisibleAnnotations: + x: #x() + com.android.hoststubgen.hosthelper.HostStubGenKeptInStub + x: #x() + com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl } SourceFile: "TinyFrameworkNative.java" RuntimeVisibleAnnotations: diff --git a/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/12-hoststubgen-test-tiny-framework-host-ext-stub-dump.txt b/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/12-hoststubgen-test-tiny-framework-host-ext-stub-dump.txt index ebe14225a825..b0db48347d46 100644 --- a/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/12-hoststubgen-test-tiny-framework-host-ext-stub-dump.txt +++ b/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/12-hoststubgen-test-tiny-framework-host-ext-stub-dump.txt @@ -1538,7 +1538,7 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative flags: (0x0021) ACC_PUBLIC, ACC_SUPER this_class: #x // com/android/hoststubgen/test/tinyframework/TinyFrameworkNative super_class: #x // java/lang/Object - interfaces: 0, fields: 1, methods: 8, attributes: 3 + interfaces: 0, fields: 1, methods: 9, attributes: 3 int value; descriptor: I flags: (0x0000) @@ -1654,6 +1654,22 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative com.android.hoststubgen.hosthelper.HostStubGenKeptInStub x: #x() com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl + + public static void nativeStillNotSupported_should_be_like_this(); + descriptor: ()V + flags: (0x0009) ACC_PUBLIC, ACC_STATIC + Code: + stack=3, locals=0, args_size=0 + 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 } SourceFile: "TinyFrameworkNative.java" RuntimeVisibleAnnotations: diff --git a/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/13-hoststubgen-test-tiny-framework-host-ext-impl-dump.txt b/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/13-hoststubgen-test-tiny-framework-host-ext-impl-dump.txt index 49be4db4eb9b..2357844c1e10 100644 --- a/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/13-hoststubgen-test-tiny-framework-host-ext-impl-dump.txt +++ b/tools/hoststubgen/hoststubgen/test-tiny-framework/golden-output/13-hoststubgen-test-tiny-framework-host-ext-impl-dump.txt @@ -2727,7 +2727,7 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative flags: (0x0021) ACC_PUBLIC, ACC_SUPER this_class: #x // com/android/hoststubgen/test/tinyframework/TinyFrameworkNative super_class: #x // java/lang/Object - interfaces: 0, fields: 1, methods: 9, attributes: 3 + interfaces: 0, fields: 1, methods: 11, attributes: 3 int value; descriptor: I flags: (0x0000) @@ -2774,10 +2774,15 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative descriptor: (I)I flags: (0x0009) ACC_PUBLIC, ACC_STATIC Code: - stack=1, locals=1, args_size=1 - x: iload_0 - x: invokestatic #x // Method com/android/hoststubgen/test/tinyframework/TinyFrameworkNative_host.nativeAddTwo:(I)I - x: ireturn + stack=4, locals=1, args_size=1 + x: ldc #x // class com/android/hoststubgen/test/tinyframework/TinyFrameworkNative + x: ldc #x // String nativeAddTwo + x: ldc #x // String (I)I + 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: iload_0 + x: invokestatic #x // Method com/android/hoststubgen/test/tinyframework/TinyFrameworkNative_host.nativeAddTwo:(I)I + x: ireturn RuntimeVisibleAnnotations: x: #x() com.android.hoststubgen.hosthelper.HostStubGenProcessedAsSubstitute @@ -2814,10 +2819,15 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative flags: (0x0009) ACC_PUBLIC, ACC_STATIC Code: stack=4, locals=4, args_size=2 - x: lload_0 - x: lload_2 - x: invokestatic #x // Method com/android/hoststubgen/test/tinyframework/TinyFrameworkNative_host.nativeLongPlus:(JJ)J - x: lreturn + x: ldc #x // class com/android/hoststubgen/test/tinyframework/TinyFrameworkNative + x: ldc #x // String nativeLongPlus + x: ldc #x // String (JJ)J + 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: lload_0 + x: lload_2 + x: invokestatic #x // Method com/android/hoststubgen/test/tinyframework/TinyFrameworkNative_host.nativeLongPlus:(JJ)J + x: lreturn RuntimeVisibleAnnotations: x: #x() com.android.hoststubgen.hosthelper.HostStubGenProcessedAsSubstitute @@ -2880,11 +2890,16 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative descriptor: (I)I flags: (0x0001) ACC_PUBLIC Code: - stack=2, locals=2, args_size=2 - x: aload_0 - x: iload_1 - x: invokestatic #x // Method com/android/hoststubgen/test/tinyframework/TinyFrameworkNative_host.nativeNonStaticAddToValue:(Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkNative;I)I - x: ireturn + stack=4, locals=2, args_size=2 + x: ldc #x // class com/android/hoststubgen/test/tinyframework/TinyFrameworkNative + x: ldc #x // String nativeNonStaticAddToValue + x: ldc #x // String (I)I + 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: iload_1 + x: invokestatic #x // Method com/android/hoststubgen/test/tinyframework/TinyFrameworkNative_host.nativeNonStaticAddToValue:(Lcom/android/hoststubgen/test/tinyframework/TinyFrameworkNative;I)I + x: ireturn RuntimeVisibleAnnotations: x: #x() com.android.hoststubgen.hosthelper.HostStubGenProcessedAsSubstitute @@ -2917,6 +2932,60 @@ public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative com.android.hoststubgen.hosthelper.HostStubGenKeptInStub x: #x() com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl + + public static void nativeStillNotSupported(); + descriptor: ()V + flags: (0x0009) ACC_PUBLIC, ACC_STATIC + Code: + stack=4, locals=0, args_size=0 + x: ldc #x // class com/android/hoststubgen/test/tinyframework/TinyFrameworkNative + x: ldc #x // String nativeStillNotSupported + 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: ldc #x // String com/android/hoststubgen/test/tinyframework/TinyFrameworkNative + x: ldc #x // String nativeStillNotSupported + x: ldc #x // String ()V + x: invokestatic #x // Method com/android/hoststubgen/hosthelper/HostTestUtils.getStackWalker:()Ljava/lang/StackWalker; + x: invokevirtual #x // Method java/lang/StackWalker.getCallerClass:()Ljava/lang/Class; + x: invokestatic #x // Method com/android/hoststubgen/hosthelper/HostTestUtils.onNonStubMethodCalled:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Class;)V + x: invokestatic #x // Method com/android/hoststubgen/hosthelper/HostTestUtils.onThrowMethodCalled:()V + x: new #x // class java/lang/RuntimeException + x: dup + x: ldc #x // String Unreachable + x: invokespecial #x // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V + x: athrow + RuntimeVisibleAnnotations: + x: #x() + com.android.hoststubgen.hosthelper.HostStubGenProcessedAsThrow + x: #x() + com.android.hoststubgen.hosthelper.HostStubGenProcessedAsSubstitute + x: #x() + com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl + RuntimeInvisibleAnnotations: + x: #x() + android.hosttest.annotation.HostSideTestThrow + + public static void nativeStillNotSupported_should_be_like_this(); + descriptor: ()V + flags: (0x0009) ACC_PUBLIC, ACC_STATIC + Code: + stack=4, locals=0, args_size=0 + x: ldc #x // class com/android/hoststubgen/test/tinyframework/TinyFrameworkNative + x: ldc #x // String nativeStillNotSupported_should_be_like_this + 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: new #x // class java/lang/RuntimeException + x: dup + x: invokespecial #x // Method java/lang/RuntimeException."<init>":()V + x: athrow + LineNumberTable: + RuntimeVisibleAnnotations: + x: #x() + com.android.hoststubgen.hosthelper.HostStubGenKeptInStub + x: #x() + com.android.hoststubgen.hosthelper.HostStubGenKeptInImpl } SourceFile: "TinyFrameworkNative.java" RuntimeVisibleAnnotations: diff --git a/tools/hoststubgen/hoststubgen/test-tiny-framework/tiny-framework/src/com/android/hoststubgen/test/tinyframework/TinyFrameworkNative.java b/tools/hoststubgen/hoststubgen/test-tiny-framework/tiny-framework/src/com/android/hoststubgen/test/tinyframework/TinyFrameworkNative.java index e7b5d9fc2ece..5a5e22db59e5 100644 --- a/tools/hoststubgen/hoststubgen/test-tiny-framework/tiny-framework/src/com/android/hoststubgen/test/tinyframework/TinyFrameworkNative.java +++ b/tools/hoststubgen/hoststubgen/test-tiny-framework/tiny-framework/src/com/android/hoststubgen/test/tinyframework/TinyFrameworkNative.java @@ -16,6 +16,7 @@ package com.android.hoststubgen.test.tinyframework; import android.hosttest.annotation.HostSideTestNativeSubstitutionClass; +import android.hosttest.annotation.HostSideTestThrow; import android.hosttest.annotation.HostSideTestWholeClassStub; @HostSideTestWholeClassStub @@ -44,4 +45,11 @@ public class TinyFrameworkNative { public int nativeNonStaticAddToValue_should_be_like_this(int arg) { return TinyFrameworkNative_host.nativeNonStaticAddToValue(this, arg); } + + @HostSideTestThrow + public static native void nativeStillNotSupported(); + + public static void nativeStillNotSupported_should_be_like_this() { + throw new RuntimeException(); + } } diff --git a/tools/hoststubgen/hoststubgen/test-tiny-framework/tiny-test/src/com/android/hoststubgen/test/tinyframework/TinyFrameworkClassTest.java b/tools/hoststubgen/hoststubgen/test-tiny-framework/tiny-test/src/com/android/hoststubgen/test/tinyframework/TinyFrameworkClassTest.java index d3501057163d..fc6b862705f8 100644 --- a/tools/hoststubgen/hoststubgen/test-tiny-framework/tiny-test/src/com/android/hoststubgen/test/tinyframework/TinyFrameworkClassTest.java +++ b/tools/hoststubgen/hoststubgen/test-tiny-framework/tiny-test/src/com/android/hoststubgen/test/tinyframework/TinyFrameworkClassTest.java @@ -17,6 +17,8 @@ package com.android.hoststubgen.test.tinyframework; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.fail; + import com.android.hoststubgen.test.tinyframework.TinyFrameworkNestedClasses.SubClass; import org.junit.Rule; @@ -158,6 +160,32 @@ public class TinyFrameworkClassTest { assertThat(instance.nativeNonStaticAddToValue(3)).isEqualTo(8); } + + @Test + public void testSubstituteNativeWithThrow() throws Exception { + // We can't use TinyFrameworkNative.nativeStillNotSupported() directly in this class, + // because @Throw implies @Keep (not @Stub), and we currently compile this test + // against the stub jar (so it won't contain @Throw methods). + // + // But the method exists at runtime, so we can use reflections to call it. + // + // In the real Ravenwood environment, we don't use HostStubGen's stub jar at all, + // so it's not a problem. + + final var clazz = TinyFrameworkNative.class; + final var method = clazz.getMethod("nativeStillNotSupported"); + + try { + method.invoke(null); + + fail("java.lang.reflect.InvocationTargetException expected"); + + } catch (java.lang.reflect.InvocationTargetException e) { + var inner = e.getCause(); + assertThat(inner.getMessage()).contains("not supported on the host side"); + } + } + @Test public void testExitLog() { thrown.expect(RuntimeException.class); diff --git a/tools/hoststubgen/scripts/run-all-tests.sh b/tools/hoststubgen/scripts/run-all-tests.sh index c7007db6028e..222c874ac34b 100755 --- a/tools/hoststubgen/scripts/run-all-tests.sh +++ b/tools/hoststubgen/scripts/run-all-tests.sh @@ -25,6 +25,7 @@ READY_TEST_MODULES=( HostStubGenTest-framework-all-test-host-test hoststubgen-test-tiny-test CtsUtilTestCasesRavenwood + CtsOsTestCasesRavenwood # This one uses native sustitution, so let's run it too. ) MUST_BUILD_MODULES=( @@ -55,4 +56,4 @@ run ./scripts/build-framework-hostside-jars-and-extract.sh # These tests should all pass. run atest $ATEST_ARGS ${READY_TEST_MODULES[*]} -echo ""${0##*/}" finished, with no failures. Ready to submit!"
\ No newline at end of file +echo ""${0##*/}" finished, with no failures. Ready to submit!" |