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

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

Merge "[Ravenwood] Internal clean up, more PFD APIs, OsConstants, etc" into main

parents 50275f14 5b1f7008
Loading
Loading
Loading
Loading
+17 −19
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ 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;
@@ -388,7 +390,6 @@ 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();
@@ -406,7 +407,6 @@ 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();
@@ -425,7 +425,6 @@ 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);
@@ -485,7 +484,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
     *
     * @throws UncheckedIOException if {@link #dup(FileDescriptor)} throws IOException.
     */
    @RavenwoodThrow(reason = "Requires JNI support")
    @RavenwoodThrow(reason = "Socket.getFileDescriptor$()")
    public static ParcelFileDescriptor fromSocket(Socket socket) {
        FileDescriptor fd = socket.getFileDescriptor$();
        try {
@@ -519,7 +518,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
     *
     * @throws UncheckedIOException if {@link #dup(FileDescriptor)} throws IOException.
     */
    @RavenwoodThrow(reason = "Requires JNI support")
    @RavenwoodThrow(reason = "DatagramSocket.getFileDescriptor$()")
    public static ParcelFileDescriptor fromDatagramSocket(DatagramSocket datagramSocket) {
        FileDescriptor fd = datagramSocket.getFileDescriptor$();
        try {
@@ -534,7 +533,6 @@ 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));
@@ -556,7 +554,6 @@ 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();
@@ -573,7 +570,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 = "Requires JNI support")
    @RavenwoodThrow(reason = "Os.socketpair()")
    public static ParcelFileDescriptor[] createSocketPair() throws IOException {
        return createSocketPair(SOCK_STREAM);
    }
@@ -581,7 +578,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
    /**
     * @hide
     */
    @RavenwoodThrow(reason = "Requires JNI support")
    @RavenwoodThrow(reason = "Os.socketpair()")
    public static ParcelFileDescriptor[] createSocketPair(int type) throws IOException {
        try {
            final FileDescriptor fd0 = new FileDescriptor();
@@ -604,7 +601,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")
    @RavenwoodThrow(reason = "Os.socketpair()")
    public static ParcelFileDescriptor[] createReliableSocketPair() throws IOException {
        return createReliableSocketPair(SOCK_STREAM);
    }
@@ -612,7 +609,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
    /**
     * @hide
     */
    @RavenwoodThrow(reason = "Requires JNI support")
    @RavenwoodThrow(reason = "Os.socketpair()")
    public static ParcelFileDescriptor[] createReliableSocketPair(int type) throws IOException {
        try {
            final FileDescriptor[] comm = createCommSocketPair();
@@ -627,7 +624,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
        }
    }

    @RavenwoodThrow(reason = "Requires JNI support")
    @RavenwoodThrow(reason = "Os.socketpair()")
    private static FileDescriptor[] createCommSocketPair() throws IOException {
        try {
            // Use SOCK_SEQPACKET so that we have a guarantee that the status
@@ -656,7 +653,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
     */
    @UnsupportedAppUsage
    @Deprecated
    @RavenwoodThrow(reason = "Requires JNI support")
    @RavenwoodThrow(blockedBy = MemoryFile.class)
    public static ParcelFileDescriptor fromData(byte[] data, String name) throws IOException {
        if (data == null) return null;
        MemoryFile file = new MemoryFile(name, data.length);
@@ -712,7 +709,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
     * @hide
     */
    @TestApi
    @RavenwoodThrow(reason = "Requires kernel support")
    @RavenwoodThrow(reason = "Os.readlink() and Os.stat()")
    public static File getFile(FileDescriptor fd) throws IOException {
        try {
            final String path = Os.readlink("/proc/self/fd/" + getFdInt(fd));
@@ -744,7 +741,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 = "Requires JNI support")
    @RavenwoodThrow(reason = "Os.readlink() and Os.stat()")
    public long getStatSize() {
        if (mWrapped != null) {
            return mWrapped.getStatSize();
@@ -769,7 +766,6 @@ 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);
@@ -1037,7 +1033,6 @@ 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;

@@ -1326,12 +1321,15 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {

    }

    @RavenwoodThrow
    @RavenwoodReplace
    private static boolean isAtLeastQ() {
        return (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q);
    }

    @RavenwoodThrow
    private static boolean isAtLeastQ$ravenwood() {
        return RavenwoodEnvironment.workaround().isTargetSdkAtLeastQ();
    }

    private static int ifAtLeastQ(int value) {
        return isAtLeastQ() ? value : 0;
    }
+31 −0
Original line number Diff line number Diff line
@@ -15,12 +15,17 @@
 */
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() {
    }
@@ -52,4 +57,30 @@ 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;
        }
    }
}
+21 −1
Original line number Diff line number Diff line
@@ -56,11 +56,24 @@ 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"],
}

@@ -77,6 +90,9 @@ java_library {
    srcs: [
        "runtime-helper-src/framework/**/*.java",
    ],
    static_libs: [
        "ravenwood-runtime-common",
    ],
    libs: [
        "framework-minus-apex.ravenwood",
        "ravenwood-junit",
@@ -105,6 +121,7 @@ java_library {
    ],
    static_libs: [
        "androidx.test.monitor-for-device",
        "ravenwood-runtime-common",
    ],
    libs: [
        "android.test.mock",
@@ -145,6 +162,9 @@ java_library {
        "junit-flag-src/**/*.java",
    ],
    sdk_version: "test_current",
    static_libs: [
        "ravenwood-runtime-common",
    ],
    libs: [
        "junit",
        "flag-junit",
@@ -199,7 +219,7 @@ cc_library_shared {
    ],

    srcs: [
        "runtime-helper-src/jni/*.cpp",
        "runtime-jni/*.cpp",
    ],

    shared_libs: [
+0 −4
Original line number Diff line number Diff line
@@ -86,10 +86,6 @@ 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);
+3 −1
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ 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;
@@ -54,7 +56,7 @@ import java.util.regex.Pattern;
 * before a test class is fully initialized.
 */
public class RavenwoodRule implements TestRule {
    static final boolean IS_ON_RAVENWOOD = RavenwoodRuleImpl.isOnRavenwood();
    static final boolean IS_ON_RAVENWOOD = RavenwoodCommonUtils.isOnRavenwood();

    /**
     * When probing is enabled, all tests will be unconditionally run on Ravenwood to detect
Loading