diff --git a/core/api/current.txt b/core/api/current.txt index 50580554e1ec4..0a1d5904be6c0 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -31471,6 +31471,7 @@ package android.os { method public int dataPosition(); method public int dataSize(); method public void enforceInterface(@NonNull String); + method public void enforceNoDataAvail(); method public boolean hasFileDescriptors(); method public boolean hasFileDescriptors(int, int); method public byte[] marshall(); diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java index 36645155a4723..3661ee0884b79 100644 --- a/core/java/android/os/Parcel.java +++ b/core/java/android/os/Parcel.java @@ -845,6 +845,19 @@ public final class Parcel { nativeEnforceInterface(mNativePtr, interfaceName); } + /** + * Verify there are no bytes left to be read on the Parcel. + * + * @throws BadParcelableException If the current position hasn't reached the end of the Parcel. + * When used over binder, this exception should propagate to the caller. + */ + public void enforceNoDataAvail() { + final int n = dataAvail(); + if (n > 0) { + throw new BadParcelableException("Parcel data not fully consumed, unread size: " + n); + } + } + /** * Writes the work source uid to the request headers. *