summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2018-11-14 12:55:27 -0800
committerSteven Moreland <smoreland@google.com>2018-11-14 17:57:58 -0800
commit8356bb86f14136437d9063f8e633b27ac27f3a18 (patch)
tree81ccd1b5300fd20f545c7b49d99e010f0c0e2d77
parentc51b2c9deb1189ec4ca583efbc9bc404aa10b325 (diff)
downloadnative-8356bb86f14136437d9063f8e633b27ac27f3a18.tar.gz
libbinder_ndk: remove NullableStrongBinder
Nullable types do not exist in Java. For most Java types, the type is split into a nullable and non-nullable variant. This is because C++ types are more usually non-nullable, but everything in Java is non-nullable. This does mean that some Java interfaces may have to have '@Nullable' added to them in order to function as expected w/ the NDK. It also means that some transactions will be allowed in Java which are not allowed in C++. However, in Java, if a null is ignored, it will just result in a NullPointerException and be delivered to the other side. C++ does not have this same capacity (in Android), and so instead, we distinguish nullability in the type system. The basic layout is: NDK layer - all objects are nullable if they are nullable in Java NDK C++ wrapper - functions are provided for nullable and non-nullable variants AIDL - @Nullable selects nullable wrapper if desired, but the default is to return an error to the remote process (like Java would throw NullPointerException). Bug: 111445392 Test: android.binder.cts Change-Id: I615420f735a45ef7869b9ee7e86ce21b844d84a2
-rw-r--r--libs/binder/ndk/include_ndk/android/binder_parcel.h20
-rw-r--r--libs/binder/ndk/include_ndk/android/binder_parcel_utils.h22
-rw-r--r--libs/binder/ndk/libbinder_ndk.map.txt1
-rw-r--r--libs/binder/ndk/parcel.cpp11
4 files changed, 25 insertions, 29 deletions
diff --git a/libs/binder/ndk/include_ndk/android/binder_parcel.h b/libs/binder/ndk/include_ndk/android/binder_parcel.h
index 4ee1b67653..c6178984bc 100644
--- a/libs/binder/ndk/include_ndk/android/binder_parcel.h
+++ b/libs/binder/ndk/include_ndk/android/binder_parcel.h
@@ -297,12 +297,11 @@ typedef int8_t* (*AParcel_byteArrayAllocator)(void* arrayData, size_t length);
binder_status_t AParcel_writeStrongBinder(AParcel* parcel, AIBinder* binder) __INTRODUCED_IN(29);
/**
- * Reads an AIBinder from the next location in a non-null parcel. This will fail if the binder is
- * non-null. One strong ref-count of ownership is passed to the caller of this function.
+ * Reads an AIBinder from the next location in a non-null parcel. One strong ref-count of ownership
+ * is passed to the caller of this function.
*
* \param parcel the parcel to read from.
- * \param binder the out parameter for what is read from the parcel. This will not be null on
- * success.
+ * \param binder the out parameter for what is read from the parcel. This may be null.
*
* \return STATUS_OK on successful write.
*/
@@ -310,19 +309,6 @@ binder_status_t AParcel_readStrongBinder(const AParcel* parcel, AIBinder** binde
__INTRODUCED_IN(29);
/**
- * Reads an AIBinder from the next location in a non-null parcel. This may read a null. One strong
- * ref-count of ownership is passed to the caller of this function.
- *
- * \param parcel the parcel to read from.
- * \param binder the out parameter for what is read from the parcel. This may be null even on
- * success.
- *
- * \return STATUS_OK on successful write.
- */
-binder_status_t AParcel_readNullableStrongBinder(const AParcel* parcel, AIBinder** binder)
- __INTRODUCED_IN(29);
-
-/**
* Writes a file descriptor to the next location in a non-null parcel. This does not take ownership
* of fd.
*
diff --git a/libs/binder/ndk/include_ndk/android/binder_parcel_utils.h b/libs/binder/ndk/include_ndk/android/binder_parcel_utils.h
index 59c06ae610..657577ecbd 100644
--- a/libs/binder/ndk/include_ndk/android/binder_parcel_utils.h
+++ b/libs/binder/ndk/include_ndk/android/binder_parcel_utils.h
@@ -85,6 +85,28 @@ static inline void AParcel_stdVectorSetter(void* vectorData, size_t index, T val
}
/**
+ * Convenience method to write a strong binder but return an error if it is null.
+ */
+static inline binder_status_t AParcel_writeRequiredStrongBinder(AParcel* parcel, AIBinder* binder) {
+ if (binder == nullptr) {
+ return STATUS_UNEXPECTED_NULL;
+ }
+ return AParcel_writeStrongBinder(parcel, binder);
+}
+
+/**
+ * Convenience method to read a strong binder but return an error if it is null.
+ */
+static inline binder_status_t AParcel_readRequiredStrongBinder(const AParcel* parcel,
+ AIBinder** binder) {
+ binder_status_t ret = AParcel_readStrongBinder(parcel, binder);
+ if (ret == STATUS_OK && *binder == nullptr) {
+ return STATUS_UNEXPECTED_NULL;
+ }
+ return ret;
+}
+
+/**
* Allocates a std::string to length and returns the underlying buffer. For use with
* AParcel_readString. See use below in AParcel_readString(const AParcel*, std::string*).
*/
diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt
index 7a75942406..41df90bd64 100644
--- a/libs/binder/ndk/libbinder_ndk.map.txt
+++ b/libs/binder/ndk/libbinder_ndk.map.txt
@@ -39,7 +39,6 @@ LIBBINDER_NDK { # introduced=29
AParcel_readInt32Array;
AParcel_readInt64;
AParcel_readInt64Array;
- AParcel_readNullableStrongBinder;
AParcel_readParcelFileDescriptor;
AParcel_readStatusHeader;
AParcel_readString;
diff --git a/libs/binder/ndk/parcel.cpp b/libs/binder/ndk/parcel.cpp
index 8e5b4776e3..53e50100a3 100644
--- a/libs/binder/ndk/parcel.cpp
+++ b/libs/binder/ndk/parcel.cpp
@@ -194,17 +194,6 @@ binder_status_t AParcel_writeStrongBinder(AParcel* parcel, AIBinder* binder) {
}
binder_status_t AParcel_readStrongBinder(const AParcel* parcel, AIBinder** binder) {
sp<IBinder> readBinder = nullptr;
- status_t status = parcel->get()->readStrongBinder(&readBinder);
- if (status != STATUS_OK) {
- return PruneStatusT(status);
- }
- sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(readBinder);
- AIBinder_incStrong(ret.get());
- *binder = ret.get();
- return PruneStatusT(status);
-}
-binder_status_t AParcel_readNullableStrongBinder(const AParcel* parcel, AIBinder** binder) {
- sp<IBinder> readBinder = nullptr;
status_t status = parcel->get()->readNullableStrongBinder(&readBinder);
if (status != STATUS_OK) {
return PruneStatusT(status);