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

Commit cebd3111 authored by Keun young Park's avatar Keun young Park Committed by Keun-young Park
Browse files

Add SharedMemory.fromFileDescriptor

- Rename existing SharedMemory.create and make it public
- Passed file is now detached after creating shared memory and is
  not usable any more.

Bug: 188780895
CTS-Coverage-Bug: 197226773
Test: atest com.android.car.internal.test.LargeParcelableJavaStableAIDLTest
      (runs only in auto. will add matching CTS tests for non-auto devices)

Change-Id: I11381e78580b97982b25a52aa06f2192def7353f
parent 45957fa9
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -31865,6 +31865,7 @@ package android.os {
    method public void close();
    method public void close();
    method @NonNull public static android.os.SharedMemory create(@Nullable String, int) throws android.system.ErrnoException;
    method @NonNull public static android.os.SharedMemory create(@Nullable String, int) throws android.system.ErrnoException;
    method public int describeContents();
    method public int describeContents();
    method @NonNull public static android.os.SharedMemory fromFileDescriptor(@NonNull android.os.ParcelFileDescriptor);
    method public int getSize();
    method public int getSize();
    method @NonNull public java.nio.ByteBuffer map(int, int, int) throws android.system.ErrnoException;
    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;
    method @NonNull public java.nio.ByteBuffer mapReadOnly() throws android.system.ErrnoException;
+0 −4
Original line number Original line Diff line number Diff line
@@ -274,10 +274,6 @@ package android.os {
    field public static final int VPN_UID = 1016; // 0x3f8
    field public static final int VPN_UID = 1016; // 0x3f8
  }
  }


  public final class SharedMemory implements java.io.Closeable android.os.Parcelable {
    method @NonNull public static android.os.SharedMemory create(@NonNull android.os.ParcelFileDescriptor);
  }

  public class StatsServiceManager {
  public class StatsServiceManager {
    method @NonNull public android.os.StatsServiceManager.ServiceRegisterer getStatsCompanionServiceRegisterer();
    method @NonNull public android.os.StatsServiceManager.ServiceRegisterer getStatsCompanionServiceRegisterer();
    method @NonNull public android.os.StatsServiceManager.ServiceRegisterer getStatsManagerServiceRegisterer();
    method @NonNull public android.os.StatsServiceManager.ServiceRegisterer getStatsManagerServiceRegisterer();
+14 −7
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@ package android.os;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.system.ErrnoException;
import android.system.ErrnoException;
import android.system.Os;
import android.system.Os;
@@ -95,15 +94,23 @@ public final class SharedMemory implements Parcelable, Closeable {
    }
    }


    /**
    /**
     * Creates from existing shared memory passed as {@link ParcelFileDesciptor}.
     * Creates an instance from existing shared memory passed as {@link ParcelFileDescriptor}.
     *
     *
     * @param fd File descriptor of 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.
     *
     *
     * @hide
     * @param fd File descriptor of shared memory passed as {@link ParcelFileDescriptor}.
     */
     */
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public static @NonNull SharedMemory fromFileDescriptor(@NonNull ParcelFileDescriptor fd) {
    public static @NonNull SharedMemory create(@NonNull ParcelFileDescriptor fd) {
        FileDescriptor f = new FileDescriptor();
        return new SharedMemory(fd.getFileDescriptor());
        f.setInt$(fd.detachFd());
        return new SharedMemory(f);
    }
    }


    private static final int PROT_MASK = OsConstants.PROT_READ | OsConstants.PROT_WRITE
    private static final int PROT_MASK = OsConstants.PROT_READ | OsConstants.PROT_WRITE