| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 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 | #ifndef ANDROID_PARCEL_H |
| 18 | #define ANDROID_PARCEL_H |
| 19 | |
| Christopher Wiley | 9a5e32f | 2016-01-28 16:56:53 -0800 | [diff] [blame] | 20 | #include <string> |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
| Christopher Wiley | 83e6b98 | 2016-04-19 10:27:00 -0700 | [diff] [blame] | 23 | #include <android-base/unique_fd.h> |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <cutils/native_handle.h> |
| 25 | #include <utils/Errors.h> |
| 26 | #include <utils/RefBase.h> |
| 27 | #include <utils/String16.h> |
| 28 | #include <utils/Vector.h> |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 29 | #include <utils/Flattenable.h> |
| Christopher Ferris | 0170cd0 | 2016-07-18 16:57:34 -0700 | [diff] [blame] | 30 | #include <linux/android/binder.h> |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
| Casey Dahlin | f0c1377 | 2015-10-27 18:33:56 -0700 | [diff] [blame] | 32 | #include <binder/IInterface.h> |
| Christopher Wiley | 97f048d | 2015-11-19 06:49:05 -0800 | [diff] [blame] | 33 | #include <binder/Parcelable.h> |
| Robert Quattlebaum | 6316f5b | 2017-01-04 13:25:14 -0800 | [diff] [blame] | 34 | #include <binder/Map.h> |
| Casey Dahlin | f0c1377 | 2015-10-27 18:33:56 -0700 | [diff] [blame] | 35 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | // --------------------------------------------------------------------------- |
| 37 | namespace android { |
| 38 | |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 39 | template <typename T> class Flattenable; |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 40 | template <typename T> class LightFlattenable; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | class IBinder; |
| Brad Fitzpatrick | 70081a1 | 2010-07-27 09:49:11 -0700 | [diff] [blame] | 42 | class IPCThreadState; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | class ProcessState; |
| 44 | class String8; |
| 45 | class TextOutput; |
| 46 | |
| Robert Quattlebaum | 6316f5b | 2017-01-04 13:25:14 -0800 | [diff] [blame] | 47 | namespace binder { |
| 48 | class Value; |
| 49 | }; |
| 50 | |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 51 | class Parcel { |
| Serban Constantinescu | f683e01 | 2013-11-05 16:53:55 +0000 | [diff] [blame] | 52 | friend class IPCThreadState; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | public: |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 54 | class ReadableBlob; |
| 55 | class WritableBlob; |
| 56 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | Parcel(); |
| 58 | ~Parcel(); |
| 59 | |
| 60 | const uint8_t* data() const; |
| 61 | size_t dataSize() const; |
| 62 | size_t dataAvail() const; |
| 63 | size_t dataPosition() const; |
| 64 | size_t dataCapacity() const; |
| Dianne Hackborn | 8938ed2 | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 65 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | status_t setDataSize(size_t size); |
| 67 | void setDataPosition(size_t pos) const; |
| 68 | status_t setDataCapacity(size_t size); |
| 69 | |
| 70 | status_t setData(const uint8_t* buffer, size_t len); |
| 71 | |
| Andreas Huber | 51faf46 | 2011-04-13 10:21:56 -0700 | [diff] [blame] | 72 | status_t appendFrom(const Parcel *parcel, |
| 73 | size_t start, size_t len); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | |
| Dianne Hackborn | 15feb9b | 2017-04-10 15:34:35 -0700 | [diff] [blame] | 75 | int compareData(const Parcel& other); |
| 76 | |
| Jeff Brown | 13b1604 | 2014-11-11 16:44:25 -0800 | [diff] [blame] | 77 | bool allowFds() const; |
| Dianne Hackborn | 7746cc3 | 2011-10-03 21:09:35 -0700 | [diff] [blame] | 78 | bool pushAllowFds(bool allowFds); |
| 79 | void restoreAllowFds(bool lastValue); |
| Dianne Hackborn | 8938ed2 | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 80 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | bool hasFileDescriptors() const; |
| 82 | |
| Brad Fitzpatrick | 702ea9d | 2010-06-18 13:07:53 -0700 | [diff] [blame] | 83 | // Writes the RPC header. |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | status_t writeInterfaceToken(const String16& interface); |
| Brad Fitzpatrick | a877cd8 | 2010-07-07 16:06:39 -0700 | [diff] [blame] | 85 | |
| Brad Fitzpatrick | 702ea9d | 2010-06-18 13:07:53 -0700 | [diff] [blame] | 86 | // Parses the RPC header, returning true if the interface name |
| 87 | // in the header matches the expected interface from the caller. |
| Brad Fitzpatrick | 70081a1 | 2010-07-27 09:49:11 -0700 | [diff] [blame] | 88 | // |
| 89 | // Additionally, enforceInterface does part of the work of |
| 90 | // propagating the StrictMode policy mask, populating the current |
| 91 | // IPCThreadState, which as an optimization may optionally be |
| 92 | // passed in. |
| Brad Fitzpatrick | a877cd8 | 2010-07-07 16:06:39 -0700 | [diff] [blame] | 93 | bool enforceInterface(const String16& interface, |
| Brad Fitzpatrick | 70081a1 | 2010-07-27 09:49:11 -0700 | [diff] [blame] | 94 | IPCThreadState* threadState = NULL) const; |
| Brad Fitzpatrick | 702ea9d | 2010-06-18 13:07:53 -0700 | [diff] [blame] | 95 | bool checkInterface(IBinder*) const; |
| Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 96 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | void freeData(); |
| 98 | |
| Arve Hjønnevåg | 84e625a | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 99 | private: |
| 100 | const binder_size_t* objects() const; |
| 101 | |
| 102 | public: |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | size_t objectsCount() const; |
| 104 | |
| 105 | status_t errorCheck() const; |
| 106 | void setError(status_t err); |
| 107 | |
| 108 | status_t write(const void* data, size_t len); |
| 109 | void* writeInplace(size_t len); |
| 110 | status_t writeUnpadded(const void* data, size_t len); |
| 111 | status_t writeInt32(int32_t val); |
| Dan Stoza | 41a0f2f | 2014-12-01 10:01:10 -0800 | [diff] [blame] | 112 | status_t writeUint32(uint32_t val); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | status_t writeInt64(int64_t val); |
| Ronghua Wu | 2d13afd | 2015-03-16 11:11:07 -0700 | [diff] [blame] | 114 | status_t writeUint64(uint64_t val); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | status_t writeFloat(float val); |
| 116 | status_t writeDouble(double val); |
| 117 | status_t writeCString(const char* str); |
| 118 | status_t writeString8(const String8& str); |
| 119 | status_t writeString16(const String16& str); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 120 | status_t writeString16(const std::unique_ptr<String16>& str); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | status_t writeString16(const char16_t* str, size_t len); |
| 122 | status_t writeStrongBinder(const sp<IBinder>& val); |
| 123 | status_t writeWeakBinder(const wp<IBinder>& val); |
| Marco Nelissen | 5c0106e | 2013-10-16 10:57:51 -0700 | [diff] [blame] | 124 | status_t writeInt32Array(size_t len, const int32_t *val); |
| Marco Nelissen | f0190bf | 2014-03-13 14:17:40 -0700 | [diff] [blame] | 125 | status_t writeByteArray(size_t len, const uint8_t *val); |
| Casey Dahlin | d6848f5 | 2015-10-15 15:44:59 -0700 | [diff] [blame] | 126 | status_t writeBool(bool val); |
| 127 | status_t writeChar(char16_t val); |
| 128 | status_t writeByte(int8_t val); |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 129 | |
| Christopher Wiley | 9a5e32f | 2016-01-28 16:56:53 -0800 | [diff] [blame] | 130 | // Take a UTF8 encoded string, convert to UTF16, write it to the parcel. |
| 131 | status_t writeUtf8AsUtf16(const std::string& str); |
| 132 | status_t writeUtf8AsUtf16(const std::unique_ptr<std::string>& str); |
| 133 | |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 134 | status_t writeByteVector(const std::unique_ptr<std::vector<int8_t>>& val); |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 135 | status_t writeByteVector(const std::vector<int8_t>& val); |
| Casey Dahlin | 185d344 | 2016-02-09 11:08:35 -0800 | [diff] [blame] | 136 | status_t writeByteVector(const std::unique_ptr<std::vector<uint8_t>>& val); |
| 137 | status_t writeByteVector(const std::vector<uint8_t>& val); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 138 | status_t writeInt32Vector(const std::unique_ptr<std::vector<int32_t>>& val); |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 139 | status_t writeInt32Vector(const std::vector<int32_t>& val); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 140 | status_t writeInt64Vector(const std::unique_ptr<std::vector<int64_t>>& val); |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 141 | status_t writeInt64Vector(const std::vector<int64_t>& val); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 142 | status_t writeFloatVector(const std::unique_ptr<std::vector<float>>& val); |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 143 | status_t writeFloatVector(const std::vector<float>& val); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 144 | status_t writeDoubleVector(const std::unique_ptr<std::vector<double>>& val); |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 145 | status_t writeDoubleVector(const std::vector<double>& val); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 146 | status_t writeBoolVector(const std::unique_ptr<std::vector<bool>>& val); |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 147 | status_t writeBoolVector(const std::vector<bool>& val); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 148 | status_t writeCharVector(const std::unique_ptr<std::vector<char16_t>>& val); |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 149 | status_t writeCharVector(const std::vector<char16_t>& val); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 150 | status_t writeString16Vector( |
| 151 | const std::unique_ptr<std::vector<std::unique_ptr<String16>>>& val); |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 152 | status_t writeString16Vector(const std::vector<String16>& val); |
| Christopher Wiley | 9a5e32f | 2016-01-28 16:56:53 -0800 | [diff] [blame] | 153 | status_t writeUtf8VectorAsUtf16Vector( |
| 154 | const std::unique_ptr<std::vector<std::unique_ptr<std::string>>>& val); |
| 155 | status_t writeUtf8VectorAsUtf16Vector(const std::vector<std::string>& val); |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 156 | |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 157 | status_t writeStrongBinderVector(const std::unique_ptr<std::vector<sp<IBinder>>>& val); |
| Casey Dahlin | eb8e15f | 2015-11-03 13:50:37 -0800 | [diff] [blame] | 158 | status_t writeStrongBinderVector(const std::vector<sp<IBinder>>& val); |
| 159 | |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 160 | template<typename T> |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 161 | status_t writeParcelableVector(const std::unique_ptr<std::vector<std::unique_ptr<T>>>& val); |
| 162 | template<typename T> |
| Janis Danisevskis | 8d74709 | 2016-08-11 13:52:12 +0100 | [diff] [blame] | 163 | status_t writeParcelableVector(const std::shared_ptr<std::vector<std::unique_ptr<T>>>& val); |
| 164 | template<typename T> |
| Christopher Wiley | 97f048d | 2015-11-19 06:49:05 -0800 | [diff] [blame] | 165 | status_t writeParcelableVector(const std::vector<T>& val); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 166 | |
| 167 | template<typename T> |
| 168 | status_t writeNullableParcelable(const std::unique_ptr<T>& parcelable); |
| 169 | |
| Christopher Wiley | 97f048d | 2015-11-19 06:49:05 -0800 | [diff] [blame] | 170 | status_t writeParcelable(const Parcelable& parcelable); |
| 171 | |
| Robert Quattlebaum | 6316f5b | 2017-01-04 13:25:14 -0800 | [diff] [blame] | 172 | status_t writeValue(const binder::Value& value); |
| 173 | |
| Christopher Wiley | 97f048d | 2015-11-19 06:49:05 -0800 | [diff] [blame] | 174 | template<typename T> |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 175 | status_t write(const Flattenable<T>& val); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 177 | template<typename T> |
| 178 | status_t write(const LightFlattenable<T>& val); |
| 179 | |
| Christopher Wiley | 31c1beb | 2016-08-19 11:43:54 -0700 | [diff] [blame] | 180 | template<typename T> |
| 181 | status_t writeVectorSize(const std::vector<T>& val); |
| 182 | template<typename T> |
| 183 | status_t writeVectorSize(const std::unique_ptr<std::vector<T>>& val); |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 184 | |
| Robert Quattlebaum | 6316f5b | 2017-01-04 13:25:14 -0800 | [diff] [blame] | 185 | status_t writeMap(const binder::Map& map); |
| 186 | status_t writeNullableMap(const std::unique_ptr<binder::Map>& map); |
| 187 | |
| Mathias Agopian | a47f02a | 2009-05-21 16:29:38 -0700 | [diff] [blame] | 188 | // Place a native_handle into the parcel (the native_handle's file- |
| 189 | // descriptors are dup'ed, so it is safe to delete the native_handle |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 190 | // when this function returns). |
| Mathias Agopian | a47f02a | 2009-05-21 16:29:38 -0700 | [diff] [blame] | 191 | // Doesn't take ownership of the native_handle. |
| 192 | status_t writeNativeHandle(const native_handle* handle); |
| Dianne Hackborn | 1941a40 | 2016-08-29 12:30:43 -0700 | [diff] [blame] | 193 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | // Place a file descriptor into the parcel. The given fd must remain |
| 195 | // valid for the lifetime of the parcel. |
| Jeff Brown | 93ff1f9 | 2011-11-04 19:01:44 -0700 | [diff] [blame] | 196 | // The Parcel does not take ownership of the given fd unless you ask it to. |
| 197 | status_t writeFileDescriptor(int fd, bool takeOwnership = false); |
| Dianne Hackborn | 1941a40 | 2016-08-29 12:30:43 -0700 | [diff] [blame] | 198 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | // Place a file descriptor into the parcel. A dup of the fd is made, which |
| 200 | // will be closed once the parcel is destroyed. |
| 201 | status_t writeDupFileDescriptor(int fd); |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 202 | |
| Dianne Hackborn | 1941a40 | 2016-08-29 12:30:43 -0700 | [diff] [blame] | 203 | // Place a Java "parcel file descriptor" into the parcel. The given fd must remain |
| 204 | // valid for the lifetime of the parcel. |
| 205 | // The Parcel does not take ownership of the given fd unless you ask it to. |
| 206 | status_t writeParcelFileDescriptor(int fd, bool takeOwnership = false); |
| 207 | |
| Casey Dahlin | 06673e3 | 2015-11-23 13:24:23 -0800 | [diff] [blame] | 208 | // Place a file descriptor into the parcel. This will not affect the |
| 209 | // semantics of the smart file descriptor. A new descriptor will be |
| 210 | // created, and will be closed when the parcel is destroyed. |
| 211 | status_t writeUniqueFileDescriptor( |
| Christopher Wiley | 2cf1995 | 2016-04-11 11:09:37 -0700 | [diff] [blame] | 212 | const base::unique_fd& fd); |
| Casey Dahlin | 06673e3 | 2015-11-23 13:24:23 -0800 | [diff] [blame] | 213 | |
| 214 | // Place a vector of file desciptors into the parcel. Each descriptor is |
| 215 | // dup'd as in writeDupFileDescriptor |
| 216 | status_t writeUniqueFileDescriptorVector( |
| Christopher Wiley | 2cf1995 | 2016-04-11 11:09:37 -0700 | [diff] [blame] | 217 | const std::unique_ptr<std::vector<base::unique_fd>>& val); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 218 | status_t writeUniqueFileDescriptorVector( |
| Christopher Wiley | 2cf1995 | 2016-04-11 11:09:37 -0700 | [diff] [blame] | 219 | const std::vector<base::unique_fd>& val); |
| Casey Dahlin | 06673e3 | 2015-11-23 13:24:23 -0800 | [diff] [blame] | 220 | |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 221 | // Writes a blob to the parcel. |
| 222 | // If the blob is small, then it is stored in-place, otherwise it is |
| Jeff Brown | 13b1604 | 2014-11-11 16:44:25 -0800 | [diff] [blame] | 223 | // transferred by way of an anonymous shared memory region. Prefer sending |
| 224 | // immutable blobs if possible since they may be subsequently transferred between |
| 225 | // processes without further copying whereas mutable blobs always need to be copied. |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 226 | // The caller should call release() on the blob after writing its contents. |
| Jeff Brown | 13b1604 | 2014-11-11 16:44:25 -0800 | [diff] [blame] | 227 | status_t writeBlob(size_t len, bool mutableCopy, WritableBlob* outBlob); |
| 228 | |
| 229 | // Write an existing immutable blob file descriptor to the parcel. |
| 230 | // This allows the client to send the same blob to multiple processes |
| 231 | // as long as it keeps a dup of the blob file descriptor handy for later. |
| 232 | status_t writeDupImmutableBlobFileDescriptor(int fd); |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 233 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | status_t writeObject(const flat_binder_object& val, bool nullMetaData); |
| 235 | |
| Brad Fitzpatrick | 837a0d0 | 2010-07-13 15:33:35 -0700 | [diff] [blame] | 236 | // Like Parcel.java's writeNoException(). Just writes a zero int32. |
| 237 | // Currently the native implementation doesn't do any of the StrictMode |
| 238 | // stack gathering and serialization that the Java implementation does. |
| 239 | status_t writeNoException(); |
| 240 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | void remove(size_t start, size_t amt); |
| 242 | |
| 243 | status_t read(void* outData, size_t len) const; |
| 244 | const void* readInplace(size_t len) const; |
| 245 | int32_t readInt32() const; |
| 246 | status_t readInt32(int32_t *pArg) const; |
| Dan Stoza | 41a0f2f | 2014-12-01 10:01:10 -0800 | [diff] [blame] | 247 | uint32_t readUint32() const; |
| 248 | status_t readUint32(uint32_t *pArg) const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | int64_t readInt64() const; |
| 250 | status_t readInt64(int64_t *pArg) const; |
| Ronghua Wu | 2d13afd | 2015-03-16 11:11:07 -0700 | [diff] [blame] | 251 | uint64_t readUint64() const; |
| 252 | status_t readUint64(uint64_t *pArg) const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | float readFloat() const; |
| 254 | status_t readFloat(float *pArg) const; |
| 255 | double readDouble() const; |
| 256 | status_t readDouble(double *pArg) const; |
| Andreas Huber | 84a6d04 | 2009-08-17 13:33:27 -0700 | [diff] [blame] | 257 | intptr_t readIntPtr() const; |
| 258 | status_t readIntPtr(intptr_t *pArg) const; |
| Casey Dahlin | d6848f5 | 2015-10-15 15:44:59 -0700 | [diff] [blame] | 259 | bool readBool() const; |
| 260 | status_t readBool(bool *pArg) const; |
| 261 | char16_t readChar() const; |
| 262 | status_t readChar(char16_t *pArg) const; |
| 263 | int8_t readByte() const; |
| 264 | status_t readByte(int8_t *pArg) const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | |
| Christopher Wiley | 9a5e32f | 2016-01-28 16:56:53 -0800 | [diff] [blame] | 266 | // Read a UTF16 encoded string, convert to UTF8 |
| 267 | status_t readUtf8FromUtf16(std::string* str) const; |
| 268 | status_t readUtf8FromUtf16(std::unique_ptr<std::string>* str) const; |
| 269 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | const char* readCString() const; |
| 271 | String8 readString8() const; |
| Roshan Pius | 87b64d2 | 2016-07-18 12:51:02 -0700 | [diff] [blame] | 272 | status_t readString8(String8* pArg) const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | String16 readString16() const; |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 274 | status_t readString16(String16* pArg) const; |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 275 | status_t readString16(std::unique_ptr<String16>* pArg) const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | const char16_t* readString16Inplace(size_t* outLen) const; |
| 277 | sp<IBinder> readStrongBinder() const; |
| Casey Dahlin | f0c1377 | 2015-10-27 18:33:56 -0700 | [diff] [blame] | 278 | status_t readStrongBinder(sp<IBinder>* val) const; |
| Christopher Wiley | 35d77ca | 2016-03-08 10:49:51 -0800 | [diff] [blame] | 279 | status_t readNullableStrongBinder(sp<IBinder>* val) const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | wp<IBinder> readWeakBinder() const; |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 281 | |
| Casey Dahlin | f0c1377 | 2015-10-27 18:33:56 -0700 | [diff] [blame] | 282 | template<typename T> |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 283 | status_t readParcelableVector( |
| 284 | std::unique_ptr<std::vector<std::unique_ptr<T>>>* val) const; |
| 285 | template<typename T> |
| Christopher Wiley | 97f048d | 2015-11-19 06:49:05 -0800 | [diff] [blame] | 286 | status_t readParcelableVector(std::vector<T>* val) const; |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 287 | |
| Christopher Wiley | 97f048d | 2015-11-19 06:49:05 -0800 | [diff] [blame] | 288 | status_t readParcelable(Parcelable* parcelable) const; |
| 289 | |
| 290 | template<typename T> |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 291 | status_t readParcelable(std::unique_ptr<T>* parcelable) const; |
| 292 | |
| Robert Quattlebaum | 6316f5b | 2017-01-04 13:25:14 -0800 | [diff] [blame] | 293 | status_t readValue(binder::Value* value) const; |
| 294 | |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 295 | template<typename T> |
| Casey Dahlin | eb8e15f | 2015-11-03 13:50:37 -0800 | [diff] [blame] | 296 | status_t readStrongBinder(sp<T>* val) const; |
| 297 | |
| Christopher Wiley | 35d77ca | 2016-03-08 10:49:51 -0800 | [diff] [blame] | 298 | template<typename T> |
| 299 | status_t readNullableStrongBinder(sp<T>* val) const; |
| 300 | |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 301 | status_t readStrongBinderVector(std::unique_ptr<std::vector<sp<IBinder>>>* val) const; |
| Casey Dahlin | eb8e15f | 2015-11-03 13:50:37 -0800 | [diff] [blame] | 302 | status_t readStrongBinderVector(std::vector<sp<IBinder>>* val) const; |
| Casey Dahlin | f0c1377 | 2015-10-27 18:33:56 -0700 | [diff] [blame] | 303 | |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 304 | status_t readByteVector(std::unique_ptr<std::vector<int8_t>>* val) const; |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 305 | status_t readByteVector(std::vector<int8_t>* val) const; |
| Casey Dahlin | 185d344 | 2016-02-09 11:08:35 -0800 | [diff] [blame] | 306 | status_t readByteVector(std::unique_ptr<std::vector<uint8_t>>* val) const; |
| 307 | status_t readByteVector(std::vector<uint8_t>* val) const; |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 308 | status_t readInt32Vector(std::unique_ptr<std::vector<int32_t>>* val) const; |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 309 | status_t readInt32Vector(std::vector<int32_t>* val) const; |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 310 | status_t readInt64Vector(std::unique_ptr<std::vector<int64_t>>* val) const; |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 311 | status_t readInt64Vector(std::vector<int64_t>* val) const; |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 312 | status_t readFloatVector(std::unique_ptr<std::vector<float>>* val) const; |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 313 | status_t readFloatVector(std::vector<float>* val) const; |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 314 | status_t readDoubleVector(std::unique_ptr<std::vector<double>>* val) const; |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 315 | status_t readDoubleVector(std::vector<double>* val) const; |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 316 | status_t readBoolVector(std::unique_ptr<std::vector<bool>>* val) const; |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 317 | status_t readBoolVector(std::vector<bool>* val) const; |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 318 | status_t readCharVector(std::unique_ptr<std::vector<char16_t>>* val) const; |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 319 | status_t readCharVector(std::vector<char16_t>* val) const; |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 320 | status_t readString16Vector( |
| 321 | std::unique_ptr<std::vector<std::unique_ptr<String16>>>* val) const; |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 322 | status_t readString16Vector(std::vector<String16>* val) const; |
| Christopher Wiley | 9a5e32f | 2016-01-28 16:56:53 -0800 | [diff] [blame] | 323 | status_t readUtf8VectorFromUtf16Vector( |
| 324 | std::unique_ptr<std::vector<std::unique_ptr<std::string>>>* val) const; |
| 325 | status_t readUtf8VectorFromUtf16Vector(std::vector<std::string>* val) const; |
| Casey Dahlin | 451ff58 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 326 | |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 327 | template<typename T> |
| 328 | status_t read(Flattenable<T>& val) const; |
| Brad Fitzpatrick | 837a0d0 | 2010-07-13 15:33:35 -0700 | [diff] [blame] | 329 | |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 330 | template<typename T> |
| 331 | status_t read(LightFlattenable<T>& val) const; |
| 332 | |
| Christopher Wiley | 31c1beb | 2016-08-19 11:43:54 -0700 | [diff] [blame] | 333 | template<typename T> |
| 334 | status_t resizeOutVector(std::vector<T>* val) const; |
| 335 | template<typename T> |
| 336 | status_t resizeOutVector(std::unique_ptr<std::vector<T>>* val) const; |
| 337 | |
| Robert Quattlebaum | 6316f5b | 2017-01-04 13:25:14 -0800 | [diff] [blame] | 338 | status_t readMap(binder::Map* map)const; |
| 339 | status_t readNullableMap(std::unique_ptr<binder::Map>* map) const; |
| 340 | |
| Brad Fitzpatrick | 837a0d0 | 2010-07-13 15:33:35 -0700 | [diff] [blame] | 341 | // Like Parcel.java's readExceptionCode(). Reads the first int32 |
| 342 | // off of a Parcel's header, returning 0 or the negative error |
| 343 | // code on exceptions, but also deals with skipping over rich |
| 344 | // response headers. Callers should use this to read & parse the |
| 345 | // response headers rather than doing it by hand. |
| 346 | int32_t readExceptionCode() const; |
| 347 | |
| Mathias Agopian | a47f02a | 2009-05-21 16:29:38 -0700 | [diff] [blame] | 348 | // Retrieve native_handle from the parcel. This returns a copy of the |
| 349 | // parcel's native_handle (the caller takes ownership). The caller |
| 350 | // must free the native_handle with native_handle_close() and |
| 351 | // native_handle_delete(). |
| 352 | native_handle* readNativeHandle() const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | |
| 354 | |
| 355 | // Retrieve a file descriptor from the parcel. This returns the raw fd |
| 356 | // in the parcel, which you do not own -- use dup() to get your own copy. |
| 357 | int readFileDescriptor() const; |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 358 | |
| Dianne Hackborn | 1941a40 | 2016-08-29 12:30:43 -0700 | [diff] [blame] | 359 | // Retrieve a Java "parcel file descriptor" from the parcel. This returns the raw fd |
| 360 | // in the parcel, which you do not own -- use dup() to get your own copy. |
| 361 | int readParcelFileDescriptor() const; |
| 362 | |
| Casey Dahlin | 06673e3 | 2015-11-23 13:24:23 -0800 | [diff] [blame] | 363 | // Retrieve a smart file descriptor from the parcel. |
| 364 | status_t readUniqueFileDescriptor( |
| Christopher Wiley | 2cf1995 | 2016-04-11 11:09:37 -0700 | [diff] [blame] | 365 | base::unique_fd* val) const; |
| Casey Dahlin | 06673e3 | 2015-11-23 13:24:23 -0800 | [diff] [blame] | 366 | |
| 367 | |
| 368 | // Retrieve a vector of smart file descriptors from the parcel. |
| 369 | status_t readUniqueFileDescriptorVector( |
| Christopher Wiley | 2cf1995 | 2016-04-11 11:09:37 -0700 | [diff] [blame] | 370 | std::unique_ptr<std::vector<base::unique_fd>>* val) const; |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 371 | status_t readUniqueFileDescriptorVector( |
| Christopher Wiley | 2cf1995 | 2016-04-11 11:09:37 -0700 | [diff] [blame] | 372 | std::vector<base::unique_fd>* val) const; |
| Casey Dahlin | 06673e3 | 2015-11-23 13:24:23 -0800 | [diff] [blame] | 373 | |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 374 | // Reads a blob from the parcel. |
| 375 | // The caller should call release() on the blob after reading its contents. |
| 376 | status_t readBlob(size_t len, ReadableBlob* outBlob) const; |
| 377 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | const flat_binder_object* readObject(bool nullMetaData) const; |
| 379 | |
| 380 | // Explicitly close all file descriptors in the parcel. |
| 381 | void closeFileDescriptors(); |
| Dianne Hackborn | 7e790af | 2014-11-11 12:22:53 -0800 | [diff] [blame] | 382 | |
| 383 | // Debugging: get metrics on current allocations. |
| 384 | static size_t getGlobalAllocSize(); |
| 385 | static size_t getGlobalAllocCount(); |
| 386 | |
| Arve Hjønnevåg | 84e625a | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 387 | private: |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | typedef void (*release_func)(Parcel* parcel, |
| 389 | const uint8_t* data, size_t dataSize, |
| Arve Hjønnevåg | 84e625a | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 390 | const binder_size_t* objects, size_t objectsSize, |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | void* cookie); |
| 392 | |
| Arve Hjønnevåg | 84e625a | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 393 | uintptr_t ipcData() const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | size_t ipcDataSize() const; |
| Arve Hjønnevåg | 84e625a | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 395 | uintptr_t ipcObjects() const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | size_t ipcObjectsCount() const; |
| 397 | void ipcSetDataReference(const uint8_t* data, size_t dataSize, |
| Arve Hjønnevåg | 84e625a | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 398 | const binder_size_t* objects, size_t objectsCount, |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | release_func relFunc, void* relCookie); |
| 400 | |
| Arve Hjønnevåg | 84e625a | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 401 | public: |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | void print(TextOutput& to, uint32_t flags = 0) const; |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 403 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | private: |
| 405 | Parcel(const Parcel& o); |
| 406 | Parcel& operator=(const Parcel& o); |
| 407 | |
| 408 | status_t finishWrite(size_t len); |
| 409 | void releaseObjects(); |
| 410 | void acquireObjects(); |
| 411 | status_t growData(size_t len); |
| 412 | status_t restartWrite(size_t desired); |
| 413 | status_t continueWrite(size_t desired); |
| Serban Constantinescu | f683e01 | 2013-11-05 16:53:55 +0000 | [diff] [blame] | 414 | status_t writePointer(uintptr_t val); |
| 415 | status_t readPointer(uintptr_t *pArg) const; |
| 416 | uintptr_t readPointer() const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | void freeDataNoInit(); |
| 418 | void initState(); |
| 419 | void scanForFds() const; |
| 420 | |
| Andreas Huber | 84a6d04 | 2009-08-17 13:33:27 -0700 | [diff] [blame] | 421 | template<class T> |
| 422 | status_t readAligned(T *pArg) const; |
| 423 | |
| 424 | template<class T> T readAligned() const; |
| 425 | |
| 426 | template<class T> |
| 427 | status_t writeAligned(T val); |
| 428 | |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 429 | status_t writeRawNullableParcelable(const Parcelable* |
| 430 | parcelable); |
| 431 | |
| Christopher Wiley | 03d1eb6 | 2015-11-19 06:42:40 -0800 | [diff] [blame] | 432 | template<typename T, typename U> |
| 433 | status_t unsafeReadTypedVector(std::vector<T>* val, |
| 434 | status_t(Parcel::*read_func)(U*) const) const; |
| 435 | template<typename T> |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 436 | status_t readNullableTypedVector(std::unique_ptr<std::vector<T>>* val, |
| 437 | status_t(Parcel::*read_func)(T*) const) const; |
| 438 | template<typename T> |
| Christopher Wiley | 03d1eb6 | 2015-11-19 06:42:40 -0800 | [diff] [blame] | 439 | status_t readTypedVector(std::vector<T>* val, |
| 440 | status_t(Parcel::*read_func)(T*) const) const; |
| 441 | template<typename T, typename U> |
| 442 | status_t unsafeWriteTypedVector(const std::vector<T>& val, |
| 443 | status_t(Parcel::*write_func)(U)); |
| 444 | template<typename T> |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 445 | status_t writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val, |
| 446 | status_t(Parcel::*write_func)(const T&)); |
| 447 | template<typename T> |
| 448 | status_t writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val, |
| 449 | status_t(Parcel::*write_func)(T)); |
| 450 | template<typename T> |
| Christopher Wiley | 03d1eb6 | 2015-11-19 06:42:40 -0800 | [diff] [blame] | 451 | status_t writeTypedVector(const std::vector<T>& val, |
| 452 | status_t(Parcel::*write_func)(const T&)); |
| 453 | template<typename T> |
| 454 | status_t writeTypedVector(const std::vector<T>& val, |
| 455 | status_t(Parcel::*write_func)(T)); |
| 456 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | status_t mError; |
| 458 | uint8_t* mData; |
| 459 | size_t mDataSize; |
| 460 | size_t mDataCapacity; |
| 461 | mutable size_t mDataPos; |
| Arve Hjønnevåg | 84e625a | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 462 | binder_size_t* mObjects; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | size_t mObjectsSize; |
| 464 | size_t mObjectsCapacity; |
| 465 | mutable size_t mNextObjectHint; |
| 466 | |
| 467 | mutable bool mFdsKnown; |
| 468 | mutable bool mHasFds; |
| Dianne Hackborn | 8938ed2 | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 469 | bool mAllowFds; |
| Christopher Tate | e4e0ae8 | 2016-03-24 16:03:44 -0700 | [diff] [blame] | 470 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | release_func mOwner; |
| 472 | void* mOwnerCookie; |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 473 | |
| 474 | class Blob { |
| 475 | public: |
| 476 | Blob(); |
| 477 | ~Blob(); |
| 478 | |
| Jeff Brown | 13b1604 | 2014-11-11 16:44:25 -0800 | [diff] [blame] | 479 | void clear(); |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 480 | void release(); |
| 481 | inline size_t size() const { return mSize; } |
| Colin Cross | 17576de | 2016-09-26 13:07:06 -0700 | [diff] [blame] | 482 | inline int fd() const { return mFd; } |
| Jeff Brown | 13b1604 | 2014-11-11 16:44:25 -0800 | [diff] [blame] | 483 | inline bool isMutable() const { return mMutable; } |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 484 | |
| 485 | protected: |
| Jeff Brown | 13b1604 | 2014-11-11 16:44:25 -0800 | [diff] [blame] | 486 | void init(int fd, void* data, size_t size, bool isMutable); |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 487 | |
| Jeff Brown | 13b1604 | 2014-11-11 16:44:25 -0800 | [diff] [blame] | 488 | int mFd; // owned by parcel so not closed when released |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 489 | void* mData; |
| 490 | size_t mSize; |
| Jeff Brown | 13b1604 | 2014-11-11 16:44:25 -0800 | [diff] [blame] | 491 | bool mMutable; |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 492 | }; |
| 493 | |
| Colin Cross | 97b64db | 2016-09-26 13:48:02 -0700 | [diff] [blame] | 494 | #if defined(__clang__) |
| 495 | #pragma clang diagnostic push |
| 496 | #pragma clang diagnostic ignored "-Wweak-vtables" |
| 497 | #endif |
| 498 | |
| Fabien Sanglard | c38992f | 2016-10-27 19:05:29 -0700 | [diff] [blame] | 499 | // FlattenableHelperInterface and FlattenableHelper avoid generating a vtable entry in objects |
| 500 | // following Flattenable template/protocol. |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 501 | class FlattenableHelperInterface { |
| 502 | protected: |
| 503 | ~FlattenableHelperInterface() { } |
| 504 | public: |
| 505 | virtual size_t getFlattenedSize() const = 0; |
| 506 | virtual size_t getFdCount() const = 0; |
| 507 | virtual status_t flatten(void* buffer, size_t size, int* fds, size_t count) const = 0; |
| 508 | virtual status_t unflatten(void const* buffer, size_t size, int const* fds, size_t count) = 0; |
| 509 | }; |
| 510 | |
| Colin Cross | 97b64db | 2016-09-26 13:48:02 -0700 | [diff] [blame] | 511 | #if defined(__clang__) |
| 512 | #pragma clang diagnostic pop |
| 513 | #endif |
| 514 | |
| Fabien Sanglard | c38992f | 2016-10-27 19:05:29 -0700 | [diff] [blame] | 515 | // Concrete implementation of FlattenableHelperInterface that delegates virtual calls to the |
| 516 | // specified class T implementing the Flattenable protocol. It "virtualizes" a compile-time |
| 517 | // protocol. |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 518 | template<typename T> |
| 519 | class FlattenableHelper : public FlattenableHelperInterface { |
| 520 | friend class Parcel; |
| 521 | const Flattenable<T>& val; |
| Colin Cross | 382ecd3 | 2016-09-26 13:33:59 -0700 | [diff] [blame] | 522 | explicit FlattenableHelper(const Flattenable<T>& _val) : val(_val) { } |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 523 | |
| Colin Cross | 97b64db | 2016-09-26 13:48:02 -0700 | [diff] [blame] | 524 | protected: |
| 525 | ~FlattenableHelper() = default; |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 526 | public: |
| 527 | virtual size_t getFlattenedSize() const { |
| 528 | return val.getFlattenedSize(); |
| 529 | } |
| 530 | virtual size_t getFdCount() const { |
| 531 | return val.getFdCount(); |
| 532 | } |
| 533 | virtual status_t flatten(void* buffer, size_t size, int* fds, size_t count) const { |
| 534 | return val.flatten(buffer, size, fds, count); |
| 535 | } |
| 536 | virtual status_t unflatten(void const* buffer, size_t size, int const* fds, size_t count) { |
| 537 | return const_cast<Flattenable<T>&>(val).unflatten(buffer, size, fds, count); |
| 538 | } |
| 539 | }; |
| 540 | status_t write(const FlattenableHelperInterface& val); |
| 541 | status_t read(FlattenableHelperInterface& val) const; |
| 542 | |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 543 | public: |
| 544 | class ReadableBlob : public Blob { |
| 545 | friend class Parcel; |
| 546 | public: |
| 547 | inline const void* data() const { return mData; } |
| Jeff Brown | 13b1604 | 2014-11-11 16:44:25 -0800 | [diff] [blame] | 548 | inline void* mutableData() { return isMutable() ? mData : NULL; } |
| Jeff Brown | 5707dbf | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 549 | }; |
| 550 | |
| 551 | class WritableBlob : public Blob { |
| 552 | friend class Parcel; |
| 553 | public: |
| 554 | inline void* data() { return mData; } |
| 555 | }; |
| Dan Sandler | aa5c234 | 2015-04-10 10:08:45 -0400 | [diff] [blame] | 556 | |
| 557 | private: |
| Adrian Roos | cbf3726 | 2015-10-22 16:12:53 -0700 | [diff] [blame] | 558 | size_t mOpenAshmemSize; |
| Dan Sandler | aa5c234 | 2015-04-10 10:08:45 -0400 | [diff] [blame] | 559 | |
| 560 | public: |
| Adrian Roos | 6bb3114 | 2015-10-22 16:46:12 -0700 | [diff] [blame] | 561 | // TODO: Remove once ABI can be changed. |
| Dan Sandler | aa5c234 | 2015-04-10 10:08:45 -0400 | [diff] [blame] | 562 | size_t getBlobAshmemSize() const; |
| Adrian Roos | cbf3726 | 2015-10-22 16:12:53 -0700 | [diff] [blame] | 563 | size_t getOpenAshmemSize() const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | }; |
| 565 | |
| 566 | // --------------------------------------------------------------------------- |
| 567 | |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 568 | template<typename T> |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 569 | status_t Parcel::write(const Flattenable<T>& val) { |
| 570 | const FlattenableHelper<T> helper(val); |
| 571 | return write(helper); |
| 572 | } |
| 573 | |
| 574 | template<typename T> |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 575 | status_t Parcel::write(const LightFlattenable<T>& val) { |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 576 | size_t size(val.getFlattenedSize()); |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 577 | if (!val.isFixedSize()) { |
| Colin Cross | 4c62b4f | 2016-09-27 13:58:30 -0700 | [diff] [blame] | 578 | if (size > INT32_MAX) { |
| 579 | return BAD_VALUE; |
| 580 | } |
| 581 | status_t err = writeInt32(static_cast<int32_t>(size)); |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 582 | if (err != NO_ERROR) { |
| 583 | return err; |
| 584 | } |
| 585 | } |
| Mathias Agopian | 2098517 | 2012-08-31 14:25:22 -0700 | [diff] [blame] | 586 | if (size) { |
| 587 | void* buffer = writeInplace(size); |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 588 | if (buffer == NULL) |
| 589 | return NO_MEMORY; |
| 590 | return val.flatten(buffer, size); |
| Mathias Agopian | 2098517 | 2012-08-31 14:25:22 -0700 | [diff] [blame] | 591 | } |
| 592 | return NO_ERROR; |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | template<typename T> |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 596 | status_t Parcel::read(Flattenable<T>& val) const { |
| 597 | FlattenableHelper<T> helper(val); |
| 598 | return read(helper); |
| 599 | } |
| 600 | |
| 601 | template<typename T> |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 602 | status_t Parcel::read(LightFlattenable<T>& val) const { |
| 603 | size_t size; |
| 604 | if (val.isFixedSize()) { |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 605 | size = val.getFlattenedSize(); |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 606 | } else { |
| 607 | int32_t s; |
| 608 | status_t err = readInt32(&s); |
| 609 | if (err != NO_ERROR) { |
| 610 | return err; |
| 611 | } |
| Colin Cross | 4c62b4f | 2016-09-27 13:58:30 -0700 | [diff] [blame] | 612 | size = static_cast<size_t>(s); |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 613 | } |
| Mathias Agopian | 2098517 | 2012-08-31 14:25:22 -0700 | [diff] [blame] | 614 | if (size) { |
| 615 | void const* buffer = readInplace(size); |
| 616 | return buffer == NULL ? NO_MEMORY : |
| 617 | val.unflatten(buffer, size); |
| 618 | } |
| 619 | return NO_ERROR; |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| Casey Dahlin | f0c1377 | 2015-10-27 18:33:56 -0700 | [diff] [blame] | 622 | template<typename T> |
| Christopher Wiley | 31c1beb | 2016-08-19 11:43:54 -0700 | [diff] [blame] | 623 | status_t Parcel::writeVectorSize(const std::vector<T>& val) { |
| 624 | if (val.size() > INT32_MAX) { |
| 625 | return BAD_VALUE; |
| 626 | } |
| Colin Cross | 4c62b4f | 2016-09-27 13:58:30 -0700 | [diff] [blame] | 627 | return writeInt32(static_cast<int32_t>(val.size())); |
| Christopher Wiley | 31c1beb | 2016-08-19 11:43:54 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | template<typename T> |
| 631 | status_t Parcel::writeVectorSize(const std::unique_ptr<std::vector<T>>& val) { |
| 632 | if (!val) { |
| 633 | return writeInt32(-1); |
| 634 | } |
| 635 | |
| 636 | return writeVectorSize(*val); |
| 637 | } |
| 638 | |
| 639 | template<typename T> |
| 640 | status_t Parcel::resizeOutVector(std::vector<T>* val) const { |
| 641 | int32_t size; |
| 642 | status_t err = readInt32(&size); |
| 643 | if (err != NO_ERROR) { |
| 644 | return err; |
| 645 | } |
| 646 | |
| 647 | if (size < 0) { |
| 648 | return UNEXPECTED_NULL; |
| 649 | } |
| 650 | val->resize(size_t(size)); |
| 651 | return OK; |
| 652 | } |
| 653 | |
| 654 | template<typename T> |
| 655 | status_t Parcel::resizeOutVector(std::unique_ptr<std::vector<T>>* val) const { |
| 656 | int32_t size; |
| 657 | status_t err = readInt32(&size); |
| 658 | if (err != NO_ERROR) { |
| 659 | return err; |
| 660 | } |
| 661 | |
| 662 | val->reset(); |
| 663 | if (size >= 0) { |
| 664 | val->reset(new std::vector<T>(size_t(size))); |
| 665 | } |
| 666 | |
| 667 | return OK; |
| 668 | } |
| 669 | |
| 670 | template<typename T> |
| Casey Dahlin | f0c1377 | 2015-10-27 18:33:56 -0700 | [diff] [blame] | 671 | status_t Parcel::readStrongBinder(sp<T>* val) const { |
| 672 | sp<IBinder> tmp; |
| 673 | status_t ret = readStrongBinder(&tmp); |
| 674 | |
| 675 | if (ret == OK) { |
| 676 | *val = interface_cast<T>(tmp); |
| 677 | |
| 678 | if (val->get() == nullptr) { |
| 679 | return UNKNOWN_ERROR; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | return ret; |
| 684 | } |
| 685 | |
| Christopher Wiley | 35d77ca | 2016-03-08 10:49:51 -0800 | [diff] [blame] | 686 | template<typename T> |
| 687 | status_t Parcel::readNullableStrongBinder(sp<T>* val) const { |
| 688 | sp<IBinder> tmp; |
| 689 | status_t ret = readNullableStrongBinder(&tmp); |
| 690 | |
| 691 | if (ret == OK) { |
| 692 | *val = interface_cast<T>(tmp); |
| 693 | |
| Christopher Wiley | 447b00f | 2016-07-19 09:23:25 -0700 | [diff] [blame] | 694 | if (val->get() == nullptr && tmp.get() != nullptr) { |
| 695 | ret = UNKNOWN_ERROR; |
| Christopher Wiley | 35d77ca | 2016-03-08 10:49:51 -0800 | [diff] [blame] | 696 | } |
| 697 | } |
| Christopher Wiley | 447b00f | 2016-07-19 09:23:25 -0700 | [diff] [blame] | 698 | |
| 699 | return ret; |
| Christopher Wiley | 35d77ca | 2016-03-08 10:49:51 -0800 | [diff] [blame] | 700 | } |
| 701 | |
| Christopher Wiley | 03d1eb6 | 2015-11-19 06:42:40 -0800 | [diff] [blame] | 702 | template<typename T, typename U> |
| 703 | status_t Parcel::unsafeReadTypedVector( |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 704 | std::vector<T>* val, |
| 705 | status_t(Parcel::*read_func)(U*) const) const { |
| Christopher Wiley | 03d1eb6 | 2015-11-19 06:42:40 -0800 | [diff] [blame] | 706 | int32_t size; |
| 707 | status_t status = this->readInt32(&size); |
| 708 | |
| 709 | if (status != OK) { |
| 710 | return status; |
| 711 | } |
| 712 | |
| 713 | if (size < 0) { |
| 714 | return UNEXPECTED_NULL; |
| 715 | } |
| 716 | |
| Stephen Hines | 803ed29 | 2016-11-16 11:34:09 -0800 | [diff] [blame] | 717 | if (val->max_size() < static_cast<size_t>(size)) { |
| Casey Dahlin | 65a8f07 | 2016-10-26 17:18:25 -0700 | [diff] [blame] | 718 | return NO_MEMORY; |
| 719 | } |
| 720 | |
| Colin Cross | 4c62b4f | 2016-09-27 13:58:30 -0700 | [diff] [blame] | 721 | val->resize(static_cast<size_t>(size)); |
| Christopher Wiley | 03d1eb6 | 2015-11-19 06:42:40 -0800 | [diff] [blame] | 722 | |
| Stephen Hines | 803ed29 | 2016-11-16 11:34:09 -0800 | [diff] [blame] | 723 | if (val->size() < static_cast<size_t>(size)) { |
| Casey Dahlin | 65a8f07 | 2016-10-26 17:18:25 -0700 | [diff] [blame] | 724 | return NO_MEMORY; |
| 725 | } |
| 726 | |
| Christopher Wiley | 03d1eb6 | 2015-11-19 06:42:40 -0800 | [diff] [blame] | 727 | for (auto& v: *val) { |
| 728 | status = (this->*read_func)(&v); |
| 729 | |
| 730 | if (status != OK) { |
| 731 | return status; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | return OK; |
| 736 | } |
| 737 | |
| 738 | template<typename T> |
| 739 | status_t Parcel::readTypedVector(std::vector<T>* val, |
| 740 | status_t(Parcel::*read_func)(T*) const) const { |
| 741 | return unsafeReadTypedVector(val, read_func); |
| 742 | } |
| 743 | |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 744 | template<typename T> |
| 745 | status_t Parcel::readNullableTypedVector(std::unique_ptr<std::vector<T>>* val, |
| 746 | status_t(Parcel::*read_func)(T*) const) const { |
| Colin Cross | 4c62b4f | 2016-09-27 13:58:30 -0700 | [diff] [blame] | 747 | const size_t start = dataPosition(); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 748 | int32_t size; |
| 749 | status_t status = readInt32(&size); |
| 750 | val->reset(); |
| 751 | |
| 752 | if (status != OK || size < 0) { |
| 753 | return status; |
| 754 | } |
| 755 | |
| 756 | setDataPosition(start); |
| 757 | val->reset(new std::vector<T>()); |
| 758 | |
| 759 | status = unsafeReadTypedVector(val->get(), read_func); |
| 760 | |
| 761 | if (status != OK) { |
| 762 | val->reset(); |
| 763 | } |
| 764 | |
| 765 | return status; |
| 766 | } |
| 767 | |
| Christopher Wiley | 03d1eb6 | 2015-11-19 06:42:40 -0800 | [diff] [blame] | 768 | template<typename T, typename U> |
| 769 | status_t Parcel::unsafeWriteTypedVector(const std::vector<T>& val, |
| 770 | status_t(Parcel::*write_func)(U)) { |
| 771 | if (val.size() > std::numeric_limits<int32_t>::max()) { |
| 772 | return BAD_VALUE; |
| 773 | } |
| 774 | |
| Colin Cross | 4c62b4f | 2016-09-27 13:58:30 -0700 | [diff] [blame] | 775 | status_t status = this->writeInt32(static_cast<int32_t>(val.size())); |
| Christopher Wiley | 03d1eb6 | 2015-11-19 06:42:40 -0800 | [diff] [blame] | 776 | |
| 777 | if (status != OK) { |
| 778 | return status; |
| 779 | } |
| 780 | |
| 781 | for (const auto& item : val) { |
| 782 | status = (this->*write_func)(item); |
| 783 | |
| 784 | if (status != OK) { |
| 785 | return status; |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | return OK; |
| 790 | } |
| 791 | |
| 792 | template<typename T> |
| 793 | status_t Parcel::writeTypedVector(const std::vector<T>& val, |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 794 | status_t(Parcel::*write_func)(const T&)) { |
| Christopher Wiley | 03d1eb6 | 2015-11-19 06:42:40 -0800 | [diff] [blame] | 795 | return unsafeWriteTypedVector(val, write_func); |
| 796 | } |
| 797 | |
| 798 | template<typename T> |
| 799 | status_t Parcel::writeTypedVector(const std::vector<T>& val, |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 800 | status_t(Parcel::*write_func)(T)) { |
| Christopher Wiley | 03d1eb6 | 2015-11-19 06:42:40 -0800 | [diff] [blame] | 801 | return unsafeWriteTypedVector(val, write_func); |
| 802 | } |
| 803 | |
| Christopher Wiley | 97f048d | 2015-11-19 06:49:05 -0800 | [diff] [blame] | 804 | template<typename T> |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 805 | status_t Parcel::writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val, |
| 806 | status_t(Parcel::*write_func)(const T&)) { |
| 807 | if (val.get() == nullptr) { |
| 808 | return this->writeInt32(-1); |
| 809 | } |
| 810 | |
| 811 | return unsafeWriteTypedVector(*val, write_func); |
| 812 | } |
| 813 | |
| 814 | template<typename T> |
| 815 | status_t Parcel::writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val, |
| 816 | status_t(Parcel::*write_func)(T)) { |
| 817 | if (val.get() == nullptr) { |
| 818 | return this->writeInt32(-1); |
| 819 | } |
| 820 | |
| 821 | return unsafeWriteTypedVector(*val, write_func); |
| 822 | } |
| 823 | |
| 824 | template<typename T> |
| Christopher Wiley | 97f048d | 2015-11-19 06:49:05 -0800 | [diff] [blame] | 825 | status_t Parcel::readParcelableVector(std::vector<T>* val) const { |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 826 | return unsafeReadTypedVector<T, Parcelable>(val, &Parcel::readParcelable); |
| 827 | } |
| 828 | |
| 829 | template<typename T> |
| 830 | status_t Parcel::readParcelableVector(std::unique_ptr<std::vector<std::unique_ptr<T>>>* val) const { |
| Colin Cross | 4c62b4f | 2016-09-27 13:58:30 -0700 | [diff] [blame] | 831 | const size_t start = dataPosition(); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 832 | int32_t size; |
| 833 | status_t status = readInt32(&size); |
| 834 | val->reset(); |
| 835 | |
| 836 | if (status != OK || size < 0) { |
| 837 | return status; |
| 838 | } |
| 839 | |
| 840 | setDataPosition(start); |
| Janis Danisevskis | f26a3ab | 2016-05-20 18:10:04 +0100 | [diff] [blame] | 841 | val->reset(new std::vector<std::unique_ptr<T>>()); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 842 | |
| Janis Danisevskis | f26a3ab | 2016-05-20 18:10:04 +0100 | [diff] [blame] | 843 | status = unsafeReadTypedVector(val->get(), &Parcel::readParcelable<T>); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 844 | |
| 845 | if (status != OK) { |
| 846 | val->reset(); |
| 847 | } |
| 848 | |
| 849 | return status; |
| 850 | } |
| 851 | |
| 852 | template<typename T> |
| 853 | status_t Parcel::readParcelable(std::unique_ptr<T>* parcelable) const { |
| Colin Cross | 4c62b4f | 2016-09-27 13:58:30 -0700 | [diff] [blame] | 854 | const size_t start = dataPosition(); |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 855 | int32_t present; |
| 856 | status_t status = readInt32(&present); |
| 857 | parcelable->reset(); |
| 858 | |
| 859 | if (status != OK || !present) { |
| 860 | return status; |
| 861 | } |
| 862 | |
| 863 | setDataPosition(start); |
| 864 | parcelable->reset(new T()); |
| 865 | |
| 866 | status = readParcelable(parcelable->get()); |
| 867 | |
| 868 | if (status != OK) { |
| 869 | parcelable->reset(); |
| 870 | } |
| 871 | |
| 872 | return status; |
| 873 | } |
| 874 | |
| 875 | template<typename T> |
| 876 | status_t Parcel::writeNullableParcelable(const std::unique_ptr<T>& parcelable) { |
| 877 | return writeRawNullableParcelable(parcelable.get()); |
| Christopher Wiley | 97f048d | 2015-11-19 06:49:05 -0800 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | template<typename T> |
| 881 | status_t Parcel::writeParcelableVector(const std::vector<T>& val) { |
| Casey Dahlin | b987262 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 882 | return unsafeWriteTypedVector<T,const Parcelable&>(val, &Parcel::writeParcelable); |
| 883 | } |
| 884 | |
| 885 | template<typename T> |
| 886 | status_t Parcel::writeParcelableVector(const std::unique_ptr<std::vector<std::unique_ptr<T>>>& val) { |
| 887 | if (val.get() == nullptr) { |
| 888 | return this->writeInt32(-1); |
| 889 | } |
| 890 | |
| Janis Danisevskis | 8d74709 | 2016-08-11 13:52:12 +0100 | [diff] [blame] | 891 | return unsafeWriteTypedVector(*val, &Parcel::writeNullableParcelable<T>); |
| 892 | } |
| 893 | |
| 894 | template<typename T> |
| 895 | status_t Parcel::writeParcelableVector(const std::shared_ptr<std::vector<std::unique_ptr<T>>>& val) { |
| 896 | if (val.get() == nullptr) { |
| 897 | return this->writeInt32(-1); |
| 898 | } |
| 899 | |
| 900 | return unsafeWriteTypedVector(*val, &Parcel::writeNullableParcelable<T>); |
| Christopher Wiley | 97f048d | 2015-11-19 06:49:05 -0800 | [diff] [blame] | 901 | } |
| 902 | |
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 903 | // --------------------------------------------------------------------------- |
| 904 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel) |
| 906 | { |
| 907 | parcel.print(to); |
| 908 | return to; |
| 909 | } |
| 910 | |
| 911 | // --------------------------------------------------------------------------- |
| 912 | |
| 913 | // Generic acquire and release of objects. |
| 914 | void acquire_object(const sp<ProcessState>& proc, |
| Ian Pedowitz | 6880307 | 2015-10-22 22:08:10 +0000 | [diff] [blame] | 915 | const flat_binder_object& obj, const void* who); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | void release_object(const sp<ProcessState>& proc, |
| Ian Pedowitz | 6880307 | 2015-10-22 22:08:10 +0000 | [diff] [blame] | 917 | const flat_binder_object& obj, const void* who); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | |
| 919 | void flatten_binder(const sp<ProcessState>& proc, |
| 920 | const sp<IBinder>& binder, flat_binder_object* out); |
| 921 | void flatten_binder(const sp<ProcessState>& proc, |
| 922 | const wp<IBinder>& binder, flat_binder_object* out); |
| 923 | status_t unflatten_binder(const sp<ProcessState>& proc, |
| 924 | const flat_binder_object& flat, sp<IBinder>* out); |
| 925 | status_t unflatten_binder(const sp<ProcessState>& proc, |
| 926 | const flat_binder_object& flat, wp<IBinder>* out); |
| 927 | |
| 928 | }; // namespace android |
| 929 | |
| 930 | // --------------------------------------------------------------------------- |
| 931 | |
| 932 | #endif // ANDROID_PARCEL_H |