diff options
| -rw-r--r-- | core/api/current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/os/Parcel.java | 8 | ||||
| -rw-r--r-- | core/java/android/os/flags.aconfig | 9 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/os/ParcelTest.java | 61 |
4 files changed, 15 insertions, 65 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index fbc8eefdd945..216bbab882a9 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -34264,6 +34264,7 @@ package android.os { method public boolean hasFileDescriptors(); method public boolean hasFileDescriptors(int, int); method public byte[] marshall(); + method @FlaggedApi("android.os.parcel_marshall_bytebuffer") public void marshall(@NonNull java.nio.ByteBuffer); method @NonNull public static android.os.Parcel obtain(); method @NonNull public static android.os.Parcel obtain(@NonNull android.os.IBinder); method @Deprecated @Nullable public Object[] readArray(@Nullable ClassLoader); @@ -34333,6 +34334,7 @@ package android.os { method public void setDataSize(int); method public void setPropagateAllowBlocking(); method public void unmarshall(@NonNull byte[], int, int); + method @FlaggedApi("android.os.parcel_marshall_bytebuffer") public void unmarshall(@NonNull java.nio.ByteBuffer); method public void writeArray(@Nullable Object[]); method public void writeBinderArray(@Nullable android.os.IBinder[]); method public void writeBinderList(@Nullable java.util.List<android.os.IBinder>); diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java index 6cb49b3ea166..4a9928532b93 100644 --- a/core/java/android/os/Parcel.java +++ b/core/java/android/os/Parcel.java @@ -20,6 +20,7 @@ import static com.android.internal.util.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; +import android.annotation.FlaggedApi; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; @@ -27,6 +28,7 @@ import android.annotation.SuppressLint; import android.annotation.TestApi; import android.app.AppOpsManager; import android.compat.annotation.UnsupportedAppUsage; +import android.os.Flags; import android.ravenwood.annotation.RavenwoodClassLoadHook; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.ravenwood.annotation.RavenwoodReplace; @@ -837,9 +839,8 @@ public final class Parcel { * @param buffer The ByteBuffer to write the data to. * @throws ReadOnlyBufferException if the buffer is read-only. * @throws BufferOverflowException if the buffer is too small. - * - * @hide */ + @FlaggedApi(Flags.FLAG_PARCEL_MARSHALL_BYTEBUFFER) public final void marshall(@NonNull ByteBuffer buffer) { if (buffer == null) { throw new NullPointerException(); @@ -875,9 +876,8 @@ public final class Parcel { * Fills the raw bytes of this Parcel with data from the supplied buffer. * * @param buffer will read buffer.remaining() bytes from the buffer. - * - * @hide */ + @FlaggedApi(Flags.FLAG_PARCEL_MARSHALL_BYTEBUFFER) public final void unmarshall(@NonNull ByteBuffer buffer) { if (buffer == null) { throw new NullPointerException(); diff --git a/core/java/android/os/flags.aconfig b/core/java/android/os/flags.aconfig index 86acb2b21cfa..0150d171d51c 100644 --- a/core/java/android/os/flags.aconfig +++ b/core/java/android/os/flags.aconfig @@ -354,6 +354,15 @@ flag { flag { namespace: "system_performance" + name: "parcel_marshall_bytebuffer" + is_exported: true + description: "Parcel marshal/unmarshall APIs that use ByteBuffer." + is_fixed_read_only: true + bug: "401362825" +} + +flag { + namespace: "system_performance" name: "perfetto_sdk_tracing" description: "Tracing using Perfetto SDK." bug: "303199244" diff --git a/core/tests/coretests/src/android/os/ParcelTest.java b/core/tests/coretests/src/android/os/ParcelTest.java index bb059108d4b6..3e6520106ab0 100644 --- a/core/tests/coretests/src/android/os/ParcelTest.java +++ b/core/tests/coretests/src/android/os/ParcelTest.java @@ -29,8 +29,6 @@ import android.util.Log; import androidx.test.ext.junit.runners.AndroidJUnit4; -import java.nio.BufferOverflowException; -import java.nio.ByteBuffer; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -418,63 +416,4 @@ public class ParcelTest { int binderEndPos = pA.dataPosition(); assertTrue(pA.hasBinders(binderStartPos, binderEndPos - binderStartPos)); } - - private static final byte[] TEST_DATA = new byte[] {4, 8, 15, 16, 23, 42}; - - // Allow for some Parcel overhead - private static final int TEST_DATA_LENGTH = TEST_DATA.length + 100; - - @Test - public void testMarshall_ByteBuffer_wrapped() { - ByteBuffer bb = ByteBuffer.allocate(TEST_DATA_LENGTH); - testMarshall_ByteBuffer(bb); - } - - @Test - public void testMarshall_DirectByteBuffer() { - ByteBuffer bb = ByteBuffer.allocateDirect(TEST_DATA_LENGTH); - testMarshall_ByteBuffer(bb); - } - - private void testMarshall_ByteBuffer(ByteBuffer bb) { - // Ensure that Parcel respects the starting offset by not starting at 0 - bb.position(1); - bb.mark(); - - // Parcel test data, then marshall into the ByteBuffer - Parcel p1 = Parcel.obtain(); - p1.writeByteArray(TEST_DATA); - p1.marshall(bb); - p1.recycle(); - - assertTrue(bb.position() > 1); - bb.reset(); - - // Unmarshall test data into a new Parcel - Parcel p2 = Parcel.obtain(); - bb.reset(); - p2.unmarshall(bb); - assertTrue(bb.position() > 1); - p2.setDataPosition(0); - byte[] marshalled = p2.marshall(); - - bb.reset(); - for (int i = 0; i < TEST_DATA.length; i++) { - assertEquals(bb.get(), marshalled[i]); - } - - byte[] testDataCopy = new byte[TEST_DATA.length]; - p2.setDataPosition(0); - p2.readByteArray(testDataCopy); - for (int i = 0; i < TEST_DATA.length; i++) { - assertEquals(TEST_DATA[i], testDataCopy[i]); - } - - // Test that overflowing the buffer throws an exception - bb.reset(); - // Leave certainly not enough room for the test data - bb.limit(bb.position() + TEST_DATA.length - 1); - assertThrows(BufferOverflowException.class, () -> p2.marshall(bb)); - p2.recycle(); - } } |