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

Commit 0c7e7c88 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add SharedMemory.fromFileDescriptor" am: d0792368 am: b2cb2c79 am:...

Merge "Add SharedMemory.fromFileDescriptor" am: d0792368 am: b2cb2c79 am: 3950828a am: f8029596

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1775625

Change-Id: I8717effee98ca093eac698bf146a426910d69ce0
parents b5f57d99 f8029596
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31833,6 +31833,7 @@ package android.os {
    method public void close();
    method @NonNull public static android.os.SharedMemory create(@Nullable String, int) throws android.system.ErrnoException;
    method public int describeContents();
    method @NonNull public static android.os.SharedMemory fromFileDescriptor(@NonNull android.os.ParcelFileDescriptor);
    method public int getSize();
    method @NonNull public java.nio.ByteBuffer map(int, int, int) throws android.system.ErrnoException;
    method @NonNull public java.nio.ByteBuffer mapReadOnly() throws android.system.ErrnoException;
+20 −0
Original line number Diff line number Diff line
@@ -93,6 +93,26 @@ public final class SharedMemory implements Parcelable, Closeable {
        }
    }

    /**
     * Creates an instance from existing shared memory passed as {@link ParcelFileDescriptor}.
     *
     * <p> The {@code fd} should be a shared memory created from
       {@code SharedMemory or ASharedMemory}. This can be useful when shared memory is passed as
       file descriptor through JNI or binder service implemented in cpp.
     * <p> Note that newly created {@code SharedMemory} takes ownership of passed {@code fd} and
     * the original {@code fd} becomes detached (Check {@link ParcelFileDescriptor#detachFd()}).
     * If the caller wants to use the file descriptor after the call, the caller should duplicate
     * the file descriptor (Check {@link ParcelFileDescriptor#dup()}) and pass the duped version
     * instead.
     *
     * @param fd File descriptor of shared memory passed as {@link ParcelFileDescriptor}.
     */
    public static @NonNull SharedMemory fromFileDescriptor(@NonNull ParcelFileDescriptor fd) {
        FileDescriptor f = new FileDescriptor();
        f.setInt$(fd.detachFd());
        return new SharedMemory(f);
    }

    private static final int PROT_MASK = OsConstants.PROT_READ | OsConstants.PROT_WRITE
            | OsConstants.PROT_EXEC | OsConstants.PROT_NONE;