summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJooyung Han <jooyung@google.com>2021-11-25 01:06:52 +0900
committerJooyung Han <jooyung@google.com>2021-12-11 11:40:55 +0900
commit8a3ab3aadc2b54e140dac4c0e5eb389ffe2e5fc3 (patch)
tree1a57cc6ea16fb1dbef551cc7403ac34120fc16f2
parent889451ed46c40eb11ac5942197c551bee2bf3ef9 (diff)
downloadnative-8a3ab3aadc2b54e140dac4c0e5eb389ffe2e5fc3.tar.gz
binder_ndk: fix read/write interface
To meet the legacy CPP behavior, reading and writing null interface values is okay even when @nullable is not specified in AIDL. Bug: 151817759 Test: atest CtsNdkBinderTestCases Change-Id: I6f33e5ce1071f52681988fd6c1b6b8f30923c8b2
-rw-r--r--libs/binder/ndk/include_cpp/android/binder_parcel_utils.h13
1 files changed, 3 insertions, 10 deletions
diff --git a/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h b/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h
index c1487c0bd2..e5560f8ef5 100644
--- a/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h
+++ b/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h
@@ -482,9 +482,7 @@ static inline binder_status_t AParcel_readVector(
template <typename P>
static inline binder_status_t AParcel_writeParcelable(AParcel* parcel, const P& p) {
if constexpr (is_interface_v<P>) {
- if (!p) {
- return STATUS_UNEXPECTED_NULL;
- }
+ // Legacy behavior: allow null
return first_template_type_t<P>::writeToParcel(parcel, p);
} else {
static_assert(is_parcelable_v<P>);
@@ -502,13 +500,8 @@ static inline binder_status_t AParcel_writeParcelable(AParcel* parcel, const P&
template <typename P>
static inline binder_status_t AParcel_readParcelable(const AParcel* parcel, P* p) {
if constexpr (is_interface_v<P>) {
- binder_status_t status = first_template_type_t<P>::readFromParcel(parcel, p);
- if (status == STATUS_OK) {
- if (!*p) {
- return STATUS_UNEXPECTED_NULL;
- }
- }
- return status;
+ // Legacy behavior: allow null
+ return first_template_type_t<P>::readFromParcel(parcel, p);
} else {
static_assert(is_parcelable_v<P>);
int32_t null;