Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <android/binder_parcel.h> |
Steven Moreland | 4d5ad49 | 2018-09-13 12:49:16 -0700 | [diff] [blame] | 18 | #include "parcel_internal.h" |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 19 | |
Steven Moreland | 4d5ad49 | 2018-09-13 12:49:16 -0700 | [diff] [blame] | 20 | #include "ibinder_internal.h" |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 21 | #include "status_internal.h" |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 22 | |
Steven Moreland | 7b06f59 | 2018-10-03 19:25:32 -0700 | [diff] [blame] | 23 | #include <limits> |
| 24 | |
| 25 | #include <android-base/logging.h> |
Steven Moreland | 063f236 | 2018-10-18 12:49:11 -0700 | [diff] [blame] | 26 | #include <android-base/unique_fd.h> |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 27 | #include <binder/Parcel.h> |
Steven Moreland | 063f236 | 2018-10-18 12:49:11 -0700 | [diff] [blame] | 28 | #include <binder/ParcelFileDescriptor.h> |
Steven Moreland | 7b06f59 | 2018-10-03 19:25:32 -0700 | [diff] [blame] | 29 | #include <utils/Unicode.h> |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 30 | |
| 31 | using ::android::IBinder; |
| 32 | using ::android::Parcel; |
| 33 | using ::android::sp; |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 34 | using ::android::status_t; |
Steven Moreland | 063f236 | 2018-10-18 12:49:11 -0700 | [diff] [blame] | 35 | using ::android::base::unique_fd; |
| 36 | using ::android::os::ParcelFileDescriptor; |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 37 | |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 38 | template <typename T> |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 39 | using ContiguousArrayAllocator = bool (*)(void* arrayData, int32_t length, T** outBuffer); |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 40 | |
| 41 | template <typename T> |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 42 | using ArrayAllocator = bool (*)(void* arrayData, int32_t length); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 43 | template <typename T> |
| 44 | using ArrayGetter = T (*)(const void* arrayData, size_t index); |
| 45 | template <typename T> |
| 46 | using ArraySetter = void (*)(void* arrayData, size_t index, T value); |
| 47 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 48 | binder_status_t WriteAndValidateArraySize(AParcel* parcel, bool isNullArray, int32_t length) { |
| 49 | // only -1 can be used to represent a null array |
| 50 | if (length < -1) return STATUS_BAD_VALUE; |
| 51 | |
| 52 | if (!isNullArray && length < 0) { |
| 53 | LOG(ERROR) << __func__ << ": null array must be used with length == -1."; |
| 54 | return STATUS_BAD_VALUE; |
| 55 | } |
| 56 | if (isNullArray && length > 0) { |
| 57 | LOG(ERROR) << __func__ << ": null buffer cannot be for size " << length << " array."; |
| 58 | return STATUS_BAD_VALUE; |
| 59 | } |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 60 | |
| 61 | Parcel* rawParcel = parcel->get(); |
| 62 | |
| 63 | status_t status = rawParcel->writeInt32(static_cast<int32_t>(length)); |
| 64 | if (status != STATUS_OK) return PruneStatusT(status); |
| 65 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 66 | return STATUS_OK; |
| 67 | } |
| 68 | |
| 69 | template <typename T> |
| 70 | binder_status_t WriteArray(AParcel* parcel, const T* array, int32_t length) { |
| 71 | binder_status_t status = WriteAndValidateArraySize(parcel, array == nullptr, length); |
| 72 | if (status != STATUS_OK) return status; |
| 73 | if (length <= 0) return STATUS_OK; |
| 74 | |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 75 | int32_t size = 0; |
| 76 | if (__builtin_smul_overflow(sizeof(T), length, &size)) return STATUS_NO_MEMORY; |
| 77 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 78 | void* const data = parcel->get()->writeInplace(size); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 79 | if (data == nullptr) return STATUS_NO_MEMORY; |
| 80 | |
| 81 | memcpy(data, array, size); |
| 82 | |
| 83 | return STATUS_OK; |
| 84 | } |
| 85 | |
| 86 | // Each element in a char16_t array is converted to an int32_t (not packed). |
| 87 | template <> |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 88 | binder_status_t WriteArray<char16_t>(AParcel* parcel, const char16_t* array, int32_t length) { |
| 89 | binder_status_t status = WriteAndValidateArraySize(parcel, array == nullptr, length); |
| 90 | if (status != STATUS_OK) return status; |
| 91 | if (length <= 0) return STATUS_OK; |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 92 | |
| 93 | int32_t size = 0; |
| 94 | if (__builtin_smul_overflow(sizeof(char16_t), length, &size)) return STATUS_NO_MEMORY; |
| 95 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 96 | Parcel* rawParcel = parcel->get(); |
| 97 | |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 98 | for (int32_t i = 0; i < length; i++) { |
| 99 | status = rawParcel->writeChar(array[i]); |
| 100 | |
| 101 | if (status != STATUS_OK) return PruneStatusT(status); |
| 102 | } |
| 103 | |
| 104 | return STATUS_OK; |
| 105 | } |
| 106 | |
| 107 | template <typename T> |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 108 | binder_status_t ReadArray(const AParcel* parcel, void* arrayData, |
| 109 | ContiguousArrayAllocator<T> allocator) { |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 110 | const Parcel* rawParcel = parcel->get(); |
| 111 | |
| 112 | int32_t length; |
| 113 | status_t status = rawParcel->readInt32(&length); |
| 114 | |
| 115 | if (status != STATUS_OK) return PruneStatusT(status); |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 116 | if (length < -1) return STATUS_BAD_VALUE; |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 117 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 118 | T* array; |
| 119 | if (!allocator(arrayData, length, &array)) return STATUS_NO_MEMORY; |
| 120 | |
| 121 | if (length <= 0) return STATUS_OK; |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 122 | if (array == nullptr) return STATUS_NO_MEMORY; |
| 123 | |
| 124 | int32_t size = 0; |
| 125 | if (__builtin_smul_overflow(sizeof(T), length, &size)) return STATUS_NO_MEMORY; |
| 126 | |
| 127 | const void* data = rawParcel->readInplace(size); |
| 128 | if (data == nullptr) return STATUS_NO_MEMORY; |
| 129 | |
| 130 | memcpy(array, data, size); |
| 131 | |
| 132 | return STATUS_OK; |
| 133 | } |
| 134 | |
| 135 | // Each element in a char16_t array is converted to an int32_t (not packed) |
| 136 | template <> |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 137 | binder_status_t ReadArray<char16_t>(const AParcel* parcel, void* arrayData, |
| 138 | ContiguousArrayAllocator<char16_t> allocator) { |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 139 | const Parcel* rawParcel = parcel->get(); |
| 140 | |
| 141 | int32_t length; |
| 142 | status_t status = rawParcel->readInt32(&length); |
| 143 | |
| 144 | if (status != STATUS_OK) return PruneStatusT(status); |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 145 | if (length < -1) return STATUS_BAD_VALUE; |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 146 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 147 | char16_t* array; |
| 148 | if (!allocator(arrayData, length, &array)) return STATUS_NO_MEMORY; |
| 149 | |
| 150 | if (length <= 0) return STATUS_OK; |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 151 | if (array == nullptr) return STATUS_NO_MEMORY; |
| 152 | |
| 153 | int32_t size = 0; |
| 154 | if (__builtin_smul_overflow(sizeof(char16_t), length, &size)) return STATUS_NO_MEMORY; |
| 155 | |
| 156 | for (int32_t i = 0; i < length; i++) { |
| 157 | status = rawParcel->readChar(array + i); |
| 158 | |
| 159 | if (status != STATUS_OK) return PruneStatusT(status); |
| 160 | } |
| 161 | |
| 162 | return STATUS_OK; |
| 163 | } |
| 164 | |
| 165 | template <typename T> |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 166 | binder_status_t WriteArray(AParcel* parcel, const void* arrayData, int32_t length, |
Steven Moreland | 16e1eae | 2018-11-01 09:51:53 -0700 | [diff] [blame] | 167 | ArrayGetter<T> getter, status_t (Parcel::*write)(T)) { |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 168 | // we have no clue if arrayData represents a null object or not, we can only infer from length |
| 169 | bool arrayIsNull = length < 0; |
| 170 | binder_status_t status = WriteAndValidateArraySize(parcel, arrayIsNull, length); |
| 171 | if (status != STATUS_OK) return status; |
| 172 | if (length <= 0) return STATUS_OK; |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 173 | |
| 174 | Parcel* rawParcel = parcel->get(); |
| 175 | |
Steven Moreland | 763dc4c | 2018-12-12 11:30:06 -0800 | [diff] [blame^] | 176 | for (int32_t i = 0; i < length; i++) { |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 177 | status = (rawParcel->*write)(getter(arrayData, i)); |
| 178 | |
| 179 | if (status != STATUS_OK) return PruneStatusT(status); |
| 180 | } |
| 181 | |
| 182 | return STATUS_OK; |
| 183 | } |
| 184 | |
| 185 | template <typename T> |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 186 | binder_status_t ReadArray(const AParcel* parcel, void* arrayData, ArrayAllocator<T> allocator, |
| 187 | ArraySetter<T> setter, status_t (Parcel::*read)(T*) const) { |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 188 | const Parcel* rawParcel = parcel->get(); |
| 189 | |
| 190 | int32_t length; |
| 191 | status_t status = rawParcel->readInt32(&length); |
| 192 | |
| 193 | if (status != STATUS_OK) return PruneStatusT(status); |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 194 | if (length < -1) return STATUS_BAD_VALUE; |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 195 | |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 196 | if (!allocator(arrayData, length)) return STATUS_NO_MEMORY; |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 197 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 198 | if (length <= 0) return STATUS_OK; |
| 199 | |
Steven Moreland | 763dc4c | 2018-12-12 11:30:06 -0800 | [diff] [blame^] | 200 | for (int32_t i = 0; i < length; i++) { |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 201 | T readTarget; |
| 202 | status = (rawParcel->*read)(&readTarget); |
| 203 | if (status != STATUS_OK) return PruneStatusT(status); |
| 204 | |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 205 | setter(arrayData, i, readTarget); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | return STATUS_OK; |
| 209 | } |
| 210 | |
Steven Moreland | 9b80e28 | 2018-09-19 13:57:23 -0700 | [diff] [blame] | 211 | void AParcel_delete(AParcel* parcel) { |
| 212 | delete parcel; |
Steven Moreland | caa776c | 2018-09-04 13:48:11 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Steven Moreland | f32d1b0 | 2018-11-27 12:44:10 -0800 | [diff] [blame] | 215 | binder_status_t AParcel_setDataPosition(const AParcel* parcel, int32_t position) { |
| 216 | if (position < 0) { |
| 217 | return STATUS_BAD_VALUE; |
| 218 | } |
| 219 | |
| 220 | parcel->get()->setDataPosition(position); |
| 221 | return STATUS_OK; |
| 222 | } |
| 223 | |
| 224 | int32_t AParcel_getDataPosition(const AParcel* parcel) { |
| 225 | return parcel->get()->dataPosition(); |
| 226 | } |
| 227 | |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 228 | binder_status_t AParcel_writeStrongBinder(AParcel* parcel, AIBinder* binder) { |
Steven Moreland | c0e46d3 | 2018-09-12 15:40:49 -0700 | [diff] [blame] | 229 | sp<IBinder> writeBinder = binder != nullptr ? binder->getBinder() : nullptr; |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 230 | return parcel->get()->writeStrongBinder(writeBinder); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 231 | } |
| 232 | binder_status_t AParcel_readStrongBinder(const AParcel* parcel, AIBinder** binder) { |
| 233 | sp<IBinder> readBinder = nullptr; |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 234 | status_t status = parcel->get()->readNullableStrongBinder(&readBinder); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 235 | if (status != STATUS_OK) { |
| 236 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 237 | } |
Steven Moreland | 9496895 | 2018-09-05 14:42:59 -0700 | [diff] [blame] | 238 | sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(readBinder); |
Steven Moreland | 71cddc3 | 2018-08-30 23:39:22 -0700 | [diff] [blame] | 239 | AIBinder_incStrong(ret.get()); |
| 240 | *binder = ret.get(); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 241 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 242 | } |
Steven Moreland | 063f236 | 2018-10-18 12:49:11 -0700 | [diff] [blame] | 243 | |
| 244 | binder_status_t AParcel_writeParcelFileDescriptor(AParcel* parcel, int fd) { |
Steven Moreland | 4ce59c7 | 2018-11-16 15:21:15 -0800 | [diff] [blame] | 245 | std::unique_ptr<ParcelFileDescriptor> parcelFd; |
Steven Moreland | 063f236 | 2018-10-18 12:49:11 -0700 | [diff] [blame] | 246 | |
Steven Moreland | 4ce59c7 | 2018-11-16 15:21:15 -0800 | [diff] [blame] | 247 | if (fd < 0) { |
| 248 | if (fd != -1) { |
| 249 | return STATUS_UNKNOWN_ERROR; |
| 250 | } |
| 251 | // parcelFd = nullptr |
| 252 | } else { // fd >= 0 |
| 253 | parcelFd = std::make_unique<ParcelFileDescriptor>(unique_fd(fd)); |
| 254 | } |
| 255 | |
| 256 | status_t status = parcel->get()->writeNullableParcelable(parcelFd); |
Steven Moreland | 063f236 | 2018-10-18 12:49:11 -0700 | [diff] [blame] | 257 | |
| 258 | // ownership is retained by caller |
Steven Moreland | 4ce59c7 | 2018-11-16 15:21:15 -0800 | [diff] [blame] | 259 | if (parcelFd != nullptr) { |
| 260 | (void)parcelFd->release().release(); |
| 261 | } |
Steven Moreland | 063f236 | 2018-10-18 12:49:11 -0700 | [diff] [blame] | 262 | |
| 263 | return PruneStatusT(status); |
| 264 | } |
| 265 | |
| 266 | binder_status_t AParcel_readParcelFileDescriptor(const AParcel* parcel, int* fd) { |
Steven Moreland | 4ce59c7 | 2018-11-16 15:21:15 -0800 | [diff] [blame] | 267 | std::unique_ptr<ParcelFileDescriptor> parcelFd; |
| 268 | |
Steven Moreland | 063f236 | 2018-10-18 12:49:11 -0700 | [diff] [blame] | 269 | status_t status = parcel->get()->readParcelable(&parcelFd); |
| 270 | if (status != STATUS_OK) return PruneStatusT(status); |
| 271 | |
Steven Moreland | 4ce59c7 | 2018-11-16 15:21:15 -0800 | [diff] [blame] | 272 | if (parcelFd) { |
| 273 | *fd = parcelFd->release().release(); |
| 274 | } else { |
| 275 | *fd = -1; |
| 276 | } |
| 277 | |
Steven Moreland | 063f236 | 2018-10-18 12:49:11 -0700 | [diff] [blame] | 278 | return STATUS_OK; |
| 279 | } |
| 280 | |
Steven Moreland | 9a51db8 | 2018-09-14 10:59:35 -0700 | [diff] [blame] | 281 | binder_status_t AParcel_writeStatusHeader(AParcel* parcel, const AStatus* status) { |
| 282 | return PruneStatusT(status->get()->writeToParcel(parcel->get())); |
| 283 | } |
| 284 | binder_status_t AParcel_readStatusHeader(const AParcel* parcel, AStatus** status) { |
| 285 | ::android::binder::Status bstatus; |
| 286 | binder_status_t ret = PruneStatusT(bstatus.readFromParcel(*parcel->get())); |
Steven Moreland | c1a11b8 | 2018-10-29 18:47:23 -0700 | [diff] [blame] | 287 | if (ret == STATUS_OK) { |
Steven Moreland | 9a51db8 | 2018-09-14 10:59:35 -0700 | [diff] [blame] | 288 | *status = new AStatus(std::move(bstatus)); |
| 289 | } |
Steven Moreland | c1a11b8 | 2018-10-29 18:47:23 -0700 | [diff] [blame] | 290 | return PruneStatusT(ret); |
Steven Moreland | 9a51db8 | 2018-09-14 10:59:35 -0700 | [diff] [blame] | 291 | } |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 292 | |
Steven Moreland | b4e1461 | 2018-11-14 17:25:45 -0800 | [diff] [blame] | 293 | binder_status_t AParcel_writeString(AParcel* parcel, const char* string, int32_t length) { |
| 294 | if (string == nullptr) { |
| 295 | if (length != -1) { |
| 296 | LOG(WARNING) << __func__ << ": null string must be used with length == -1."; |
| 297 | return STATUS_BAD_VALUE; |
| 298 | } |
Steven Moreland | 7b06f59 | 2018-10-03 19:25:32 -0700 | [diff] [blame] | 299 | |
Steven Moreland | b4e1461 | 2018-11-14 17:25:45 -0800 | [diff] [blame] | 300 | status_t err = parcel->get()->writeInt32(-1); |
| 301 | return PruneStatusT(err); |
| 302 | } |
| 303 | |
| 304 | if (length < 0) { |
| 305 | LOG(WARNING) << __func__ << ": Negative string length: " << length; |
| 306 | return STATUS_BAD_VALUE; |
| 307 | } |
| 308 | |
| 309 | const uint8_t* str8 = (uint8_t*)string; |
Steven Moreland | 7b06f59 | 2018-10-03 19:25:32 -0700 | [diff] [blame] | 310 | const ssize_t len16 = utf8_to_utf16_length(str8, length); |
| 311 | |
| 312 | if (len16 < 0 || len16 >= std::numeric_limits<int32_t>::max()) { |
| 313 | LOG(WARNING) << __func__ << ": Invalid string length: " << len16; |
| 314 | return STATUS_BAD_VALUE; |
| 315 | } |
| 316 | |
| 317 | status_t err = parcel->get()->writeInt32(len16); |
| 318 | if (err) { |
| 319 | return PruneStatusT(err); |
| 320 | } |
| 321 | |
| 322 | void* str16 = parcel->get()->writeInplace((len16 + 1) * sizeof(char16_t)); |
| 323 | if (str16 == nullptr) { |
| 324 | return STATUS_NO_MEMORY; |
| 325 | } |
| 326 | |
| 327 | utf8_to_utf16(str8, length, (char16_t*)str16, (size_t)len16 + 1); |
| 328 | |
| 329 | return STATUS_OK; |
| 330 | } |
| 331 | |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 332 | binder_status_t AParcel_readString(const AParcel* parcel, void* stringData, |
| 333 | AParcel_stringAllocator allocator) { |
Steven Moreland | 7b06f59 | 2018-10-03 19:25:32 -0700 | [diff] [blame] | 334 | size_t len16; |
| 335 | const char16_t* str16 = parcel->get()->readString16Inplace(&len16); |
| 336 | |
| 337 | if (str16 == nullptr) { |
Steven Moreland | b4e1461 | 2018-11-14 17:25:45 -0800 | [diff] [blame] | 338 | if (allocator(stringData, -1, nullptr)) { |
| 339 | return STATUS_OK; |
| 340 | } |
| 341 | |
Steven Moreland | 7b06f59 | 2018-10-03 19:25:32 -0700 | [diff] [blame] | 342 | return STATUS_UNEXPECTED_NULL; |
| 343 | } |
| 344 | |
| 345 | ssize_t len8; |
| 346 | |
| 347 | if (len16 == 0) { |
| 348 | len8 = 1; |
| 349 | } else { |
| 350 | len8 = utf16_to_utf8_length(str16, len16) + 1; |
| 351 | } |
| 352 | |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 353 | if (len8 <= 0 || len8 > std::numeric_limits<int32_t>::max()) { |
Steven Moreland | 7b06f59 | 2018-10-03 19:25:32 -0700 | [diff] [blame] | 354 | LOG(WARNING) << __func__ << ": Invalid string length: " << len8; |
| 355 | return STATUS_BAD_VALUE; |
| 356 | } |
| 357 | |
Steven Moreland | b4e1461 | 2018-11-14 17:25:45 -0800 | [diff] [blame] | 358 | char* str8; |
| 359 | bool success = allocator(stringData, len8, &str8); |
Steven Moreland | 7b06f59 | 2018-10-03 19:25:32 -0700 | [diff] [blame] | 360 | |
Steven Moreland | b4e1461 | 2018-11-14 17:25:45 -0800 | [diff] [blame] | 361 | if (!success || str8 == nullptr) { |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 362 | LOG(WARNING) << __func__ << ": AParcel_stringAllocator failed to allocate."; |
Steven Moreland | 7b06f59 | 2018-10-03 19:25:32 -0700 | [diff] [blame] | 363 | return STATUS_NO_MEMORY; |
| 364 | } |
| 365 | |
| 366 | utf16_to_utf8(str16, len16, str8, len8); |
| 367 | |
| 368 | return STATUS_OK; |
| 369 | } |
| 370 | |
Steven Moreland | b4e1461 | 2018-11-14 17:25:45 -0800 | [diff] [blame] | 371 | binder_status_t AParcel_writeStringArray(AParcel* parcel, const void* arrayData, int32_t length, |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 372 | AParcel_stringArrayElementGetter getter) { |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 373 | // we have no clue if arrayData represents a null object or not, we can only infer from length |
| 374 | bool arrayIsNull = length < 0; |
| 375 | binder_status_t status = WriteAndValidateArraySize(parcel, arrayIsNull, length); |
| 376 | if (status != STATUS_OK) return status; |
| 377 | if (length <= 0) return STATUS_OK; |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 378 | |
Steven Moreland | 763dc4c | 2018-12-12 11:30:06 -0800 | [diff] [blame^] | 379 | for (int32_t i = 0; i < length; i++) { |
| 380 | int32_t elementLength = 0; |
Steven Moreland | e22a994 | 2018-12-11 18:57:05 -0800 | [diff] [blame] | 381 | const char* str = getter(arrayData, i, &elementLength); |
| 382 | if (str == nullptr && elementLength != -1) return STATUS_BAD_VALUE; |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 383 | |
Steven Moreland | e22a994 | 2018-12-11 18:57:05 -0800 | [diff] [blame] | 384 | binder_status_t status = AParcel_writeString(parcel, str, elementLength); |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 385 | if (status != STATUS_OK) return status; |
| 386 | } |
| 387 | |
| 388 | return STATUS_OK; |
| 389 | } |
| 390 | |
| 391 | // This implements AParcel_stringAllocator for a string using an array, index, and element |
| 392 | // allocator. |
| 393 | struct StringArrayElementAllocationAdapter { |
Steven Moreland | 6cf66ac | 2018-11-02 18:14:54 -0700 | [diff] [blame] | 394 | void* arrayData; // stringData from the NDK |
Steven Moreland | 763dc4c | 2018-12-12 11:30:06 -0800 | [diff] [blame^] | 395 | int32_t index; // index into the string array |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 396 | AParcel_stringArrayElementAllocator elementAllocator; |
| 397 | |
Steven Moreland | b4e1461 | 2018-11-14 17:25:45 -0800 | [diff] [blame] | 398 | static bool Allocator(void* stringData, int32_t length, char** buffer) { |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 399 | StringArrayElementAllocationAdapter* adapter = |
| 400 | static_cast<StringArrayElementAllocationAdapter*>(stringData); |
Steven Moreland | b4e1461 | 2018-11-14 17:25:45 -0800 | [diff] [blame] | 401 | return adapter->elementAllocator(adapter->arrayData, adapter->index, length, buffer); |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 402 | } |
| 403 | }; |
| 404 | |
| 405 | binder_status_t AParcel_readStringArray(const AParcel* parcel, void* arrayData, |
| 406 | AParcel_stringArrayAllocator allocator, |
| 407 | AParcel_stringArrayElementAllocator elementAllocator) { |
| 408 | const Parcel* rawParcel = parcel->get(); |
| 409 | |
| 410 | int32_t length; |
| 411 | status_t status = rawParcel->readInt32(&length); |
| 412 | |
| 413 | if (status != STATUS_OK) return PruneStatusT(status); |
Steven Moreland | b4e1461 | 2018-11-14 17:25:45 -0800 | [diff] [blame] | 414 | if (length < -1) return STATUS_BAD_VALUE; |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 415 | |
| 416 | if (!allocator(arrayData, length)) return STATUS_NO_MEMORY; |
| 417 | |
Steven Moreland | b4e1461 | 2018-11-14 17:25:45 -0800 | [diff] [blame] | 418 | if (length == -1) return STATUS_OK; // null string array |
| 419 | |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 420 | StringArrayElementAllocationAdapter adapter{ |
| 421 | .arrayData = arrayData, |
| 422 | .index = 0, |
| 423 | .elementAllocator = elementAllocator, |
| 424 | }; |
| 425 | |
| 426 | for (; adapter.index < length; adapter.index++) { |
Steven Moreland | b4e1461 | 2018-11-14 17:25:45 -0800 | [diff] [blame] | 427 | binder_status_t status = AParcel_readString(parcel, static_cast<void*>(&adapter), |
| 428 | StringArrayElementAllocationAdapter::Allocator); |
| 429 | |
| 430 | if (status != STATUS_OK) return status; |
Steven Moreland | 07fb9c9 | 2018-11-01 17:14:29 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | return STATUS_OK; |
| 434 | } |
| 435 | |
Steven Moreland | e22a994 | 2018-12-11 18:57:05 -0800 | [diff] [blame] | 436 | binder_status_t AParcel_writeParcelableArray(AParcel* parcel, const void* arrayData, int32_t length, |
| 437 | AParcel_writeParcelableElement elementWriter) { |
| 438 | // we have no clue if arrayData represents a null object or not, we can only infer from length |
| 439 | bool arrayIsNull = length < 0; |
| 440 | binder_status_t status = WriteAndValidateArraySize(parcel, arrayIsNull, length); |
| 441 | if (status != STATUS_OK) return status; |
| 442 | if (length <= 0) return STATUS_OK; |
| 443 | |
Steven Moreland | 763dc4c | 2018-12-12 11:30:06 -0800 | [diff] [blame^] | 444 | for (int32_t i = 0; i < length; i++) { |
Steven Moreland | e22a994 | 2018-12-11 18:57:05 -0800 | [diff] [blame] | 445 | binder_status_t status = elementWriter(parcel, arrayData, i); |
| 446 | if (status != STATUS_OK) return status; |
| 447 | } |
| 448 | |
| 449 | return STATUS_OK; |
| 450 | } |
| 451 | |
| 452 | binder_status_t AParcel_readParcelableArray(const AParcel* parcel, void* arrayData, |
| 453 | AParcel_parcelableArrayAllocator allocator, |
| 454 | AParcel_readParcelableElement elementReader) { |
| 455 | const Parcel* rawParcel = parcel->get(); |
| 456 | |
| 457 | int32_t length; |
| 458 | status_t status = rawParcel->readInt32(&length); |
| 459 | |
| 460 | if (status != STATUS_OK) return PruneStatusT(status); |
| 461 | if (length < -1) return STATUS_BAD_VALUE; |
| 462 | |
| 463 | if (!allocator(arrayData, length)) return STATUS_NO_MEMORY; |
| 464 | |
| 465 | if (length == -1) return STATUS_OK; // null array |
| 466 | |
Steven Moreland | 763dc4c | 2018-12-12 11:30:06 -0800 | [diff] [blame^] | 467 | for (int32_t i = 0; i < length; i++) { |
Steven Moreland | e22a994 | 2018-12-11 18:57:05 -0800 | [diff] [blame] | 468 | binder_status_t status = elementReader(parcel, arrayData, i); |
| 469 | if (status != STATUS_OK) return status; |
| 470 | } |
| 471 | |
| 472 | return STATUS_OK; |
| 473 | } |
| 474 | |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 475 | // See gen_parcel_helper.py. These auto-generated read/write methods use the same types for |
| 476 | // libbinder and this library. |
| 477 | // @START |
| 478 | binder_status_t AParcel_writeInt32(AParcel* parcel, int32_t value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 479 | status_t status = parcel->get()->writeInt32(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 480 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | binder_status_t AParcel_writeUint32(AParcel* parcel, uint32_t value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 484 | status_t status = parcel->get()->writeUint32(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 485 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | binder_status_t AParcel_writeInt64(AParcel* parcel, int64_t value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 489 | status_t status = parcel->get()->writeInt64(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 490 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | binder_status_t AParcel_writeUint64(AParcel* parcel, uint64_t value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 494 | status_t status = parcel->get()->writeUint64(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 495 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | binder_status_t AParcel_writeFloat(AParcel* parcel, float value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 499 | status_t status = parcel->get()->writeFloat(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 500 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | binder_status_t AParcel_writeDouble(AParcel* parcel, double value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 504 | status_t status = parcel->get()->writeDouble(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 505 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | binder_status_t AParcel_writeBool(AParcel* parcel, bool value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 509 | status_t status = parcel->get()->writeBool(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 510 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | binder_status_t AParcel_writeChar(AParcel* parcel, char16_t value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 514 | status_t status = parcel->get()->writeChar(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 515 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | binder_status_t AParcel_writeByte(AParcel* parcel, int8_t value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 519 | status_t status = parcel->get()->writeByte(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 520 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | binder_status_t AParcel_readInt32(const AParcel* parcel, int32_t* value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 524 | status_t status = parcel->get()->readInt32(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 525 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | binder_status_t AParcel_readUint32(const AParcel* parcel, uint32_t* value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 529 | status_t status = parcel->get()->readUint32(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 530 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | binder_status_t AParcel_readInt64(const AParcel* parcel, int64_t* value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 534 | status_t status = parcel->get()->readInt64(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 535 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | binder_status_t AParcel_readUint64(const AParcel* parcel, uint64_t* value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 539 | status_t status = parcel->get()->readUint64(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 540 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | binder_status_t AParcel_readFloat(const AParcel* parcel, float* value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 544 | status_t status = parcel->get()->readFloat(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 545 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | binder_status_t AParcel_readDouble(const AParcel* parcel, double* value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 549 | status_t status = parcel->get()->readDouble(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 550 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | binder_status_t AParcel_readBool(const AParcel* parcel, bool* value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 554 | status_t status = parcel->get()->readBool(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 555 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | binder_status_t AParcel_readChar(const AParcel* parcel, char16_t* value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 559 | status_t status = parcel->get()->readChar(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 560 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | binder_status_t AParcel_readByte(const AParcel* parcel, int8_t* value) { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 564 | status_t status = parcel->get()->readByte(value); |
Steven Moreland | 5d62e44 | 2018-09-13 15:01:02 -0700 | [diff] [blame] | 565 | return PruneStatusT(status); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 568 | binder_status_t AParcel_writeInt32Array(AParcel* parcel, const int32_t* arrayData, int32_t length) { |
Steven Moreland | e3d0958 | 2018-11-02 19:29:36 -0700 | [diff] [blame] | 569 | return WriteArray<int32_t>(parcel, arrayData, length); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Steven Moreland | e3d0958 | 2018-11-02 19:29:36 -0700 | [diff] [blame] | 572 | binder_status_t AParcel_writeUint32Array(AParcel* parcel, const uint32_t* arrayData, |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 573 | int32_t length) { |
Steven Moreland | e3d0958 | 2018-11-02 19:29:36 -0700 | [diff] [blame] | 574 | return WriteArray<uint32_t>(parcel, arrayData, length); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 577 | binder_status_t AParcel_writeInt64Array(AParcel* parcel, const int64_t* arrayData, int32_t length) { |
Steven Moreland | e3d0958 | 2018-11-02 19:29:36 -0700 | [diff] [blame] | 578 | return WriteArray<int64_t>(parcel, arrayData, length); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Steven Moreland | e3d0958 | 2018-11-02 19:29:36 -0700 | [diff] [blame] | 581 | binder_status_t AParcel_writeUint64Array(AParcel* parcel, const uint64_t* arrayData, |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 582 | int32_t length) { |
Steven Moreland | e3d0958 | 2018-11-02 19:29:36 -0700 | [diff] [blame] | 583 | return WriteArray<uint64_t>(parcel, arrayData, length); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 586 | binder_status_t AParcel_writeFloatArray(AParcel* parcel, const float* arrayData, int32_t length) { |
Steven Moreland | e3d0958 | 2018-11-02 19:29:36 -0700 | [diff] [blame] | 587 | return WriteArray<float>(parcel, arrayData, length); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 590 | binder_status_t AParcel_writeDoubleArray(AParcel* parcel, const double* arrayData, int32_t length) { |
Steven Moreland | e3d0958 | 2018-11-02 19:29:36 -0700 | [diff] [blame] | 591 | return WriteArray<double>(parcel, arrayData, length); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 594 | binder_status_t AParcel_writeBoolArray(AParcel* parcel, const void* arrayData, int32_t length, |
Steven Moreland | 16e1eae | 2018-11-01 09:51:53 -0700 | [diff] [blame] | 595 | AParcel_boolArrayGetter getter) { |
| 596 | return WriteArray<bool>(parcel, arrayData, length, getter, &Parcel::writeBool); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 599 | binder_status_t AParcel_writeCharArray(AParcel* parcel, const char16_t* arrayData, int32_t length) { |
Steven Moreland | e3d0958 | 2018-11-02 19:29:36 -0700 | [diff] [blame] | 600 | return WriteArray<char16_t>(parcel, arrayData, length); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Steven Moreland | 01ebcf7 | 2018-11-15 15:06:26 -0800 | [diff] [blame] | 603 | binder_status_t AParcel_writeByteArray(AParcel* parcel, const int8_t* arrayData, int32_t length) { |
Steven Moreland | e3d0958 | 2018-11-02 19:29:36 -0700 | [diff] [blame] | 604 | return WriteArray<int8_t>(parcel, arrayData, length); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 607 | binder_status_t AParcel_readInt32Array(const AParcel* parcel, void* arrayData, |
Steven Moreland | 9ac9dca | 2018-11-01 10:07:31 -0700 | [diff] [blame] | 608 | AParcel_int32ArrayAllocator allocator) { |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 609 | return ReadArray<int32_t>(parcel, arrayData, allocator); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 612 | binder_status_t AParcel_readUint32Array(const AParcel* parcel, void* arrayData, |
Steven Moreland | 9ac9dca | 2018-11-01 10:07:31 -0700 | [diff] [blame] | 613 | AParcel_uint32ArrayAllocator allocator) { |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 614 | return ReadArray<uint32_t>(parcel, arrayData, allocator); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 617 | binder_status_t AParcel_readInt64Array(const AParcel* parcel, void* arrayData, |
Steven Moreland | 9ac9dca | 2018-11-01 10:07:31 -0700 | [diff] [blame] | 618 | AParcel_int64ArrayAllocator allocator) { |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 619 | return ReadArray<int64_t>(parcel, arrayData, allocator); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 622 | binder_status_t AParcel_readUint64Array(const AParcel* parcel, void* arrayData, |
Steven Moreland | 9ac9dca | 2018-11-01 10:07:31 -0700 | [diff] [blame] | 623 | AParcel_uint64ArrayAllocator allocator) { |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 624 | return ReadArray<uint64_t>(parcel, arrayData, allocator); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 627 | binder_status_t AParcel_readFloatArray(const AParcel* parcel, void* arrayData, |
Steven Moreland | 9ac9dca | 2018-11-01 10:07:31 -0700 | [diff] [blame] | 628 | AParcel_floatArrayAllocator allocator) { |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 629 | return ReadArray<float>(parcel, arrayData, allocator); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 632 | binder_status_t AParcel_readDoubleArray(const AParcel* parcel, void* arrayData, |
Steven Moreland | 9ac9dca | 2018-11-01 10:07:31 -0700 | [diff] [blame] | 633 | AParcel_doubleArrayAllocator allocator) { |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 634 | return ReadArray<double>(parcel, arrayData, allocator); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 637 | binder_status_t AParcel_readBoolArray(const AParcel* parcel, void* arrayData, |
Steven Moreland | 9ac9dca | 2018-11-01 10:07:31 -0700 | [diff] [blame] | 638 | AParcel_boolArrayAllocator allocator, |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 639 | AParcel_boolArraySetter setter) { |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 640 | return ReadArray<bool>(parcel, arrayData, allocator, setter, &Parcel::readBool); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 643 | binder_status_t AParcel_readCharArray(const AParcel* parcel, void* arrayData, |
Steven Moreland | 9ac9dca | 2018-11-01 10:07:31 -0700 | [diff] [blame] | 644 | AParcel_charArrayAllocator allocator) { |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 645 | return ReadArray<char16_t>(parcel, arrayData, allocator); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 648 | binder_status_t AParcel_readByteArray(const AParcel* parcel, void* arrayData, |
Steven Moreland | 9ac9dca | 2018-11-01 10:07:31 -0700 | [diff] [blame] | 649 | AParcel_byteArrayAllocator allocator) { |
Steven Moreland | 71872f8 | 2018-10-29 11:46:56 -0700 | [diff] [blame] | 650 | return ReadArray<int8_t>(parcel, arrayData, allocator); |
Steven Moreland | a884566 | 2018-10-12 11:53:03 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 653 | // @END |