Loading core/java/android/os/ParcelFileDescriptor.java +19 −17 Original line number Diff line number Diff line Loading @@ -52,8 +52,6 @@ import android.util.CloseGuard; import android.util.Log; import android.util.Slog; import com.android.internal.ravenwood.RavenwoodEnvironment; import dalvik.system.VMRuntime; import libcore.io.IoUtils; Loading Loading @@ -390,6 +388,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * new file descriptor shared state such as file position with the * original file descriptor. */ @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor dup(FileDescriptor orig) throws IOException { try { final FileDescriptor fd = new FileDescriptor(); Loading @@ -407,6 +406,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * new file descriptor shared state such as file position with the * original file descriptor. */ @RavenwoodThrow(reason = "Requires JNI support") public ParcelFileDescriptor dup() throws IOException { if (mWrapped != null) { return mWrapped.dup(); Loading @@ -425,6 +425,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * @return Returns a new ParcelFileDescriptor holding a FileDescriptor * for a dup of the given fd. */ @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor fromFd(int fd) throws IOException { final FileDescriptor original = new FileDescriptor(); setFdInt(original, fd); Loading Loading @@ -484,7 +485,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * * @throws UncheckedIOException if {@link #dup(FileDescriptor)} throws IOException. */ @RavenwoodThrow(reason = "Socket.getFileDescriptor$()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor fromSocket(Socket socket) { FileDescriptor fd = socket.getFileDescriptor$(); try { Loading Loading @@ -518,7 +519,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * * @throws UncheckedIOException if {@link #dup(FileDescriptor)} throws IOException. */ @RavenwoodThrow(reason = "DatagramSocket.getFileDescriptor$()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor fromDatagramSocket(DatagramSocket datagramSocket) { FileDescriptor fd = datagramSocket.getFileDescriptor$(); try { Loading @@ -533,6 +534,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * ParcelFileDescriptor in the returned array is the read side; the second * is the write side. */ @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createPipe() throws IOException { try { final FileDescriptor[] fds = Os.pipe2(ifAtLeastQ(O_CLOEXEC)); Loading @@ -554,6 +556,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * calling {@link #checkError()}, usually after detecting an EOF. * This can also be used to detect remote crashes. */ @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createReliablePipe() throws IOException { try { final FileDescriptor[] comm = createCommSocketPair(); Loading @@ -570,7 +573,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * Create two ParcelFileDescriptors structured as a pair of sockets * connected to each other. The two sockets are indistinguishable. */ @RavenwoodThrow(reason = "Os.socketpair()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createSocketPair() throws IOException { return createSocketPair(SOCK_STREAM); } Loading @@ -578,7 +581,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { /** * @hide */ @RavenwoodThrow(reason = "Os.socketpair()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createSocketPair(int type) throws IOException { try { final FileDescriptor fd0 = new FileDescriptor(); Loading @@ -601,7 +604,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * calling {@link #checkError()}, usually after detecting an EOF. * This can also be used to detect remote crashes. */ @RavenwoodThrow(reason = "Os.socketpair()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createReliableSocketPair() throws IOException { return createReliableSocketPair(SOCK_STREAM); } Loading @@ -609,7 +612,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { /** * @hide */ @RavenwoodThrow(reason = "Os.socketpair()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createReliableSocketPair(int type) throws IOException { try { final FileDescriptor[] comm = createCommSocketPair(); Loading @@ -624,7 +627,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { } } @RavenwoodThrow(reason = "Os.socketpair()") @RavenwoodThrow(reason = "Requires JNI support") private static FileDescriptor[] createCommSocketPair() throws IOException { try { // Use SOCK_SEQPACKET so that we have a guarantee that the status Loading Loading @@ -653,7 +656,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { */ @UnsupportedAppUsage @Deprecated @RavenwoodThrow(blockedBy = MemoryFile.class) @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor fromData(byte[] data, String name) throws IOException { if (data == null) return null; MemoryFile file = new MemoryFile(name, data.length); Loading Loading @@ -709,7 +712,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * @hide */ @TestApi @RavenwoodThrow(reason = "Os.readlink() and Os.stat()") @RavenwoodThrow(reason = "Requires kernel support") public static File getFile(FileDescriptor fd) throws IOException { try { final String path = Os.readlink("/proc/self/fd/" + getFdInt(fd)); Loading Loading @@ -741,7 +744,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * Return the total size of the file representing this fd, as determined by * {@code stat()}. Returns -1 if the fd is not a file. */ @RavenwoodThrow(reason = "Os.readlink() and Os.stat()") @RavenwoodThrow(reason = "Requires JNI support") public long getStatSize() { if (mWrapped != null) { return mWrapped.getStatSize(); Loading @@ -766,6 +769,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * @hide */ @UnsupportedAppUsage @RavenwoodThrow(reason = "Requires JNI support") public long seekTo(long pos) throws IOException { if (mWrapped != null) { return mWrapped.seekTo(pos); Loading Loading @@ -1033,6 +1037,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * take care of calling {@link ParcelFileDescriptor#close * ParcelFileDescriptor.close()} for you when the stream is closed. */ @RavenwoodKeepWholeClass public static class AutoCloseInputStream extends FileInputStream { private final ParcelFileDescriptor mPfd; Loading Loading @@ -1321,15 +1326,12 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { } @RavenwoodReplace @RavenwoodThrow private static boolean isAtLeastQ() { return (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q); } private static boolean isAtLeastQ$ravenwood() { return RavenwoodEnvironment.workaround().isTargetSdkAtLeastQ(); } @RavenwoodThrow private static int ifAtLeastQ(int value) { return isAtLeastQ() ? value : 0; } Loading core/java/com/android/internal/ravenwood/RavenwoodEnvironment.java +0 −31 Original line number Diff line number Diff line Loading @@ -15,17 +15,12 @@ */ package com.android.internal.ravenwood; import android.ravenwood.annotation.RavenwoodNativeSubstitutionClass; /** * Class to interact with the Ravenwood environment. */ @android.ravenwood.annotation.RavenwoodKeepWholeClass @RavenwoodNativeSubstitutionClass( "com.android.platform.test.ravenwood.nativesubstitution.RavenwoodEnvironment_host") public class RavenwoodEnvironment { private static RavenwoodEnvironment sInstance = new RavenwoodEnvironment(); private static Workaround sWorkaround = new Workaround(); private RavenwoodEnvironment() { } Loading Loading @@ -57,30 +52,4 @@ public class RavenwoodEnvironment { public boolean isRunningOnRavenwood$ravenwood() { return true; } /** * See {@link Workaround}. It's only usablke on Ravenwood. */ public static Workaround workaround() { if (getInstance().isRunningOnRavenwood()) { return sWorkaround; } throw new IllegalStateException("Workaround can only be used on Ravenwood"); } /** * A set of APIs used to work around missing features on Ravenwood. Ideally, this class should * be empty, and all its APIs should be able to be implemented properly. */ public static class Workaround { Workaround() { } /** * @return whether the app's target SDK level is at least Q. */ public boolean isTargetSdkAtLeastQ() { return true; } } } ravenwood/Android.bp +1 −21 Original line number Diff line number Diff line Loading @@ -56,24 +56,11 @@ java_library { visibility: ["//visibility:public"], } java_library { name: "ravenwood-runtime-common", host_supported: true, sdk_version: "core_current", srcs: [ "runtime-common-src/**/*.java", ], visibility: ["//visibility:private"], } java_library_host { name: "ravenwood-helper-libcore-runtime.host", srcs: [ "runtime-helper-src/libcore-fake/**/*.java", ], static_libs: [ "ravenwood-runtime-common", ], visibility: ["//visibility:private"], } Loading @@ -90,9 +77,6 @@ java_library { srcs: [ "runtime-helper-src/framework/**/*.java", ], static_libs: [ "ravenwood-runtime-common", ], libs: [ "framework-minus-apex.ravenwood", "ravenwood-junit", Loading Loading @@ -121,7 +105,6 @@ java_library { ], static_libs: [ "androidx.test.monitor-for-device", "ravenwood-runtime-common", ], libs: [ "android.test.mock", Loading Loading @@ -162,9 +145,6 @@ java_library { "junit-flag-src/**/*.java", ], sdk_version: "test_current", static_libs: [ "ravenwood-runtime-common", ], libs: [ "junit", "flag-junit", Loading Loading @@ -219,7 +199,7 @@ cc_library_shared { ], srcs: [ "runtime-jni/*.cpp", "runtime-helper-src/jni/*.cpp", ], shared_libs: [ Loading ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java +4 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,10 @@ public class RavenwoodRuleImpl { sPendingUncaughtException.compareAndSet(null, throwable); }; public static boolean isOnRavenwood() { return true; } public static void init(RavenwoodRule rule) { if (ENABLE_UNCAUGHT_EXCEPTION_DETECTION) { maybeThrowPendingUncaughtException(false); Loading ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java +1 −3 Original line number Diff line number Diff line Loading @@ -29,8 +29,6 @@ import android.platform.test.annotations.DisabledOnRavenwood; import android.platform.test.annotations.EnabledOnRavenwood; import android.platform.test.annotations.IgnoreUnderRavenwood; import com.android.ravenwood.common.RavenwoodCommonUtils; import org.junit.Assume; import org.junit.rules.TestRule; import org.junit.runner.Description; Loading @@ -56,7 +54,7 @@ import java.util.regex.Pattern; * before a test class is fully initialized. */ public class RavenwoodRule implements TestRule { static final boolean IS_ON_RAVENWOOD = RavenwoodCommonUtils.isOnRavenwood(); static final boolean IS_ON_RAVENWOOD = RavenwoodRuleImpl.isOnRavenwood(); /** * When probing is enabled, all tests will be unconditionally run on Ravenwood to detect Loading Loading
core/java/android/os/ParcelFileDescriptor.java +19 −17 Original line number Diff line number Diff line Loading @@ -52,8 +52,6 @@ import android.util.CloseGuard; import android.util.Log; import android.util.Slog; import com.android.internal.ravenwood.RavenwoodEnvironment; import dalvik.system.VMRuntime; import libcore.io.IoUtils; Loading Loading @@ -390,6 +388,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * new file descriptor shared state such as file position with the * original file descriptor. */ @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor dup(FileDescriptor orig) throws IOException { try { final FileDescriptor fd = new FileDescriptor(); Loading @@ -407,6 +406,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * new file descriptor shared state such as file position with the * original file descriptor. */ @RavenwoodThrow(reason = "Requires JNI support") public ParcelFileDescriptor dup() throws IOException { if (mWrapped != null) { return mWrapped.dup(); Loading @@ -425,6 +425,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * @return Returns a new ParcelFileDescriptor holding a FileDescriptor * for a dup of the given fd. */ @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor fromFd(int fd) throws IOException { final FileDescriptor original = new FileDescriptor(); setFdInt(original, fd); Loading Loading @@ -484,7 +485,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * * @throws UncheckedIOException if {@link #dup(FileDescriptor)} throws IOException. */ @RavenwoodThrow(reason = "Socket.getFileDescriptor$()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor fromSocket(Socket socket) { FileDescriptor fd = socket.getFileDescriptor$(); try { Loading Loading @@ -518,7 +519,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * * @throws UncheckedIOException if {@link #dup(FileDescriptor)} throws IOException. */ @RavenwoodThrow(reason = "DatagramSocket.getFileDescriptor$()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor fromDatagramSocket(DatagramSocket datagramSocket) { FileDescriptor fd = datagramSocket.getFileDescriptor$(); try { Loading @@ -533,6 +534,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * ParcelFileDescriptor in the returned array is the read side; the second * is the write side. */ @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createPipe() throws IOException { try { final FileDescriptor[] fds = Os.pipe2(ifAtLeastQ(O_CLOEXEC)); Loading @@ -554,6 +556,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * calling {@link #checkError()}, usually after detecting an EOF. * This can also be used to detect remote crashes. */ @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createReliablePipe() throws IOException { try { final FileDescriptor[] comm = createCommSocketPair(); Loading @@ -570,7 +573,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * Create two ParcelFileDescriptors structured as a pair of sockets * connected to each other. The two sockets are indistinguishable. */ @RavenwoodThrow(reason = "Os.socketpair()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createSocketPair() throws IOException { return createSocketPair(SOCK_STREAM); } Loading @@ -578,7 +581,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { /** * @hide */ @RavenwoodThrow(reason = "Os.socketpair()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createSocketPair(int type) throws IOException { try { final FileDescriptor fd0 = new FileDescriptor(); Loading @@ -601,7 +604,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * calling {@link #checkError()}, usually after detecting an EOF. * This can also be used to detect remote crashes. */ @RavenwoodThrow(reason = "Os.socketpair()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createReliableSocketPair() throws IOException { return createReliableSocketPair(SOCK_STREAM); } Loading @@ -609,7 +612,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { /** * @hide */ @RavenwoodThrow(reason = "Os.socketpair()") @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor[] createReliableSocketPair(int type) throws IOException { try { final FileDescriptor[] comm = createCommSocketPair(); Loading @@ -624,7 +627,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { } } @RavenwoodThrow(reason = "Os.socketpair()") @RavenwoodThrow(reason = "Requires JNI support") private static FileDescriptor[] createCommSocketPair() throws IOException { try { // Use SOCK_SEQPACKET so that we have a guarantee that the status Loading Loading @@ -653,7 +656,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { */ @UnsupportedAppUsage @Deprecated @RavenwoodThrow(blockedBy = MemoryFile.class) @RavenwoodThrow(reason = "Requires JNI support") public static ParcelFileDescriptor fromData(byte[] data, String name) throws IOException { if (data == null) return null; MemoryFile file = new MemoryFile(name, data.length); Loading Loading @@ -709,7 +712,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * @hide */ @TestApi @RavenwoodThrow(reason = "Os.readlink() and Os.stat()") @RavenwoodThrow(reason = "Requires kernel support") public static File getFile(FileDescriptor fd) throws IOException { try { final String path = Os.readlink("/proc/self/fd/" + getFdInt(fd)); Loading Loading @@ -741,7 +744,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * Return the total size of the file representing this fd, as determined by * {@code stat()}. Returns -1 if the fd is not a file. */ @RavenwoodThrow(reason = "Os.readlink() and Os.stat()") @RavenwoodThrow(reason = "Requires JNI support") public long getStatSize() { if (mWrapped != null) { return mWrapped.getStatSize(); Loading @@ -766,6 +769,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * @hide */ @UnsupportedAppUsage @RavenwoodThrow(reason = "Requires JNI support") public long seekTo(long pos) throws IOException { if (mWrapped != null) { return mWrapped.seekTo(pos); Loading Loading @@ -1033,6 +1037,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { * take care of calling {@link ParcelFileDescriptor#close * ParcelFileDescriptor.close()} for you when the stream is closed. */ @RavenwoodKeepWholeClass public static class AutoCloseInputStream extends FileInputStream { private final ParcelFileDescriptor mPfd; Loading Loading @@ -1321,15 +1326,12 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { } @RavenwoodReplace @RavenwoodThrow private static boolean isAtLeastQ() { return (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q); } private static boolean isAtLeastQ$ravenwood() { return RavenwoodEnvironment.workaround().isTargetSdkAtLeastQ(); } @RavenwoodThrow private static int ifAtLeastQ(int value) { return isAtLeastQ() ? value : 0; } Loading
core/java/com/android/internal/ravenwood/RavenwoodEnvironment.java +0 −31 Original line number Diff line number Diff line Loading @@ -15,17 +15,12 @@ */ package com.android.internal.ravenwood; import android.ravenwood.annotation.RavenwoodNativeSubstitutionClass; /** * Class to interact with the Ravenwood environment. */ @android.ravenwood.annotation.RavenwoodKeepWholeClass @RavenwoodNativeSubstitutionClass( "com.android.platform.test.ravenwood.nativesubstitution.RavenwoodEnvironment_host") public class RavenwoodEnvironment { private static RavenwoodEnvironment sInstance = new RavenwoodEnvironment(); private static Workaround sWorkaround = new Workaround(); private RavenwoodEnvironment() { } Loading Loading @@ -57,30 +52,4 @@ public class RavenwoodEnvironment { public boolean isRunningOnRavenwood$ravenwood() { return true; } /** * See {@link Workaround}. It's only usablke on Ravenwood. */ public static Workaround workaround() { if (getInstance().isRunningOnRavenwood()) { return sWorkaround; } throw new IllegalStateException("Workaround can only be used on Ravenwood"); } /** * A set of APIs used to work around missing features on Ravenwood. Ideally, this class should * be empty, and all its APIs should be able to be implemented properly. */ public static class Workaround { Workaround() { } /** * @return whether the app's target SDK level is at least Q. */ public boolean isTargetSdkAtLeastQ() { return true; } } }
ravenwood/Android.bp +1 −21 Original line number Diff line number Diff line Loading @@ -56,24 +56,11 @@ java_library { visibility: ["//visibility:public"], } java_library { name: "ravenwood-runtime-common", host_supported: true, sdk_version: "core_current", srcs: [ "runtime-common-src/**/*.java", ], visibility: ["//visibility:private"], } java_library_host { name: "ravenwood-helper-libcore-runtime.host", srcs: [ "runtime-helper-src/libcore-fake/**/*.java", ], static_libs: [ "ravenwood-runtime-common", ], visibility: ["//visibility:private"], } Loading @@ -90,9 +77,6 @@ java_library { srcs: [ "runtime-helper-src/framework/**/*.java", ], static_libs: [ "ravenwood-runtime-common", ], libs: [ "framework-minus-apex.ravenwood", "ravenwood-junit", Loading Loading @@ -121,7 +105,6 @@ java_library { ], static_libs: [ "androidx.test.monitor-for-device", "ravenwood-runtime-common", ], libs: [ "android.test.mock", Loading Loading @@ -162,9 +145,6 @@ java_library { "junit-flag-src/**/*.java", ], sdk_version: "test_current", static_libs: [ "ravenwood-runtime-common", ], libs: [ "junit", "flag-junit", Loading Loading @@ -219,7 +199,7 @@ cc_library_shared { ], srcs: [ "runtime-jni/*.cpp", "runtime-helper-src/jni/*.cpp", ], shared_libs: [ Loading
ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java +4 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,10 @@ public class RavenwoodRuleImpl { sPendingUncaughtException.compareAndSet(null, throwable); }; public static boolean isOnRavenwood() { return true; } public static void init(RavenwoodRule rule) { if (ENABLE_UNCAUGHT_EXCEPTION_DETECTION) { maybeThrowPendingUncaughtException(false); Loading
ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java +1 −3 Original line number Diff line number Diff line Loading @@ -29,8 +29,6 @@ import android.platform.test.annotations.DisabledOnRavenwood; import android.platform.test.annotations.EnabledOnRavenwood; import android.platform.test.annotations.IgnoreUnderRavenwood; import com.android.ravenwood.common.RavenwoodCommonUtils; import org.junit.Assume; import org.junit.rules.TestRule; import org.junit.runner.Description; Loading @@ -56,7 +54,7 @@ import java.util.regex.Pattern; * before a test class is fully initialized. */ public class RavenwoodRule implements TestRule { static final boolean IS_ON_RAVENWOOD = RavenwoodCommonUtils.isOnRavenwood(); static final boolean IS_ON_RAVENWOOD = RavenwoodRuleImpl.isOnRavenwood(); /** * When probing is enabled, all tests will be unconditionally run on Ravenwood to detect Loading