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

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

Merge "Revert "[Ravenwood] Internal clean up, more PFD APIs, OsConstant..."" into main

parents 8f30bc9e f3c1075a
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -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;
@@ -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();
@@ -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();
@@ -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);
@@ -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 {
@@ -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 {
@@ -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));
@@ -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();
@@ -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);
    }
@@ -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();
@@ -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);
    }
@@ -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();
@@ -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
@@ -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);
@@ -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));
@@ -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();
@@ -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);
@@ -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;

@@ -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;
    }
+0 −31
Original line number Diff line number Diff line
@@ -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() {
    }
@@ -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;
        }
    }
}
+1 −21
Original line number Diff line number Diff line
@@ -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"],
}

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

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

    shared_libs: [
+4 −0
Original line number Diff line number Diff line
@@ -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);
+1 −3
Original line number Diff line number Diff line
@@ -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;
@@ -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