summaryrefslogtreecommitdiff
path: root/ravenwood/runtime-helper-src
diff options
context:
space:
mode:
author John Wu <topjohnwu@google.com> 2024-07-31 22:46:33 +0000
committer Cherrypicker Worker <android-build-cherrypicker-worker@google.com> 2024-08-01 18:17:21 +0000
commit4ac7fb181a44e5bf484339db21109f76148ebe84 (patch)
tree353f29bfe23eaa22f83f371f1d92e37da35948a9 /ravenwood/runtime-helper-src
parentf01b502933344c8bdf84c25c22fef259323332f9 (diff)
[Ravenwood] Enable PFD.getStatSize and cleanup implementation
Bug: 353521759 Flag: EXEMPT host side test change only Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:be940db4aacbb14f0abc35197b224bf197ddac4f) Merged-In: I011f14bdefb041d6f75a5d4c1d729dc368528d09 Change-Id: I011f14bdefb041d6f75a5d4c1d729dc368528d09
Diffstat (limited to 'ravenwood/runtime-helper-src')
-rw-r--r--ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java93
-rw-r--r--ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java13
-rw-r--r--ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java15
3 files changed, 22 insertions, 99 deletions
diff --git a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java
index 1a15d7a8c19e..5a3589dae43a 100644
--- a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java
+++ b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/ParcelFileDescriptor_host.java
@@ -16,105 +16,16 @@
package com.android.platform.test.ravenwood.nativesubstitution;
-import static android.os.ParcelFileDescriptor.MODE_APPEND;
-import static android.os.ParcelFileDescriptor.MODE_CREATE;
-import static android.os.ParcelFileDescriptor.MODE_READ_ONLY;
-import static android.os.ParcelFileDescriptor.MODE_READ_WRITE;
-import static android.os.ParcelFileDescriptor.MODE_TRUNCATE;
-import static android.os.ParcelFileDescriptor.MODE_WORLD_READABLE;
-import static android.os.ParcelFileDescriptor.MODE_WORLD_WRITEABLE;
-import static android.os.ParcelFileDescriptor.MODE_WRITE_ONLY;
-
-import android.system.ErrnoException;
-import android.system.Os;
-import android.util.Log;
-
-import com.android.internal.annotations.GuardedBy;
import com.android.ravenwood.common.JvmWorkaround;
-import java.io.File;
import java.io.FileDescriptor;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.util.HashMap;
-import java.util.Map;
public class ParcelFileDescriptor_host {
- private static final String TAG = "ParcelFileDescriptor_host";
-
- /**
- * Since we don't have a great way to keep an unmanaged {@code FileDescriptor} reference
- * alive, we keep a strong reference to the {@code RandomAccessFile} we used to open it. This
- * gives us a way to look up the original parent object when closing later.
- */
- @GuardedBy("sActive")
- private static final Map<FileDescriptor, RandomAccessFile> sActive = new HashMap<>();
-
- public static void native_setFdInt$ravenwood(FileDescriptor fd, int fdInt) {
+ public static void setFdInt(FileDescriptor fd, int fdInt) {
JvmWorkaround.getInstance().setFdInt(fd, fdInt);
}
- public static int native_getFdInt$ravenwood(FileDescriptor fd) {
+ public static int getFdInt(FileDescriptor fd) {
return JvmWorkaround.getInstance().getFdInt(fd);
}
-
- public static FileDescriptor native_open$ravenwood(File file, int pfdMode) throws IOException {
- if ((pfdMode & MODE_CREATE) != 0 && !file.exists()) {
- throw new FileNotFoundException();
- }
-
- final String modeString;
- if ((pfdMode & MODE_READ_WRITE) == MODE_READ_WRITE) {
- modeString = "rw";
- } else if ((pfdMode & MODE_WRITE_ONLY) == MODE_WRITE_ONLY) {
- modeString = "rw";
- } else if ((pfdMode & MODE_READ_ONLY) == MODE_READ_ONLY) {
- modeString = "r";
- } else {
- throw new IllegalArgumentException();
- }
-
- final RandomAccessFile raf = new RandomAccessFile(file, modeString);
-
- // Now that we have a real file on disk, match requested flags
- if ((pfdMode & MODE_TRUNCATE) != 0) {
- raf.setLength(0);
- }
- if ((pfdMode & MODE_APPEND) != 0) {
- raf.seek(raf.length());
- }
- if ((pfdMode & MODE_WORLD_READABLE) != 0) {
- file.setReadable(true, false);
- }
- if ((pfdMode & MODE_WORLD_WRITEABLE) != 0) {
- file.setWritable(true, false);
- }
-
- final FileDescriptor fd = raf.getFD();
- synchronized (sActive) {
- sActive.put(fd, raf);
- }
- return fd;
- }
-
- public static void native_close$ravenwood(FileDescriptor fd) {
- final RandomAccessFile raf;
- synchronized (sActive) {
- raf = sActive.remove(fd);
- }
- int fdInt = JvmWorkaround.getInstance().getFdInt(fd);
- try {
- if (raf != null) {
- raf.close();
- } else {
- // This FD wasn't created by native_open$ravenwood().
- // The FD was passed to the PFD ctor. Just close it.
- Os.close(fd);
- }
- } catch (IOException | ErrnoException e) {
- Log.w(TAG, "Exception thrown while closing fd " + fdInt, e);
- }
- }
}
-; \ No newline at end of file
diff --git a/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java b/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java
index 825ab72e773a..ecaa8161ee46 100644
--- a/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java
+++ b/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java
@@ -15,9 +15,11 @@
*/
package android.system;
+import com.android.ravenwood.common.JvmWorkaround;
import com.android.ravenwood.common.RavenwoodRuntimeNative;
import java.io.FileDescriptor;
+import java.io.IOException;
/**
* OS class replacement used on Ravenwood. For now, we just implement APIs as we need them...
@@ -56,6 +58,15 @@ public final class Os {
/** Ravenwood version of the OS API. */
public static void close(FileDescriptor fd) throws ErrnoException {
- RavenwoodRuntimeNative.close(fd);
+ try {
+ JvmWorkaround.getInstance().closeFd(fd);
+ } catch (IOException e) {
+ // The only valid error on Linux that can happen is EIO
+ throw new ErrnoException("close", OsConstants.EIO);
+ }
+ }
+
+ public static FileDescriptor open(String path, int flags, int mode) throws ErrnoException {
+ return RavenwoodRuntimeNative.open(path, flags, mode);
}
}
diff --git a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java
index 2bc8e7123aad..beba83391652 100644
--- a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java
+++ b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java
@@ -48,7 +48,7 @@ public class RavenwoodRuntimeNative {
public static native StructStat stat(String path) throws ErrnoException;
- private static native void nClose(int fd) throws ErrnoException;
+ private static native int nOpen(String path, int flags, int mode) throws ErrnoException;
public static long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException {
return nLseek(JvmWorkaround.getInstance().getFdInt(fd), offset, whence);
@@ -69,7 +69,7 @@ public class RavenwoodRuntimeNative {
public static FileDescriptor dup(FileDescriptor fd) throws ErrnoException {
var fdInt = nDup(JvmWorkaround.getInstance().getFdInt(fd));
- var retFd = new java.io.FileDescriptor();
+ var retFd = new FileDescriptor();
JvmWorkaround.getInstance().setFdInt(retFd, fdInt);
return retFd;
}
@@ -86,10 +86,11 @@ public class RavenwoodRuntimeNative {
return nFstat(fdInt);
}
- /** See close(2) */
- public static void close(FileDescriptor fd) throws ErrnoException {
- var fdInt = JvmWorkaround.getInstance().getFdInt(fd);
-
- nClose(fdInt);
+ public static FileDescriptor open(String path, int flags, int mode) throws ErrnoException {
+ int fd = nOpen(path, flags, mode);
+ if (fd < 0) return null;
+ var retFd = new FileDescriptor();
+ JvmWorkaround.getInstance().setFdInt(retFd, fd);
+ return retFd;
}
}