Loading libs/binder/ndk/include_ndk/android/binder_parcel.h +98 −44 Original line number Diff line number Diff line Loading @@ -50,80 +50,120 @@ typedef struct AParcel AParcel; */ void AParcel_delete(AParcel* parcel) __INTRODUCED_IN(29); /** * This is called to allocate a buffer for a C-style string (null-terminated). The returned buffer * should be at least length bytes. This includes space for a null terminator. length will always be * strictly less than or equal to the maximum size that can be held in a size_t and will always be * greater than 0. * * See also AParcel_readString. * * If allocation fails, null should be returned. */ typedef char* (*AParcel_stringAllocator)(void* stringData, size_t length); /** * This is called to allocate an array of size 'length'. * * See also AParcel_readStringArray */ typedef bool (*AParcel_stringArrayAllocator)(void* arrayData, size_t length); /** * This is called to allocate a string inside of an array that was allocated by an * AParcel_stringArrayAllocator. * * The index returned will always be within the range [0, length of arrayData). The returned buffer * should be at least length bytes. This includes space for a null-terminator. length will always be * strictly less than or equal to the maximum size that can be held in a size_t and will always be * greater than 0. * * See also AParcel_readStringArray */ typedef char* (*AParcel_stringArrayElementAllocator)(void* arrayData, size_t index, size_t length); /** * This returns the length and buffer of an array at a specific index in an arrayData object. * * See also AParcel_writeStringArray */ typedef const char* (*AParcel_stringArrayElementGetter)(const void* arrayData, size_t index, size_t* outLength); // @START-PRIMITIVE-VECTOR-GETTERS /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readInt32Array */ typedef int32_t* (*AParcel_int32Allocator)(void* arrayData, size_t length); typedef int32_t* (*AParcel_int32ArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readUint32Array */ typedef uint32_t* (*AParcel_uint32Allocator)(void* arrayData, size_t length); typedef uint32_t* (*AParcel_uint32ArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readInt64Array */ typedef int64_t* (*AParcel_int64Allocator)(void* arrayData, size_t length); typedef int64_t* (*AParcel_int64ArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readUint64Array */ typedef uint64_t* (*AParcel_uint64Allocator)(void* arrayData, size_t length); typedef uint64_t* (*AParcel_uint64ArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readFloatArray */ typedef float* (*AParcel_floatAllocator)(void* arrayData, size_t length); typedef float* (*AParcel_floatArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readDoubleArray */ typedef double* (*AParcel_doubleAllocator)(void* arrayData, size_t length); typedef double* (*AParcel_doubleArrayAllocator)(void* arrayData, size_t length); /** * This allocates an array of length length inside of arrayData and returns whether or not there was * This allocates an array of size 'length' inside of arrayData and returns whether or not there was * a success. * * See also AParcel_readBoolArray */ typedef bool (*AParcel_boolAllocator)(void* arrayData, size_t length); typedef bool (*AParcel_boolArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object at index. Loading @@ -142,37 +182,27 @@ typedef void (*AParcel_boolArraySetter)(void* arrayData, size_t index, bool valu /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readCharArray */ typedef char16_t* (*AParcel_charAllocator)(void* arrayData, size_t length); typedef char16_t* (*AParcel_charArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readByteArray */ typedef int8_t* (*AParcel_byteAllocator)(void* arrayData, size_t length); typedef int8_t* (*AParcel_byteArrayAllocator)(void* arrayData, size_t length); // @END-PRIMITIVE-VECTOR-GETTERS /** * This is called to allocate a buffer for a C-style string (null-terminated). The buffer should be * of length length which includes space for the null-terminator. * * See also AParcel_readString. * * If allocation fails, null should be returned. */ typedef char* (*AParcel_stringAllocator)(void* stringData, size_t length); /** * Writes an AIBinder to the next location in a non-null parcel. Can be null. */ Loading Loading @@ -229,20 +259,45 @@ binder_status_t AParcel_readStatusHeader(const AParcel* parcel, AStatus** status __INTRODUCED_IN(29); /** * Writes string value to the next location in a non-null parcel. * Writes utf-8 string value to the next location in a non-null parcel. */ binder_status_t AParcel_writeString(AParcel* parcel, const char* string, size_t length) __INTRODUCED_IN(29); /** * Reads and allocates string value from the next location in a non-null parcel. * Reads and allocates utf-8 string value from the next location in a non-null parcel. * * Data is passed to the string allocator once the string size is known. This size includes the * space for the null-terminator of this string. This allocator returns a buffer which is used as * the output buffer from this read. */ binder_status_t AParcel_readString(const AParcel* parcel, AParcel_stringAllocator allocator, void* stringData) __INTRODUCED_IN(29); binder_status_t AParcel_readString(const AParcel* parcel, void* stringData, AParcel_stringAllocator allocator) __INTRODUCED_IN(29); /** * Writes utf-8 string array data to the next location in a non-null parcel. * * length is the length of the array. AParcel_stringArrayElementGetter will be called for all * indices in range [0, length) with the arrayData provided here. The string length and buffer * returned from this function will be used to fill out the data from the parcel. */ binder_status_t AParcel_writeStringArray(AParcel* parcel, const void* arrayData, size_t length, AParcel_stringArrayElementGetter getter) __INTRODUCED_IN(29); /** * Reads and allocates utf-8 string array value from the next location in a non-null parcel. * * First, AParcel_stringArrayAllocator will be called with the size of the array to be read where * length is the length of the array to be read from the parcel. Then, for each index i in [0, * length), AParcel_stringArrayElementAllocator will be called with the length of the string to be * read from the parcel. The resultant buffer from each of these calls will be filled according to * the contents of the string that is read. */ binder_status_t AParcel_readStringArray(const AParcel* parcel, void* arrayData, AParcel_stringArrayAllocator allocator, AParcel_stringArrayElementAllocator elementAllocator) __INTRODUCED_IN(29); // @START-PRIMITIVE-READ-WRITE /** Loading Loading @@ -377,9 +432,8 @@ binder_status_t AParcel_writeDoubleArray(AParcel* parcel, const double* value, s * getter(arrayData, i) will be called for each i in [0, length) in order to get the underlying * values to write to the parcel. */ binder_status_t AParcel_writeBoolArray(AParcel* parcel, const void* arrayData, AParcel_boolArrayGetter getter, size_t length) __INTRODUCED_IN(29); binder_status_t AParcel_writeBoolArray(AParcel* parcel, const void* arrayData, size_t length, AParcel_boolArrayGetter getter) __INTRODUCED_IN(29); /** * Writes an array of char16_t to the next location in a non-null parcel. Loading @@ -401,7 +455,7 @@ binder_status_t AParcel_writeByteArray(AParcel* parcel, const int8_t* value, siz * corresponding data */ binder_status_t AParcel_readInt32Array(const AParcel* parcel, void* arrayData, AParcel_int32Allocator allocator) __INTRODUCED_IN(29); AParcel_int32ArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of uint32_t from the next location in a non-null parcel. Loading @@ -411,7 +465,7 @@ binder_status_t AParcel_readInt32Array(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readUint32Array(const AParcel* parcel, void* arrayData, AParcel_uint32Allocator allocator) __INTRODUCED_IN(29); AParcel_uint32ArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of int64_t from the next location in a non-null parcel. Loading @@ -421,7 +475,7 @@ binder_status_t AParcel_readUint32Array(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readInt64Array(const AParcel* parcel, void* arrayData, AParcel_int64Allocator allocator) __INTRODUCED_IN(29); AParcel_int64ArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of uint64_t from the next location in a non-null parcel. Loading @@ -431,7 +485,7 @@ binder_status_t AParcel_readInt64Array(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readUint64Array(const AParcel* parcel, void* arrayData, AParcel_uint64Allocator allocator) __INTRODUCED_IN(29); AParcel_uint64ArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of float from the next location in a non-null parcel. Loading @@ -441,7 +495,7 @@ binder_status_t AParcel_readUint64Array(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readFloatArray(const AParcel* parcel, void* arrayData, AParcel_floatAllocator allocator) __INTRODUCED_IN(29); AParcel_floatArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of double from the next location in a non-null parcel. Loading @@ -451,7 +505,7 @@ binder_status_t AParcel_readFloatArray(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readDoubleArray(const AParcel* parcel, void* arrayData, AParcel_doubleAllocator allocator) __INTRODUCED_IN(29); AParcel_doubleArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of bool from the next location in a non-null parcel. Loading @@ -460,7 +514,7 @@ binder_status_t AParcel_readDoubleArray(const AParcel* parcel, void* arrayData, * setter(arrayData, i, x) will be called where x is the value at the associated index. */ binder_status_t AParcel_readBoolArray(const AParcel* parcel, void* arrayData, AParcel_boolAllocator allocator, AParcel_boolArrayAllocator allocator, AParcel_boolArraySetter setter) __INTRODUCED_IN(29); /** Loading @@ -471,7 +525,7 @@ binder_status_t AParcel_readBoolArray(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readCharArray(const AParcel* parcel, void* arrayData, AParcel_charAllocator allocator) __INTRODUCED_IN(29); AParcel_charArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of int8_t from the next location in a non-null parcel. Loading @@ -481,7 +535,7 @@ binder_status_t AParcel_readCharArray(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readByteArray(const AParcel* parcel, void* arrayData, AParcel_byteAllocator allocator) __INTRODUCED_IN(29); AParcel_byteArrayAllocator allocator) __INTRODUCED_IN(29); // @END-PRIMITIVE-READ-WRITE Loading libs/binder/ndk/include_ndk/android/binder_parcel_utils.h +63 −8 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ namespace ndk { /** * This retrieves and allocates a vector to length length and returns the underlying buffer. * This retrieves and allocates a vector to size 'length' and returns the underlying buffer. */ template <typename T> static inline T* AParcel_stdVectorAllocator(void* vectorData, size_t length) { Loading @@ -48,10 +48,18 @@ static inline T* AParcel_stdVectorAllocator(void* vectorData, size_t length) { } /** * This allocates a vector to length length and returns whether the allocation is successful. * This allocates a vector to size 'length' and returns whether the allocation is successful. * * See also AParcel_stdVectorAllocator. Types used with this allocator have their sizes defined * externally with respect to the NDK, and that size information is not passed into the NDK. * Instead, it is used in cases where callbacks are used. * * See AParcel_readVector(const AParcel* parcel, std::vector<bool>) * See AParcel_readVector(const AParcel* parcel, std::vector<std::string>) */ static inline bool AParcel_stdVectorBoolAllocator(void* vectorData, size_t length) { std::vector<bool>* vec = static_cast<std::vector<bool>*>(vectorData); template <typename T> static inline bool AParcel_stdVectorExternalAllocator(void* vectorData, size_t length) { std::vector<T>* vec = static_cast<std::vector<T>*>(vectorData); if (length > vec->max_size()) return false; vec->resize(length); Loading Loading @@ -173,8 +181,8 @@ inline binder_status_t AParcel_readVector(const AParcel* parcel, std::vector<dou * Writes a vector of bool to the next location in a non-null parcel. */ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<bool>& vec) { return AParcel_writeBoolArray(parcel, static_cast<const void*>(&vec), AParcel_stdVectorGetter<bool>, vec.size()); return AParcel_writeBoolArray(parcel, static_cast<const void*>(&vec), vec.size(), AParcel_stdVectorGetter<bool>); } /** Loading @@ -182,7 +190,7 @@ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<bo */ inline binder_status_t AParcel_readVector(const AParcel* parcel, std::vector<bool>* vec) { void* vectorData = static_cast<void*>(vec); return AParcel_readBoolArray(parcel, vectorData, AParcel_stdVectorBoolAllocator, return AParcel_readBoolArray(parcel, vectorData, AParcel_stdVectorExternalAllocator<bool>, AParcel_stdVectorSetter<bool>); } Loading Loading @@ -228,6 +236,32 @@ static inline char* AParcel_stdStringAllocator(void* stringData, size_t length) return &(*str)[0]; } /** * Allocates a std::string inside of a std::vector<std::string> at index index to size 'length'. */ static inline char* AParcel_stdVectorStringElementAllocator(void* vectorData, size_t index, size_t length) { std::vector<std::string>* vec = static_cast<std::vector<std::string>*>(vectorData); std::string& element = vec->at(index); element.resize(length - 1); return &element[0]; } /** * This gets the length and buffer of a std::string inside of a std::vector<std::string> at index * index. */ static inline const char* AParcel_stdVectorStringElementGetter(const void* vectorData, size_t index, size_t* outLength) { const std::vector<std::string>* vec = static_cast<const std::vector<std::string>*>(vectorData); const std::string& element = vec->at(index); *outLength = element.size(); return element.c_str(); } /** * Convenience API for writing a std::string. */ Loading @@ -240,7 +274,28 @@ static inline binder_status_t AParcel_writeString(AParcel* parcel, const std::st */ static inline binder_status_t AParcel_readString(const AParcel* parcel, std::string* str) { void* stringData = static_cast<void*>(str); return AParcel_readString(parcel, AParcel_stdStringAllocator, stringData); return AParcel_readString(parcel, stringData, AParcel_stdStringAllocator); } /** * Convenience API for writing a std::vector<std::string> */ static inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<std::string>& vec) { const void* vectorData = static_cast<const void*>(&vec); return AParcel_writeStringArray(parcel, vectorData, vec.size(), AParcel_stdVectorStringElementGetter); } /** * Convenience API for reading a std::vector<std::string> */ static inline binder_status_t AParcel_readVector(const AParcel* parcel, std::vector<std::string>* vec) { void* vectorData = static_cast<void*>(vec); return AParcel_readStringArray(parcel, vectorData, AParcel_stdVectorExternalAllocator<std::string>, AParcel_stdVectorStringElementAllocator); } template <typename T> Loading libs/binder/ndk/libbinder_ndk.map.txt +2 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ LIBBINDER_NDK { # introduced=29 AParcel_readParcelFileDescriptor; AParcel_readStatusHeader; AParcel_readString; AParcel_readStringArray; AParcel_readStrongBinder; AParcel_readUint32; AParcel_readUint32Array; Loading @@ -63,6 +64,7 @@ LIBBINDER_NDK { # introduced=29 AParcel_writeParcelFileDescriptor; AParcel_writeStatusHeader; AParcel_writeString; AParcel_writeStringArray; AParcel_writeStrongBinder; AParcel_writeUint32; AParcel_writeUint32Array; Loading libs/binder/ndk/parcel.cpp +79 −17 File changed.Preview size limit exceeded, changes collapsed. Show changes libs/binder/ndk/scripts/gen_parcel_helper.py +12 −12 Original line number Diff line number Diff line Loading @@ -89,10 +89,10 @@ def main(): for pretty, cpp in data_types: nca = pretty in non_contiguously_addressable arg_type = "const " + cpp + "* value" if nca: arg_type = "const void* arrayData, AParcel_" + pretty.lower() + "ArrayGetter getter" arg_types = "const " + cpp + "* value, size_t length" if nca: arg_types = "const void* arrayData, size_t length, AParcel_" + pretty.lower() + "ArrayGetter getter" args = "value, length" if nca: args = "arrayData, getter, length, &Parcel::write" + pretty if nca: args = "arrayData, length, getter, &Parcel::write" + pretty header += "/**\n" header += " * Writes an array of " + cpp + " to the next location in a non-null parcel.\n" Loading @@ -101,8 +101,8 @@ def main(): header += " * getter(arrayData, i) will be called for each i in [0, length) in order to get the underlying values to write " header += "to the parcel.\n" header += " */\n" header += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_type + ", size_t length) __INTRODUCED_IN(29);\n\n" source += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_type + ", size_t length) {\n" header += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_types + ") __INTRODUCED_IN(29);\n\n" source += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_types + ") {\n" source += " return WriteArray<" + cpp + ">(parcel, " + args + ");\n"; source += "}\n\n" Loading @@ -111,13 +111,13 @@ def main(): read_func = "AParcel_read" + pretty + "Array" write_func = "AParcel_write" + pretty + "Array" allocator_type = "AParcel_" + pretty.lower() + "Allocator" allocator_type = "AParcel_" + pretty.lower() + "ArrayAllocator" getter_type = "AParcel_" + pretty.lower() + "ArrayGetter" setter_type = "AParcel_" + pretty.lower() + "ArraySetter" if nca: pre_header += "/**\n" pre_header += " * This allocates an array of length length inside of arrayData and returns whether or not there was " pre_header += " * This allocates an array of size 'length' inside of arrayData and returns whether or not there was " pre_header += "a success.\n" pre_header += " *\n" pre_header += " * See also " + read_func + "\n" Loading @@ -141,7 +141,7 @@ def main(): pre_header += "/**\n" pre_header += " * This is called to get the underlying data from an arrayData object.\n" pre_header += " *\n" pre_header += " * The implementation of this function should allocate a contiguous array of length length and " pre_header += " * The implementation of this function should allocate a contiguous array of size 'length' and " pre_header += "return that underlying buffer to be filled out. If there is an error or length is 0, null may be " pre_header += "returned.\n" pre_header += " *\n" Loading Loading @@ -178,9 +178,9 @@ def main(): cpp_helper += " * Writes a vector of " + cpp + " to the next location in a non-null parcel.\n" cpp_helper += " */\n" cpp_helper += "inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<" + cpp + ">& vec) {\n" write_args = "vec.data()" if nca: write_args = "static_cast<const void*>(&vec), AParcel_stdVectorGetter<" + cpp + ">" cpp_helper += " return AParcel_write" + pretty + "Array(parcel, " + write_args + ", vec.size());\n" write_args = "vec.data(), vec.size()" if nca: write_args = "static_cast<const void*>(&vec), vec.size(), AParcel_stdVectorGetter<" + cpp + ">" cpp_helper += " return AParcel_write" + pretty + "Array(parcel, " + write_args + ");\n" cpp_helper += "}\n\n" cpp_helper += "/**\n" Loading @@ -192,7 +192,7 @@ def main(): read_args += ["parcel"] read_args += ["vectorData"] if nca: read_args += ["AParcel_stdVectorBoolAllocator"] read_args += ["AParcel_stdVectorExternalAllocator<bool>"] read_args += ["AParcel_stdVectorSetter<" + cpp + ">"] else: read_args += ["AParcel_stdVectorAllocator<" + cpp + ">"] Loading Loading
libs/binder/ndk/include_ndk/android/binder_parcel.h +98 −44 Original line number Diff line number Diff line Loading @@ -50,80 +50,120 @@ typedef struct AParcel AParcel; */ void AParcel_delete(AParcel* parcel) __INTRODUCED_IN(29); /** * This is called to allocate a buffer for a C-style string (null-terminated). The returned buffer * should be at least length bytes. This includes space for a null terminator. length will always be * strictly less than or equal to the maximum size that can be held in a size_t and will always be * greater than 0. * * See also AParcel_readString. * * If allocation fails, null should be returned. */ typedef char* (*AParcel_stringAllocator)(void* stringData, size_t length); /** * This is called to allocate an array of size 'length'. * * See also AParcel_readStringArray */ typedef bool (*AParcel_stringArrayAllocator)(void* arrayData, size_t length); /** * This is called to allocate a string inside of an array that was allocated by an * AParcel_stringArrayAllocator. * * The index returned will always be within the range [0, length of arrayData). The returned buffer * should be at least length bytes. This includes space for a null-terminator. length will always be * strictly less than or equal to the maximum size that can be held in a size_t and will always be * greater than 0. * * See also AParcel_readStringArray */ typedef char* (*AParcel_stringArrayElementAllocator)(void* arrayData, size_t index, size_t length); /** * This returns the length and buffer of an array at a specific index in an arrayData object. * * See also AParcel_writeStringArray */ typedef const char* (*AParcel_stringArrayElementGetter)(const void* arrayData, size_t index, size_t* outLength); // @START-PRIMITIVE-VECTOR-GETTERS /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readInt32Array */ typedef int32_t* (*AParcel_int32Allocator)(void* arrayData, size_t length); typedef int32_t* (*AParcel_int32ArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readUint32Array */ typedef uint32_t* (*AParcel_uint32Allocator)(void* arrayData, size_t length); typedef uint32_t* (*AParcel_uint32ArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readInt64Array */ typedef int64_t* (*AParcel_int64Allocator)(void* arrayData, size_t length); typedef int64_t* (*AParcel_int64ArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readUint64Array */ typedef uint64_t* (*AParcel_uint64Allocator)(void* arrayData, size_t length); typedef uint64_t* (*AParcel_uint64ArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readFloatArray */ typedef float* (*AParcel_floatAllocator)(void* arrayData, size_t length); typedef float* (*AParcel_floatArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readDoubleArray */ typedef double* (*AParcel_doubleAllocator)(void* arrayData, size_t length); typedef double* (*AParcel_doubleArrayAllocator)(void* arrayData, size_t length); /** * This allocates an array of length length inside of arrayData and returns whether or not there was * This allocates an array of size 'length' inside of arrayData and returns whether or not there was * a success. * * See also AParcel_readBoolArray */ typedef bool (*AParcel_boolAllocator)(void* arrayData, size_t length); typedef bool (*AParcel_boolArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object at index. Loading @@ -142,37 +182,27 @@ typedef void (*AParcel_boolArraySetter)(void* arrayData, size_t index, bool valu /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readCharArray */ typedef char16_t* (*AParcel_charAllocator)(void* arrayData, size_t length); typedef char16_t* (*AParcel_charArrayAllocator)(void* arrayData, size_t length); /** * This is called to get the underlying data from an arrayData object. * * The implementation of this function should allocate a contiguous array of length length and * The implementation of this function should allocate a contiguous array of size 'length' and * return that underlying buffer to be filled out. If there is an error or length is 0, null may be * returned. * * See also AParcel_readByteArray */ typedef int8_t* (*AParcel_byteAllocator)(void* arrayData, size_t length); typedef int8_t* (*AParcel_byteArrayAllocator)(void* arrayData, size_t length); // @END-PRIMITIVE-VECTOR-GETTERS /** * This is called to allocate a buffer for a C-style string (null-terminated). The buffer should be * of length length which includes space for the null-terminator. * * See also AParcel_readString. * * If allocation fails, null should be returned. */ typedef char* (*AParcel_stringAllocator)(void* stringData, size_t length); /** * Writes an AIBinder to the next location in a non-null parcel. Can be null. */ Loading Loading @@ -229,20 +259,45 @@ binder_status_t AParcel_readStatusHeader(const AParcel* parcel, AStatus** status __INTRODUCED_IN(29); /** * Writes string value to the next location in a non-null parcel. * Writes utf-8 string value to the next location in a non-null parcel. */ binder_status_t AParcel_writeString(AParcel* parcel, const char* string, size_t length) __INTRODUCED_IN(29); /** * Reads and allocates string value from the next location in a non-null parcel. * Reads and allocates utf-8 string value from the next location in a non-null parcel. * * Data is passed to the string allocator once the string size is known. This size includes the * space for the null-terminator of this string. This allocator returns a buffer which is used as * the output buffer from this read. */ binder_status_t AParcel_readString(const AParcel* parcel, AParcel_stringAllocator allocator, void* stringData) __INTRODUCED_IN(29); binder_status_t AParcel_readString(const AParcel* parcel, void* stringData, AParcel_stringAllocator allocator) __INTRODUCED_IN(29); /** * Writes utf-8 string array data to the next location in a non-null parcel. * * length is the length of the array. AParcel_stringArrayElementGetter will be called for all * indices in range [0, length) with the arrayData provided here. The string length and buffer * returned from this function will be used to fill out the data from the parcel. */ binder_status_t AParcel_writeStringArray(AParcel* parcel, const void* arrayData, size_t length, AParcel_stringArrayElementGetter getter) __INTRODUCED_IN(29); /** * Reads and allocates utf-8 string array value from the next location in a non-null parcel. * * First, AParcel_stringArrayAllocator will be called with the size of the array to be read where * length is the length of the array to be read from the parcel. Then, for each index i in [0, * length), AParcel_stringArrayElementAllocator will be called with the length of the string to be * read from the parcel. The resultant buffer from each of these calls will be filled according to * the contents of the string that is read. */ binder_status_t AParcel_readStringArray(const AParcel* parcel, void* arrayData, AParcel_stringArrayAllocator allocator, AParcel_stringArrayElementAllocator elementAllocator) __INTRODUCED_IN(29); // @START-PRIMITIVE-READ-WRITE /** Loading Loading @@ -377,9 +432,8 @@ binder_status_t AParcel_writeDoubleArray(AParcel* parcel, const double* value, s * getter(arrayData, i) will be called for each i in [0, length) in order to get the underlying * values to write to the parcel. */ binder_status_t AParcel_writeBoolArray(AParcel* parcel, const void* arrayData, AParcel_boolArrayGetter getter, size_t length) __INTRODUCED_IN(29); binder_status_t AParcel_writeBoolArray(AParcel* parcel, const void* arrayData, size_t length, AParcel_boolArrayGetter getter) __INTRODUCED_IN(29); /** * Writes an array of char16_t to the next location in a non-null parcel. Loading @@ -401,7 +455,7 @@ binder_status_t AParcel_writeByteArray(AParcel* parcel, const int8_t* value, siz * corresponding data */ binder_status_t AParcel_readInt32Array(const AParcel* parcel, void* arrayData, AParcel_int32Allocator allocator) __INTRODUCED_IN(29); AParcel_int32ArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of uint32_t from the next location in a non-null parcel. Loading @@ -411,7 +465,7 @@ binder_status_t AParcel_readInt32Array(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readUint32Array(const AParcel* parcel, void* arrayData, AParcel_uint32Allocator allocator) __INTRODUCED_IN(29); AParcel_uint32ArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of int64_t from the next location in a non-null parcel. Loading @@ -421,7 +475,7 @@ binder_status_t AParcel_readUint32Array(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readInt64Array(const AParcel* parcel, void* arrayData, AParcel_int64Allocator allocator) __INTRODUCED_IN(29); AParcel_int64ArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of uint64_t from the next location in a non-null parcel. Loading @@ -431,7 +485,7 @@ binder_status_t AParcel_readInt64Array(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readUint64Array(const AParcel* parcel, void* arrayData, AParcel_uint64Allocator allocator) __INTRODUCED_IN(29); AParcel_uint64ArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of float from the next location in a non-null parcel. Loading @@ -441,7 +495,7 @@ binder_status_t AParcel_readUint64Array(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readFloatArray(const AParcel* parcel, void* arrayData, AParcel_floatAllocator allocator) __INTRODUCED_IN(29); AParcel_floatArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of double from the next location in a non-null parcel. Loading @@ -451,7 +505,7 @@ binder_status_t AParcel_readFloatArray(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readDoubleArray(const AParcel* parcel, void* arrayData, AParcel_doubleAllocator allocator) __INTRODUCED_IN(29); AParcel_doubleArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of bool from the next location in a non-null parcel. Loading @@ -460,7 +514,7 @@ binder_status_t AParcel_readDoubleArray(const AParcel* parcel, void* arrayData, * setter(arrayData, i, x) will be called where x is the value at the associated index. */ binder_status_t AParcel_readBoolArray(const AParcel* parcel, void* arrayData, AParcel_boolAllocator allocator, AParcel_boolArrayAllocator allocator, AParcel_boolArraySetter setter) __INTRODUCED_IN(29); /** Loading @@ -471,7 +525,7 @@ binder_status_t AParcel_readBoolArray(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readCharArray(const AParcel* parcel, void* arrayData, AParcel_charAllocator allocator) __INTRODUCED_IN(29); AParcel_charArrayAllocator allocator) __INTRODUCED_IN(29); /** * Reads an array of int8_t from the next location in a non-null parcel. Loading @@ -481,7 +535,7 @@ binder_status_t AParcel_readCharArray(const AParcel* parcel, void* arrayData, * corresponding data */ binder_status_t AParcel_readByteArray(const AParcel* parcel, void* arrayData, AParcel_byteAllocator allocator) __INTRODUCED_IN(29); AParcel_byteArrayAllocator allocator) __INTRODUCED_IN(29); // @END-PRIMITIVE-READ-WRITE Loading
libs/binder/ndk/include_ndk/android/binder_parcel_utils.h +63 −8 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ namespace ndk { /** * This retrieves and allocates a vector to length length and returns the underlying buffer. * This retrieves and allocates a vector to size 'length' and returns the underlying buffer. */ template <typename T> static inline T* AParcel_stdVectorAllocator(void* vectorData, size_t length) { Loading @@ -48,10 +48,18 @@ static inline T* AParcel_stdVectorAllocator(void* vectorData, size_t length) { } /** * This allocates a vector to length length and returns whether the allocation is successful. * This allocates a vector to size 'length' and returns whether the allocation is successful. * * See also AParcel_stdVectorAllocator. Types used with this allocator have their sizes defined * externally with respect to the NDK, and that size information is not passed into the NDK. * Instead, it is used in cases where callbacks are used. * * See AParcel_readVector(const AParcel* parcel, std::vector<bool>) * See AParcel_readVector(const AParcel* parcel, std::vector<std::string>) */ static inline bool AParcel_stdVectorBoolAllocator(void* vectorData, size_t length) { std::vector<bool>* vec = static_cast<std::vector<bool>*>(vectorData); template <typename T> static inline bool AParcel_stdVectorExternalAllocator(void* vectorData, size_t length) { std::vector<T>* vec = static_cast<std::vector<T>*>(vectorData); if (length > vec->max_size()) return false; vec->resize(length); Loading Loading @@ -173,8 +181,8 @@ inline binder_status_t AParcel_readVector(const AParcel* parcel, std::vector<dou * Writes a vector of bool to the next location in a non-null parcel. */ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<bool>& vec) { return AParcel_writeBoolArray(parcel, static_cast<const void*>(&vec), AParcel_stdVectorGetter<bool>, vec.size()); return AParcel_writeBoolArray(parcel, static_cast<const void*>(&vec), vec.size(), AParcel_stdVectorGetter<bool>); } /** Loading @@ -182,7 +190,7 @@ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<bo */ inline binder_status_t AParcel_readVector(const AParcel* parcel, std::vector<bool>* vec) { void* vectorData = static_cast<void*>(vec); return AParcel_readBoolArray(parcel, vectorData, AParcel_stdVectorBoolAllocator, return AParcel_readBoolArray(parcel, vectorData, AParcel_stdVectorExternalAllocator<bool>, AParcel_stdVectorSetter<bool>); } Loading Loading @@ -228,6 +236,32 @@ static inline char* AParcel_stdStringAllocator(void* stringData, size_t length) return &(*str)[0]; } /** * Allocates a std::string inside of a std::vector<std::string> at index index to size 'length'. */ static inline char* AParcel_stdVectorStringElementAllocator(void* vectorData, size_t index, size_t length) { std::vector<std::string>* vec = static_cast<std::vector<std::string>*>(vectorData); std::string& element = vec->at(index); element.resize(length - 1); return &element[0]; } /** * This gets the length and buffer of a std::string inside of a std::vector<std::string> at index * index. */ static inline const char* AParcel_stdVectorStringElementGetter(const void* vectorData, size_t index, size_t* outLength) { const std::vector<std::string>* vec = static_cast<const std::vector<std::string>*>(vectorData); const std::string& element = vec->at(index); *outLength = element.size(); return element.c_str(); } /** * Convenience API for writing a std::string. */ Loading @@ -240,7 +274,28 @@ static inline binder_status_t AParcel_writeString(AParcel* parcel, const std::st */ static inline binder_status_t AParcel_readString(const AParcel* parcel, std::string* str) { void* stringData = static_cast<void*>(str); return AParcel_readString(parcel, AParcel_stdStringAllocator, stringData); return AParcel_readString(parcel, stringData, AParcel_stdStringAllocator); } /** * Convenience API for writing a std::vector<std::string> */ static inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<std::string>& vec) { const void* vectorData = static_cast<const void*>(&vec); return AParcel_writeStringArray(parcel, vectorData, vec.size(), AParcel_stdVectorStringElementGetter); } /** * Convenience API for reading a std::vector<std::string> */ static inline binder_status_t AParcel_readVector(const AParcel* parcel, std::vector<std::string>* vec) { void* vectorData = static_cast<void*>(vec); return AParcel_readStringArray(parcel, vectorData, AParcel_stdVectorExternalAllocator<std::string>, AParcel_stdVectorStringElementAllocator); } template <typename T> Loading
libs/binder/ndk/libbinder_ndk.map.txt +2 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ LIBBINDER_NDK { # introduced=29 AParcel_readParcelFileDescriptor; AParcel_readStatusHeader; AParcel_readString; AParcel_readStringArray; AParcel_readStrongBinder; AParcel_readUint32; AParcel_readUint32Array; Loading @@ -63,6 +64,7 @@ LIBBINDER_NDK { # introduced=29 AParcel_writeParcelFileDescriptor; AParcel_writeStatusHeader; AParcel_writeString; AParcel_writeStringArray; AParcel_writeStrongBinder; AParcel_writeUint32; AParcel_writeUint32Array; Loading
libs/binder/ndk/parcel.cpp +79 −17 File changed.Preview size limit exceeded, changes collapsed. Show changes
libs/binder/ndk/scripts/gen_parcel_helper.py +12 −12 Original line number Diff line number Diff line Loading @@ -89,10 +89,10 @@ def main(): for pretty, cpp in data_types: nca = pretty in non_contiguously_addressable arg_type = "const " + cpp + "* value" if nca: arg_type = "const void* arrayData, AParcel_" + pretty.lower() + "ArrayGetter getter" arg_types = "const " + cpp + "* value, size_t length" if nca: arg_types = "const void* arrayData, size_t length, AParcel_" + pretty.lower() + "ArrayGetter getter" args = "value, length" if nca: args = "arrayData, getter, length, &Parcel::write" + pretty if nca: args = "arrayData, length, getter, &Parcel::write" + pretty header += "/**\n" header += " * Writes an array of " + cpp + " to the next location in a non-null parcel.\n" Loading @@ -101,8 +101,8 @@ def main(): header += " * getter(arrayData, i) will be called for each i in [0, length) in order to get the underlying values to write " header += "to the parcel.\n" header += " */\n" header += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_type + ", size_t length) __INTRODUCED_IN(29);\n\n" source += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_type + ", size_t length) {\n" header += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_types + ") __INTRODUCED_IN(29);\n\n" source += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_types + ") {\n" source += " return WriteArray<" + cpp + ">(parcel, " + args + ");\n"; source += "}\n\n" Loading @@ -111,13 +111,13 @@ def main(): read_func = "AParcel_read" + pretty + "Array" write_func = "AParcel_write" + pretty + "Array" allocator_type = "AParcel_" + pretty.lower() + "Allocator" allocator_type = "AParcel_" + pretty.lower() + "ArrayAllocator" getter_type = "AParcel_" + pretty.lower() + "ArrayGetter" setter_type = "AParcel_" + pretty.lower() + "ArraySetter" if nca: pre_header += "/**\n" pre_header += " * This allocates an array of length length inside of arrayData and returns whether or not there was " pre_header += " * This allocates an array of size 'length' inside of arrayData and returns whether or not there was " pre_header += "a success.\n" pre_header += " *\n" pre_header += " * See also " + read_func + "\n" Loading @@ -141,7 +141,7 @@ def main(): pre_header += "/**\n" pre_header += " * This is called to get the underlying data from an arrayData object.\n" pre_header += " *\n" pre_header += " * The implementation of this function should allocate a contiguous array of length length and " pre_header += " * The implementation of this function should allocate a contiguous array of size 'length' and " pre_header += "return that underlying buffer to be filled out. If there is an error or length is 0, null may be " pre_header += "returned.\n" pre_header += " *\n" Loading Loading @@ -178,9 +178,9 @@ def main(): cpp_helper += " * Writes a vector of " + cpp + " to the next location in a non-null parcel.\n" cpp_helper += " */\n" cpp_helper += "inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<" + cpp + ">& vec) {\n" write_args = "vec.data()" if nca: write_args = "static_cast<const void*>(&vec), AParcel_stdVectorGetter<" + cpp + ">" cpp_helper += " return AParcel_write" + pretty + "Array(parcel, " + write_args + ", vec.size());\n" write_args = "vec.data(), vec.size()" if nca: write_args = "static_cast<const void*>(&vec), vec.size(), AParcel_stdVectorGetter<" + cpp + ">" cpp_helper += " return AParcel_write" + pretty + "Array(parcel, " + write_args + ");\n" cpp_helper += "}\n\n" cpp_helper += "/**\n" Loading @@ -192,7 +192,7 @@ def main(): read_args += ["parcel"] read_args += ["vectorData"] if nca: read_args += ["AParcel_stdVectorBoolAllocator"] read_args += ["AParcel_stdVectorExternalAllocator<bool>"] read_args += ["AParcel_stdVectorSetter<" + cpp + ">"] else: read_args += ["AParcel_stdVectorAllocator<" + cpp + ">"] Loading