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

Commit e4f60cce authored by John Reck's avatar John Reck
Browse files

SharedMemory API changes

Hides getFd & getFileDescriptor due to lifecycle concenrs.
Adds ASharedMemory_dupFromJava to allow sharing a shared
memory region between Java & Native as safe as possible.
Mis-use results in an FD leak instead of double-close.

Bug: 64394076
Test: SharedMemory CTS tests
Change-Id: I01a5eb978fc4e99559a79baac75754c32f13bdc4
parent cbf16572
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -31066,7 +31066,6 @@ package android.os {
    ctor public MemoryFile(java.lang.String, int) throws java.io.IOException;
    method public deprecated synchronized boolean allowPurging(boolean) throws java.io.IOException;
    method public void close();
    method public java.io.FileDescriptor getFileDescriptor() throws java.io.IOException;
    method public java.io.InputStream getInputStream();
    method public java.io.OutputStream getOutputStream();
    method public deprecated boolean isPurgingAllowed();
@@ -31498,8 +31497,6 @@ package android.os {
    method public void close();
    method public static android.os.SharedMemory create(java.lang.String, int) throws android.system.ErrnoException;
    method public int describeContents();
    method public int getFd();
    method public java.io.FileDescriptor getFileDescriptor();
    method public int getSize();
    method public java.nio.ByteBuffer map(int, int, int) throws android.system.ErrnoException;
    method public java.nio.ByteBuffer mapReadOnly() throws android.system.ErrnoException;
+0 −3
Original line number Diff line number Diff line
@@ -33911,7 +33911,6 @@ package android.os {
    ctor public MemoryFile(java.lang.String, int) throws java.io.IOException;
    method public deprecated synchronized boolean allowPurging(boolean) throws java.io.IOException;
    method public void close();
    method public java.io.FileDescriptor getFileDescriptor() throws java.io.IOException;
    method public java.io.InputStream getInputStream();
    method public java.io.OutputStream getOutputStream();
    method public deprecated boolean isPurgingAllowed();
@@ -34372,8 +34371,6 @@ package android.os {
    method public void close();
    method public static android.os.SharedMemory create(java.lang.String, int) throws android.system.ErrnoException;
    method public int describeContents();
    method public int getFd();
    method public java.io.FileDescriptor getFileDescriptor();
    method public int getSize();
    method public java.nio.ByteBuffer map(int, int, int) throws android.system.ErrnoException;
    method public java.nio.ByteBuffer mapReadOnly() throws android.system.ErrnoException;
+0 −3
Original line number Diff line number Diff line
@@ -31223,7 +31223,6 @@ package android.os {
    ctor public MemoryFile(java.lang.String, int) throws java.io.IOException;
    method public deprecated synchronized boolean allowPurging(boolean) throws java.io.IOException;
    method public void close();
    method public java.io.FileDescriptor getFileDescriptor() throws java.io.IOException;
    method public java.io.InputStream getInputStream();
    method public java.io.OutputStream getOutputStream();
    method public deprecated boolean isPurgingAllowed();
@@ -31656,8 +31655,6 @@ package android.os {
    method public void close();
    method public static android.os.SharedMemory create(java.lang.String, int) throws android.system.ErrnoException;
    method public int describeContents();
    method public int getFd();
    method public java.io.FileDescriptor getFileDescriptor();
    method public int getSize();
    method public java.nio.ByteBuffer map(int, int, int) throws android.system.ErrnoException;
    method public java.nio.ByteBuffer mapReadOnly() throws android.system.ErrnoException;
+2 −0
Original line number Diff line number Diff line
@@ -219,6 +219,8 @@ public class MemoryFile {
     * The returned file descriptor is not duplicated.
     *
     * @throws IOException If the memory file has been closed.
     *
     * @hide
     */
    public FileDescriptor getFileDescriptor() throws IOException {
        return mSharedMemory.getFileDescriptor();
+6 −1
Original line number Diff line number Diff line
@@ -60,7 +60,8 @@ public final class SharedMemory implements Parcelable, Closeable {
        }

        mMemoryRegistration = new MemoryRegistration(mSize);
        mCleaner = Cleaner.create(this, new Closer(mFileDescriptor, mMemoryRegistration));
        mCleaner = Cleaner.create(mFileDescriptor,
                new Closer(mFileDescriptor, mMemoryRegistration));
    }

    /**
@@ -138,6 +139,8 @@ public final class SharedMemory implements Parcelable, Closeable {
     * This FileDescriptor is interoperable with the ASharedMemory NDK APIs.
     *
     * @return Returns the FileDescriptor associated with this object.
     *
     * @hide Exists only for MemoryFile interop
     */
    public @NonNull FileDescriptor getFileDescriptor() {
        return mFileDescriptor;
@@ -150,6 +153,8 @@ public final class SharedMemory implements Parcelable, Closeable {
     * This fd is interoperable with the ASharedMemory NDK APIs.
     *
     * @return Returns the native fd associated with this object, or -1 if it is already closed.
     *
     * @hide Exposed for native ASharedMemory_dupFromJava()
     */
    public int getFd() {
        return mFileDescriptor.getInt$();
Loading