blob: 14fd002af3f7143e130df5f9a4f4474088fbcb63 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Wiley9a5e32f2016-01-28 16:56:53 -080020#include <string>
Casey Dahlin451ff582015-10-19 18:12:18 -070021#include <vector>
22
Christopher Wiley83e6b982016-04-19 10:27:00 -070023#include <android-base/unique_fd.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080024#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 Agopian8683fca2012-08-12 19:37:16 -070029#include <utils/Flattenable.h>
Christopher Ferris0170cd02016-07-18 16:57:34 -070030#include <linux/android/binder.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031
Casey Dahlinf0c13772015-10-27 18:33:56 -070032#include <binder/IInterface.h>
Christopher Wiley97f048d2015-11-19 06:49:05 -080033#include <binder/Parcelable.h>
Casey Dahlinf0c13772015-10-27 18:33:56 -070034
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035// ---------------------------------------------------------------------------
36namespace android {
37
Mathias Agopiane1424282013-07-29 21:24:40 -070038template <typename T> class Flattenable;
Mathias Agopian8683fca2012-08-12 19:37:16 -070039template <typename T> class LightFlattenable;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040class IBinder;
Brad Fitzpatrick70081a12010-07-27 09:49:11 -070041class IPCThreadState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042class ProcessState;
43class String8;
44class TextOutput;
45
Mathias Agopiane1424282013-07-29 21:24:40 -070046class Parcel {
Serban Constantinescuf683e012013-11-05 16:53:55 +000047 friend class IPCThreadState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048public:
Jeff Brown5707dbf2011-09-23 21:17:56 -070049 class ReadableBlob;
50 class WritableBlob;
51
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052 Parcel();
53 ~Parcel();
54
55 const uint8_t* data() const;
56 size_t dataSize() const;
57 size_t dataAvail() const;
58 size_t dataPosition() const;
59 size_t dataCapacity() const;
Dianne Hackborn8938ed22011-09-28 23:19:47 -040060
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 status_t setDataSize(size_t size);
62 void setDataPosition(size_t pos) const;
63 status_t setDataCapacity(size_t size);
64
65 status_t setData(const uint8_t* buffer, size_t len);
66
Andreas Huber51faf462011-04-13 10:21:56 -070067 status_t appendFrom(const Parcel *parcel,
68 size_t start, size_t len);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069
Jeff Brown13b16042014-11-11 16:44:25 -080070 bool allowFds() const;
Dianne Hackborn7746cc32011-10-03 21:09:35 -070071 bool pushAllowFds(bool allowFds);
72 void restoreAllowFds(bool lastValue);
Dianne Hackborn8938ed22011-09-28 23:19:47 -040073
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 bool hasFileDescriptors() const;
75
Brad Fitzpatrick702ea9d2010-06-18 13:07:53 -070076 // Writes the RPC header.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077 status_t writeInterfaceToken(const String16& interface);
Brad Fitzpatricka877cd82010-07-07 16:06:39 -070078
Brad Fitzpatrick702ea9d2010-06-18 13:07:53 -070079 // Parses the RPC header, returning true if the interface name
80 // in the header matches the expected interface from the caller.
Brad Fitzpatrick70081a12010-07-27 09:49:11 -070081 //
82 // Additionally, enforceInterface does part of the work of
83 // propagating the StrictMode policy mask, populating the current
84 // IPCThreadState, which as an optimization may optionally be
85 // passed in.
Brad Fitzpatricka877cd82010-07-07 16:06:39 -070086 bool enforceInterface(const String16& interface,
Brad Fitzpatrick70081a12010-07-27 09:49:11 -070087 IPCThreadState* threadState = NULL) const;
Brad Fitzpatrick702ea9d2010-06-18 13:07:53 -070088 bool checkInterface(IBinder*) const;
Mathias Agopian83c04462009-05-22 19:00:22 -070089
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090 void freeData();
91
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -080092private:
93 const binder_size_t* objects() const;
94
95public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096 size_t objectsCount() const;
97
98 status_t errorCheck() const;
99 void setError(status_t err);
100
101 status_t write(const void* data, size_t len);
102 void* writeInplace(size_t len);
103 status_t writeUnpadded(const void* data, size_t len);
104 status_t writeInt32(int32_t val);
Dan Stoza41a0f2f2014-12-01 10:01:10 -0800105 status_t writeUint32(uint32_t val);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106 status_t writeInt64(int64_t val);
Ronghua Wu2d13afd2015-03-16 11:11:07 -0700107 status_t writeUint64(uint64_t val);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108 status_t writeFloat(float val);
109 status_t writeDouble(double val);
110 status_t writeCString(const char* str);
111 status_t writeString8(const String8& str);
112 status_t writeString16(const String16& str);
Casey Dahlinb9872622015-11-25 15:09:45 -0800113 status_t writeString16(const std::unique_ptr<String16>& str);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800114 status_t writeString16(const char16_t* str, size_t len);
115 status_t writeStrongBinder(const sp<IBinder>& val);
116 status_t writeWeakBinder(const wp<IBinder>& val);
Marco Nelissen5c0106e2013-10-16 10:57:51 -0700117 status_t writeInt32Array(size_t len, const int32_t *val);
Marco Nelissenf0190bf2014-03-13 14:17:40 -0700118 status_t writeByteArray(size_t len, const uint8_t *val);
Casey Dahlind6848f52015-10-15 15:44:59 -0700119 status_t writeBool(bool val);
120 status_t writeChar(char16_t val);
121 status_t writeByte(int8_t val);
Mathias Agopiane1424282013-07-29 21:24:40 -0700122
Christopher Wiley9a5e32f2016-01-28 16:56:53 -0800123 // Take a UTF8 encoded string, convert to UTF16, write it to the parcel.
124 status_t writeUtf8AsUtf16(const std::string& str);
125 status_t writeUtf8AsUtf16(const std::unique_ptr<std::string>& str);
126
Casey Dahlinb9872622015-11-25 15:09:45 -0800127 status_t writeByteVector(const std::unique_ptr<std::vector<int8_t>>& val);
Casey Dahlin451ff582015-10-19 18:12:18 -0700128 status_t writeByteVector(const std::vector<int8_t>& val);
Casey Dahlin185d3442016-02-09 11:08:35 -0800129 status_t writeByteVector(const std::unique_ptr<std::vector<uint8_t>>& val);
130 status_t writeByteVector(const std::vector<uint8_t>& val);
Casey Dahlinb9872622015-11-25 15:09:45 -0800131 status_t writeInt32Vector(const std::unique_ptr<std::vector<int32_t>>& val);
Casey Dahlin451ff582015-10-19 18:12:18 -0700132 status_t writeInt32Vector(const std::vector<int32_t>& val);
Casey Dahlinb9872622015-11-25 15:09:45 -0800133 status_t writeInt64Vector(const std::unique_ptr<std::vector<int64_t>>& val);
Casey Dahlin451ff582015-10-19 18:12:18 -0700134 status_t writeInt64Vector(const std::vector<int64_t>& val);
Casey Dahlinb9872622015-11-25 15:09:45 -0800135 status_t writeFloatVector(const std::unique_ptr<std::vector<float>>& val);
Casey Dahlin451ff582015-10-19 18:12:18 -0700136 status_t writeFloatVector(const std::vector<float>& val);
Casey Dahlinb9872622015-11-25 15:09:45 -0800137 status_t writeDoubleVector(const std::unique_ptr<std::vector<double>>& val);
Casey Dahlin451ff582015-10-19 18:12:18 -0700138 status_t writeDoubleVector(const std::vector<double>& val);
Casey Dahlinb9872622015-11-25 15:09:45 -0800139 status_t writeBoolVector(const std::unique_ptr<std::vector<bool>>& val);
Casey Dahlin451ff582015-10-19 18:12:18 -0700140 status_t writeBoolVector(const std::vector<bool>& val);
Casey Dahlinb9872622015-11-25 15:09:45 -0800141 status_t writeCharVector(const std::unique_ptr<std::vector<char16_t>>& val);
Casey Dahlin451ff582015-10-19 18:12:18 -0700142 status_t writeCharVector(const std::vector<char16_t>& val);
Casey Dahlinb9872622015-11-25 15:09:45 -0800143 status_t writeString16Vector(
144 const std::unique_ptr<std::vector<std::unique_ptr<String16>>>& val);
Casey Dahlin451ff582015-10-19 18:12:18 -0700145 status_t writeString16Vector(const std::vector<String16>& val);
Christopher Wiley9a5e32f2016-01-28 16:56:53 -0800146 status_t writeUtf8VectorAsUtf16Vector(
147 const std::unique_ptr<std::vector<std::unique_ptr<std::string>>>& val);
148 status_t writeUtf8VectorAsUtf16Vector(const std::vector<std::string>& val);
Casey Dahlin451ff582015-10-19 18:12:18 -0700149
Casey Dahlinb9872622015-11-25 15:09:45 -0800150 status_t writeStrongBinderVector(const std::unique_ptr<std::vector<sp<IBinder>>>& val);
Casey Dahlineb8e15f2015-11-03 13:50:37 -0800151 status_t writeStrongBinderVector(const std::vector<sp<IBinder>>& val);
152
Mathias Agopiane1424282013-07-29 21:24:40 -0700153 template<typename T>
Casey Dahlinb9872622015-11-25 15:09:45 -0800154 status_t writeParcelableVector(const std::unique_ptr<std::vector<std::unique_ptr<T>>>& val);
155 template<typename T>
Christopher Wiley97f048d2015-11-19 06:49:05 -0800156 status_t writeParcelableVector(const std::vector<T>& val);
Casey Dahlinb9872622015-11-25 15:09:45 -0800157
158 template<typename T>
159 status_t writeNullableParcelable(const std::unique_ptr<T>& parcelable);
160
Christopher Wiley97f048d2015-11-19 06:49:05 -0800161 status_t writeParcelable(const Parcelable& parcelable);
162
163 template<typename T>
Mathias Agopiane1424282013-07-29 21:24:40 -0700164 status_t write(const Flattenable<T>& val);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165
Mathias Agopian8683fca2012-08-12 19:37:16 -0700166 template<typename T>
167 status_t write(const LightFlattenable<T>& val);
168
Christopher Wiley31c1beb2016-08-19 11:43:54 -0700169 template<typename T>
170 status_t writeVectorSize(const std::vector<T>& val);
171 template<typename T>
172 status_t writeVectorSize(const std::unique_ptr<std::vector<T>>& val);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700173
Mathias Agopiana47f02a2009-05-21 16:29:38 -0700174 // Place a native_handle into the parcel (the native_handle's file-
175 // descriptors are dup'ed, so it is safe to delete the native_handle
Casey Dahlin451ff582015-10-19 18:12:18 -0700176 // when this function returns).
Mathias Agopiana47f02a2009-05-21 16:29:38 -0700177 // Doesn't take ownership of the native_handle.
178 status_t writeNativeHandle(const native_handle* handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800179
180 // Place a file descriptor into the parcel. The given fd must remain
181 // valid for the lifetime of the parcel.
Jeff Brown93ff1f92011-11-04 19:01:44 -0700182 // The Parcel does not take ownership of the given fd unless you ask it to.
183 status_t writeFileDescriptor(int fd, bool takeOwnership = false);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800184
185 // Place a file descriptor into the parcel. A dup of the fd is made, which
186 // will be closed once the parcel is destroyed.
187 status_t writeDupFileDescriptor(int fd);
Jeff Brown5707dbf2011-09-23 21:17:56 -0700188
Casey Dahlin06673e32015-11-23 13:24:23 -0800189 // Place a file descriptor into the parcel. This will not affect the
190 // semantics of the smart file descriptor. A new descriptor will be
191 // created, and will be closed when the parcel is destroyed.
192 status_t writeUniqueFileDescriptor(
Christopher Wiley2cf19952016-04-11 11:09:37 -0700193 const base::unique_fd& fd);
Casey Dahlin06673e32015-11-23 13:24:23 -0800194
195 // Place a vector of file desciptors into the parcel. Each descriptor is
196 // dup'd as in writeDupFileDescriptor
197 status_t writeUniqueFileDescriptorVector(
Christopher Wiley2cf19952016-04-11 11:09:37 -0700198 const std::unique_ptr<std::vector<base::unique_fd>>& val);
Casey Dahlinb9872622015-11-25 15:09:45 -0800199 status_t writeUniqueFileDescriptorVector(
Christopher Wiley2cf19952016-04-11 11:09:37 -0700200 const std::vector<base::unique_fd>& val);
Casey Dahlin06673e32015-11-23 13:24:23 -0800201
Jeff Brown5707dbf2011-09-23 21:17:56 -0700202 // Writes a blob to the parcel.
203 // If the blob is small, then it is stored in-place, otherwise it is
Jeff Brown13b16042014-11-11 16:44:25 -0800204 // transferred by way of an anonymous shared memory region. Prefer sending
205 // immutable blobs if possible since they may be subsequently transferred between
206 // processes without further copying whereas mutable blobs always need to be copied.
Jeff Brown5707dbf2011-09-23 21:17:56 -0700207 // The caller should call release() on the blob after writing its contents.
Jeff Brown13b16042014-11-11 16:44:25 -0800208 status_t writeBlob(size_t len, bool mutableCopy, WritableBlob* outBlob);
209
210 // Write an existing immutable blob file descriptor to the parcel.
211 // This allows the client to send the same blob to multiple processes
212 // as long as it keeps a dup of the blob file descriptor handy for later.
213 status_t writeDupImmutableBlobFileDescriptor(int fd);
Jeff Brown5707dbf2011-09-23 21:17:56 -0700214
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800215 status_t writeObject(const flat_binder_object& val, bool nullMetaData);
216
Brad Fitzpatrick837a0d02010-07-13 15:33:35 -0700217 // Like Parcel.java's writeNoException(). Just writes a zero int32.
218 // Currently the native implementation doesn't do any of the StrictMode
219 // stack gathering and serialization that the Java implementation does.
220 status_t writeNoException();
221
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800222 void remove(size_t start, size_t amt);
223
224 status_t read(void* outData, size_t len) const;
225 const void* readInplace(size_t len) const;
226 int32_t readInt32() const;
227 status_t readInt32(int32_t *pArg) const;
Dan Stoza41a0f2f2014-12-01 10:01:10 -0800228 uint32_t readUint32() const;
229 status_t readUint32(uint32_t *pArg) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800230 int64_t readInt64() const;
231 status_t readInt64(int64_t *pArg) const;
Ronghua Wu2d13afd2015-03-16 11:11:07 -0700232 uint64_t readUint64() const;
233 status_t readUint64(uint64_t *pArg) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800234 float readFloat() const;
235 status_t readFloat(float *pArg) const;
236 double readDouble() const;
237 status_t readDouble(double *pArg) const;
Andreas Huber84a6d042009-08-17 13:33:27 -0700238 intptr_t readIntPtr() const;
239 status_t readIntPtr(intptr_t *pArg) const;
Casey Dahlind6848f52015-10-15 15:44:59 -0700240 bool readBool() const;
241 status_t readBool(bool *pArg) const;
242 char16_t readChar() const;
243 status_t readChar(char16_t *pArg) const;
244 int8_t readByte() const;
245 status_t readByte(int8_t *pArg) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800246
Christopher Wiley9a5e32f2016-01-28 16:56:53 -0800247 // Read a UTF16 encoded string, convert to UTF8
248 status_t readUtf8FromUtf16(std::string* str) const;
249 status_t readUtf8FromUtf16(std::unique_ptr<std::string>* str) const;
250
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800251 const char* readCString() const;
252 String8 readString8() const;
Roshan Pius87b64d22016-07-18 12:51:02 -0700253 status_t readString8(String8* pArg) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800254 String16 readString16() const;
Casey Dahlin451ff582015-10-19 18:12:18 -0700255 status_t readString16(String16* pArg) const;
Casey Dahlinb9872622015-11-25 15:09:45 -0800256 status_t readString16(std::unique_ptr<String16>* pArg) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800257 const char16_t* readString16Inplace(size_t* outLen) const;
258 sp<IBinder> readStrongBinder() const;
Casey Dahlinf0c13772015-10-27 18:33:56 -0700259 status_t readStrongBinder(sp<IBinder>* val) const;
Christopher Wiley35d77ca2016-03-08 10:49:51 -0800260 status_t readNullableStrongBinder(sp<IBinder>* val) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800261 wp<IBinder> readWeakBinder() const;
Mathias Agopiane1424282013-07-29 21:24:40 -0700262
Casey Dahlinf0c13772015-10-27 18:33:56 -0700263 template<typename T>
Casey Dahlinb9872622015-11-25 15:09:45 -0800264 status_t readParcelableVector(
265 std::unique_ptr<std::vector<std::unique_ptr<T>>>* val) const;
266 template<typename T>
Christopher Wiley97f048d2015-11-19 06:49:05 -0800267 status_t readParcelableVector(std::vector<T>* val) const;
Casey Dahlinb9872622015-11-25 15:09:45 -0800268
Christopher Wiley97f048d2015-11-19 06:49:05 -0800269 status_t readParcelable(Parcelable* parcelable) const;
270
271 template<typename T>
Casey Dahlinb9872622015-11-25 15:09:45 -0800272 status_t readParcelable(std::unique_ptr<T>* parcelable) const;
273
274 template<typename T>
Casey Dahlineb8e15f2015-11-03 13:50:37 -0800275 status_t readStrongBinder(sp<T>* val) const;
276
Christopher Wiley35d77ca2016-03-08 10:49:51 -0800277 template<typename T>
278 status_t readNullableStrongBinder(sp<T>* val) const;
279
Casey Dahlinb9872622015-11-25 15:09:45 -0800280 status_t readStrongBinderVector(std::unique_ptr<std::vector<sp<IBinder>>>* val) const;
Casey Dahlineb8e15f2015-11-03 13:50:37 -0800281 status_t readStrongBinderVector(std::vector<sp<IBinder>>* val) const;
Casey Dahlinf0c13772015-10-27 18:33:56 -0700282
Casey Dahlinb9872622015-11-25 15:09:45 -0800283 status_t readByteVector(std::unique_ptr<std::vector<int8_t>>* val) const;
Casey Dahlin451ff582015-10-19 18:12:18 -0700284 status_t readByteVector(std::vector<int8_t>* val) const;
Casey Dahlin185d3442016-02-09 11:08:35 -0800285 status_t readByteVector(std::unique_ptr<std::vector<uint8_t>>* val) const;
286 status_t readByteVector(std::vector<uint8_t>* val) const;
Casey Dahlinb9872622015-11-25 15:09:45 -0800287 status_t readInt32Vector(std::unique_ptr<std::vector<int32_t>>* val) const;
Casey Dahlin451ff582015-10-19 18:12:18 -0700288 status_t readInt32Vector(std::vector<int32_t>* val) const;
Casey Dahlinb9872622015-11-25 15:09:45 -0800289 status_t readInt64Vector(std::unique_ptr<std::vector<int64_t>>* val) const;
Casey Dahlin451ff582015-10-19 18:12:18 -0700290 status_t readInt64Vector(std::vector<int64_t>* val) const;
Casey Dahlinb9872622015-11-25 15:09:45 -0800291 status_t readFloatVector(std::unique_ptr<std::vector<float>>* val) const;
Casey Dahlin451ff582015-10-19 18:12:18 -0700292 status_t readFloatVector(std::vector<float>* val) const;
Casey Dahlinb9872622015-11-25 15:09:45 -0800293 status_t readDoubleVector(std::unique_ptr<std::vector<double>>* val) const;
Casey Dahlin451ff582015-10-19 18:12:18 -0700294 status_t readDoubleVector(std::vector<double>* val) const;
Casey Dahlinb9872622015-11-25 15:09:45 -0800295 status_t readBoolVector(std::unique_ptr<std::vector<bool>>* val) const;
Casey Dahlin451ff582015-10-19 18:12:18 -0700296 status_t readBoolVector(std::vector<bool>* val) const;
Casey Dahlinb9872622015-11-25 15:09:45 -0800297 status_t readCharVector(std::unique_ptr<std::vector<char16_t>>* val) const;
Casey Dahlin451ff582015-10-19 18:12:18 -0700298 status_t readCharVector(std::vector<char16_t>* val) const;
Casey Dahlinb9872622015-11-25 15:09:45 -0800299 status_t readString16Vector(
300 std::unique_ptr<std::vector<std::unique_ptr<String16>>>* val) const;
Casey Dahlin451ff582015-10-19 18:12:18 -0700301 status_t readString16Vector(std::vector<String16>* val) const;
Christopher Wiley9a5e32f2016-01-28 16:56:53 -0800302 status_t readUtf8VectorFromUtf16Vector(
303 std::unique_ptr<std::vector<std::unique_ptr<std::string>>>* val) const;
304 status_t readUtf8VectorFromUtf16Vector(std::vector<std::string>* val) const;
Casey Dahlin451ff582015-10-19 18:12:18 -0700305
Mathias Agopiane1424282013-07-29 21:24:40 -0700306 template<typename T>
307 status_t read(Flattenable<T>& val) const;
Brad Fitzpatrick837a0d02010-07-13 15:33:35 -0700308
Mathias Agopian8683fca2012-08-12 19:37:16 -0700309 template<typename T>
310 status_t read(LightFlattenable<T>& val) const;
311
Christopher Wiley31c1beb2016-08-19 11:43:54 -0700312 template<typename T>
313 status_t resizeOutVector(std::vector<T>* val) const;
314 template<typename T>
315 status_t resizeOutVector(std::unique_ptr<std::vector<T>>* val) const;
316
Brad Fitzpatrick837a0d02010-07-13 15:33:35 -0700317 // Like Parcel.java's readExceptionCode(). Reads the first int32
318 // off of a Parcel's header, returning 0 or the negative error
319 // code on exceptions, but also deals with skipping over rich
320 // response headers. Callers should use this to read & parse the
321 // response headers rather than doing it by hand.
322 int32_t readExceptionCode() const;
323
Mathias Agopiana47f02a2009-05-21 16:29:38 -0700324 // Retrieve native_handle from the parcel. This returns a copy of the
325 // parcel's native_handle (the caller takes ownership). The caller
326 // must free the native_handle with native_handle_close() and
327 // native_handle_delete().
328 native_handle* readNativeHandle() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800329
330
331 // Retrieve a file descriptor from the parcel. This returns the raw fd
332 // in the parcel, which you do not own -- use dup() to get your own copy.
333 int readFileDescriptor() const;
Jeff Brown5707dbf2011-09-23 21:17:56 -0700334
Casey Dahlin06673e32015-11-23 13:24:23 -0800335 // Retrieve a smart file descriptor from the parcel.
336 status_t readUniqueFileDescriptor(
Christopher Wiley2cf19952016-04-11 11:09:37 -0700337 base::unique_fd* val) const;
Casey Dahlin06673e32015-11-23 13:24:23 -0800338
339
340 // Retrieve a vector of smart file descriptors from the parcel.
341 status_t readUniqueFileDescriptorVector(
Christopher Wiley2cf19952016-04-11 11:09:37 -0700342 std::unique_ptr<std::vector<base::unique_fd>>* val) const;
Casey Dahlinb9872622015-11-25 15:09:45 -0800343 status_t readUniqueFileDescriptorVector(
Christopher Wiley2cf19952016-04-11 11:09:37 -0700344 std::vector<base::unique_fd>* val) const;
Casey Dahlin06673e32015-11-23 13:24:23 -0800345
Jeff Brown5707dbf2011-09-23 21:17:56 -0700346 // Reads a blob from the parcel.
347 // The caller should call release() on the blob after reading its contents.
348 status_t readBlob(size_t len, ReadableBlob* outBlob) const;
349
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800350 const flat_binder_object* readObject(bool nullMetaData) const;
351
352 // Explicitly close all file descriptors in the parcel.
353 void closeFileDescriptors();
Dianne Hackborn7e790af2014-11-11 12:22:53 -0800354
355 // Debugging: get metrics on current allocations.
356 static size_t getGlobalAllocSize();
357 static size_t getGlobalAllocCount();
358
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800359private:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800360 typedef void (*release_func)(Parcel* parcel,
361 const uint8_t* data, size_t dataSize,
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800362 const binder_size_t* objects, size_t objectsSize,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800363 void* cookie);
364
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800365 uintptr_t ipcData() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800366 size_t ipcDataSize() const;
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800367 uintptr_t ipcObjects() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800368 size_t ipcObjectsCount() const;
369 void ipcSetDataReference(const uint8_t* data, size_t dataSize,
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800370 const binder_size_t* objects, size_t objectsCount,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800371 release_func relFunc, void* relCookie);
372
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800373public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800374 void print(TextOutput& to, uint32_t flags = 0) const;
Jeff Brown5707dbf2011-09-23 21:17:56 -0700375
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800376private:
377 Parcel(const Parcel& o);
378 Parcel& operator=(const Parcel& o);
379
380 status_t finishWrite(size_t len);
381 void releaseObjects();
382 void acquireObjects();
383 status_t growData(size_t len);
384 status_t restartWrite(size_t desired);
385 status_t continueWrite(size_t desired);
Serban Constantinescuf683e012013-11-05 16:53:55 +0000386 status_t writePointer(uintptr_t val);
387 status_t readPointer(uintptr_t *pArg) const;
388 uintptr_t readPointer() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800389 void freeDataNoInit();
390 void initState();
391 void scanForFds() const;
392
Andreas Huber84a6d042009-08-17 13:33:27 -0700393 template<class T>
394 status_t readAligned(T *pArg) const;
395
396 template<class T> T readAligned() const;
397
398 template<class T>
399 status_t writeAligned(T val);
400
Casey Dahlinb9872622015-11-25 15:09:45 -0800401 status_t writeRawNullableParcelable(const Parcelable*
402 parcelable);
403
Christopher Wiley03d1eb62015-11-19 06:42:40 -0800404 template<typename T, typename U>
405 status_t unsafeReadTypedVector(std::vector<T>* val,
406 status_t(Parcel::*read_func)(U*) const) const;
407 template<typename T>
Casey Dahlinb9872622015-11-25 15:09:45 -0800408 status_t readNullableTypedVector(std::unique_ptr<std::vector<T>>* val,
409 status_t(Parcel::*read_func)(T*) const) const;
410 template<typename T>
Christopher Wiley03d1eb62015-11-19 06:42:40 -0800411 status_t readTypedVector(std::vector<T>* val,
412 status_t(Parcel::*read_func)(T*) const) const;
413 template<typename T, typename U>
414 status_t unsafeWriteTypedVector(const std::vector<T>& val,
415 status_t(Parcel::*write_func)(U));
416 template<typename T>
Casey Dahlinb9872622015-11-25 15:09:45 -0800417 status_t writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val,
418 status_t(Parcel::*write_func)(const T&));
419 template<typename T>
420 status_t writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val,
421 status_t(Parcel::*write_func)(T));
422 template<typename T>
Christopher Wiley03d1eb62015-11-19 06:42:40 -0800423 status_t writeTypedVector(const std::vector<T>& val,
424 status_t(Parcel::*write_func)(const T&));
425 template<typename T>
426 status_t writeTypedVector(const std::vector<T>& val,
427 status_t(Parcel::*write_func)(T));
428
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800429 status_t mError;
430 uint8_t* mData;
431 size_t mDataSize;
432 size_t mDataCapacity;
433 mutable size_t mDataPos;
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800434 binder_size_t* mObjects;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800435 size_t mObjectsSize;
436 size_t mObjectsCapacity;
437 mutable size_t mNextObjectHint;
438
439 mutable bool mFdsKnown;
440 mutable bool mHasFds;
Dianne Hackborn8938ed22011-09-28 23:19:47 -0400441 bool mAllowFds;
Christopher Tatee4e0ae82016-03-24 16:03:44 -0700442
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800443 release_func mOwner;
444 void* mOwnerCookie;
Jeff Brown5707dbf2011-09-23 21:17:56 -0700445
446 class Blob {
447 public:
448 Blob();
449 ~Blob();
450
Jeff Brown13b16042014-11-11 16:44:25 -0800451 void clear();
Jeff Brown5707dbf2011-09-23 21:17:56 -0700452 void release();
453 inline size_t size() const { return mSize; }
Colin Cross17576de2016-09-26 13:07:06 -0700454 inline int fd() const { return mFd; }
Jeff Brown13b16042014-11-11 16:44:25 -0800455 inline bool isMutable() const { return mMutable; }
Jeff Brown5707dbf2011-09-23 21:17:56 -0700456
457 protected:
Jeff Brown13b16042014-11-11 16:44:25 -0800458 void init(int fd, void* data, size_t size, bool isMutable);
Jeff Brown5707dbf2011-09-23 21:17:56 -0700459
Jeff Brown13b16042014-11-11 16:44:25 -0800460 int mFd; // owned by parcel so not closed when released
Jeff Brown5707dbf2011-09-23 21:17:56 -0700461 void* mData;
462 size_t mSize;
Jeff Brown13b16042014-11-11 16:44:25 -0800463 bool mMutable;
Jeff Brown5707dbf2011-09-23 21:17:56 -0700464 };
465
Mathias Agopiane1424282013-07-29 21:24:40 -0700466 class FlattenableHelperInterface {
467 protected:
468 ~FlattenableHelperInterface() { }
469 public:
470 virtual size_t getFlattenedSize() const = 0;
471 virtual size_t getFdCount() const = 0;
472 virtual status_t flatten(void* buffer, size_t size, int* fds, size_t count) const = 0;
473 virtual status_t unflatten(void const* buffer, size_t size, int const* fds, size_t count) = 0;
474 };
475
476 template<typename T>
477 class FlattenableHelper : public FlattenableHelperInterface {
478 friend class Parcel;
479 const Flattenable<T>& val;
Colin Cross382ecd32016-09-26 13:33:59 -0700480 explicit FlattenableHelper(const Flattenable<T>& _val) : val(_val) { }
Mathias Agopiane1424282013-07-29 21:24:40 -0700481
482 public:
483 virtual size_t getFlattenedSize() const {
484 return val.getFlattenedSize();
485 }
486 virtual size_t getFdCount() const {
487 return val.getFdCount();
488 }
489 virtual status_t flatten(void* buffer, size_t size, int* fds, size_t count) const {
490 return val.flatten(buffer, size, fds, count);
491 }
492 virtual status_t unflatten(void const* buffer, size_t size, int const* fds, size_t count) {
493 return const_cast<Flattenable<T>&>(val).unflatten(buffer, size, fds, count);
494 }
495 };
496 status_t write(const FlattenableHelperInterface& val);
497 status_t read(FlattenableHelperInterface& val) const;
498
Jeff Brown5707dbf2011-09-23 21:17:56 -0700499public:
500 class ReadableBlob : public Blob {
501 friend class Parcel;
502 public:
503 inline const void* data() const { return mData; }
Jeff Brown13b16042014-11-11 16:44:25 -0800504 inline void* mutableData() { return isMutable() ? mData : NULL; }
Jeff Brown5707dbf2011-09-23 21:17:56 -0700505 };
506
507 class WritableBlob : public Blob {
508 friend class Parcel;
509 public:
510 inline void* data() { return mData; }
511 };
Dan Sandleraa5c2342015-04-10 10:08:45 -0400512
513private:
Adrian Rooscbf37262015-10-22 16:12:53 -0700514 size_t mOpenAshmemSize;
Dan Sandleraa5c2342015-04-10 10:08:45 -0400515
516public:
Adrian Roos6bb31142015-10-22 16:46:12 -0700517 // TODO: Remove once ABI can be changed.
Dan Sandleraa5c2342015-04-10 10:08:45 -0400518 size_t getBlobAshmemSize() const;
Adrian Rooscbf37262015-10-22 16:12:53 -0700519 size_t getOpenAshmemSize() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800520};
521
522// ---------------------------------------------------------------------------
523
Mathias Agopian8683fca2012-08-12 19:37:16 -0700524template<typename T>
Mathias Agopiane1424282013-07-29 21:24:40 -0700525status_t Parcel::write(const Flattenable<T>& val) {
526 const FlattenableHelper<T> helper(val);
527 return write(helper);
528}
529
530template<typename T>
Mathias Agopian8683fca2012-08-12 19:37:16 -0700531status_t Parcel::write(const LightFlattenable<T>& val) {
Mathias Agopiane1424282013-07-29 21:24:40 -0700532 size_t size(val.getFlattenedSize());
Mathias Agopian8683fca2012-08-12 19:37:16 -0700533 if (!val.isFixedSize()) {
Colin Cross4c62b4f2016-09-27 13:58:30 -0700534 if (size > INT32_MAX) {
535 return BAD_VALUE;
536 }
537 status_t err = writeInt32(static_cast<int32_t>(size));
Mathias Agopian8683fca2012-08-12 19:37:16 -0700538 if (err != NO_ERROR) {
539 return err;
540 }
541 }
Mathias Agopian20985172012-08-31 14:25:22 -0700542 if (size) {
543 void* buffer = writeInplace(size);
Mathias Agopiane1424282013-07-29 21:24:40 -0700544 if (buffer == NULL)
545 return NO_MEMORY;
546 return val.flatten(buffer, size);
Mathias Agopian20985172012-08-31 14:25:22 -0700547 }
548 return NO_ERROR;
Mathias Agopian8683fca2012-08-12 19:37:16 -0700549}
550
551template<typename T>
Mathias Agopiane1424282013-07-29 21:24:40 -0700552status_t Parcel::read(Flattenable<T>& val) const {
553 FlattenableHelper<T> helper(val);
554 return read(helper);
555}
556
557template<typename T>
Mathias Agopian8683fca2012-08-12 19:37:16 -0700558status_t Parcel::read(LightFlattenable<T>& val) const {
559 size_t size;
560 if (val.isFixedSize()) {
Mathias Agopiane1424282013-07-29 21:24:40 -0700561 size = val.getFlattenedSize();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700562 } else {
563 int32_t s;
564 status_t err = readInt32(&s);
565 if (err != NO_ERROR) {
566 return err;
567 }
Colin Cross4c62b4f2016-09-27 13:58:30 -0700568 size = static_cast<size_t>(s);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700569 }
Mathias Agopian20985172012-08-31 14:25:22 -0700570 if (size) {
571 void const* buffer = readInplace(size);
572 return buffer == NULL ? NO_MEMORY :
573 val.unflatten(buffer, size);
574 }
575 return NO_ERROR;
Mathias Agopian8683fca2012-08-12 19:37:16 -0700576}
577
Casey Dahlinf0c13772015-10-27 18:33:56 -0700578template<typename T>
Christopher Wiley31c1beb2016-08-19 11:43:54 -0700579status_t Parcel::writeVectorSize(const std::vector<T>& val) {
580 if (val.size() > INT32_MAX) {
581 return BAD_VALUE;
582 }
Colin Cross4c62b4f2016-09-27 13:58:30 -0700583 return writeInt32(static_cast<int32_t>(val.size()));
Christopher Wiley31c1beb2016-08-19 11:43:54 -0700584}
585
586template<typename T>
587status_t Parcel::writeVectorSize(const std::unique_ptr<std::vector<T>>& val) {
588 if (!val) {
589 return writeInt32(-1);
590 }
591
592 return writeVectorSize(*val);
593}
594
595template<typename T>
596status_t Parcel::resizeOutVector(std::vector<T>* val) const {
597 int32_t size;
598 status_t err = readInt32(&size);
599 if (err != NO_ERROR) {
600 return err;
601 }
602
603 if (size < 0) {
604 return UNEXPECTED_NULL;
605 }
606 val->resize(size_t(size));
607 return OK;
608}
609
610template<typename T>
611status_t Parcel::resizeOutVector(std::unique_ptr<std::vector<T>>* val) const {
612 int32_t size;
613 status_t err = readInt32(&size);
614 if (err != NO_ERROR) {
615 return err;
616 }
617
618 val->reset();
619 if (size >= 0) {
620 val->reset(new std::vector<T>(size_t(size)));
621 }
622
623 return OK;
624}
625
626template<typename T>
Casey Dahlinf0c13772015-10-27 18:33:56 -0700627status_t Parcel::readStrongBinder(sp<T>* val) const {
628 sp<IBinder> tmp;
629 status_t ret = readStrongBinder(&tmp);
630
631 if (ret == OK) {
632 *val = interface_cast<T>(tmp);
633
634 if (val->get() == nullptr) {
635 return UNKNOWN_ERROR;
636 }
637 }
638
639 return ret;
640}
641
Christopher Wiley35d77ca2016-03-08 10:49:51 -0800642template<typename T>
643status_t Parcel::readNullableStrongBinder(sp<T>* val) const {
644 sp<IBinder> tmp;
645 status_t ret = readNullableStrongBinder(&tmp);
646
647 if (ret == OK) {
648 *val = interface_cast<T>(tmp);
649
Christopher Wiley447b00f2016-07-19 09:23:25 -0700650 if (val->get() == nullptr && tmp.get() != nullptr) {
651 ret = UNKNOWN_ERROR;
Christopher Wiley35d77ca2016-03-08 10:49:51 -0800652 }
653 }
Christopher Wiley447b00f2016-07-19 09:23:25 -0700654
655 return ret;
Christopher Wiley35d77ca2016-03-08 10:49:51 -0800656}
657
Christopher Wiley03d1eb62015-11-19 06:42:40 -0800658template<typename T, typename U>
659status_t Parcel::unsafeReadTypedVector(
Casey Dahlinb9872622015-11-25 15:09:45 -0800660 std::vector<T>* val,
661 status_t(Parcel::*read_func)(U*) const) const {
Christopher Wiley03d1eb62015-11-19 06:42:40 -0800662 int32_t size;
663 status_t status = this->readInt32(&size);
664
665 if (status != OK) {
666 return status;
667 }
668
669 if (size < 0) {
670 return UNEXPECTED_NULL;
671 }
672
Colin Cross4c62b4f2016-09-27 13:58:30 -0700673 val->resize(static_cast<size_t>(size));
Christopher Wiley03d1eb62015-11-19 06:42:40 -0800674
675 for (auto& v: *val) {
676 status = (this->*read_func)(&v);
677
678 if (status != OK) {
679 return status;
680 }
681 }
682
683 return OK;
684}
685
686template<typename T>
687status_t Parcel::readTypedVector(std::vector<T>* val,
688 status_t(Parcel::*read_func)(T*) const) const {
689 return unsafeReadTypedVector(val, read_func);
690}
691
Casey Dahlinb9872622015-11-25 15:09:45 -0800692template<typename T>
693status_t Parcel::readNullableTypedVector(std::unique_ptr<std::vector<T>>* val,
694 status_t(Parcel::*read_func)(T*) const) const {
Colin Cross4c62b4f2016-09-27 13:58:30 -0700695 const size_t start = dataPosition();
Casey Dahlinb9872622015-11-25 15:09:45 -0800696 int32_t size;
697 status_t status = readInt32(&size);
698 val->reset();
699
700 if (status != OK || size < 0) {
701 return status;
702 }
703
704 setDataPosition(start);
705 val->reset(new std::vector<T>());
706
707 status = unsafeReadTypedVector(val->get(), read_func);
708
709 if (status != OK) {
710 val->reset();
711 }
712
713 return status;
714}
715
Christopher Wiley03d1eb62015-11-19 06:42:40 -0800716template<typename T, typename U>
717status_t Parcel::unsafeWriteTypedVector(const std::vector<T>& val,
718 status_t(Parcel::*write_func)(U)) {
719 if (val.size() > std::numeric_limits<int32_t>::max()) {
720 return BAD_VALUE;
721 }
722
Colin Cross4c62b4f2016-09-27 13:58:30 -0700723 status_t status = this->writeInt32(static_cast<int32_t>(val.size()));
Christopher Wiley03d1eb62015-11-19 06:42:40 -0800724
725 if (status != OK) {
726 return status;
727 }
728
729 for (const auto& item : val) {
730 status = (this->*write_func)(item);
731
732 if (status != OK) {
733 return status;
734 }
735 }
736
737 return OK;
738}
739
740template<typename T>
741status_t Parcel::writeTypedVector(const std::vector<T>& val,
Casey Dahlinb9872622015-11-25 15:09:45 -0800742 status_t(Parcel::*write_func)(const T&)) {
Christopher Wiley03d1eb62015-11-19 06:42:40 -0800743 return unsafeWriteTypedVector(val, write_func);
744}
745
746template<typename T>
747status_t Parcel::writeTypedVector(const std::vector<T>& val,
Casey Dahlinb9872622015-11-25 15:09:45 -0800748 status_t(Parcel::*write_func)(T)) {
Christopher Wiley03d1eb62015-11-19 06:42:40 -0800749 return unsafeWriteTypedVector(val, write_func);
750}
751
Christopher Wiley97f048d2015-11-19 06:49:05 -0800752template<typename T>
Casey Dahlinb9872622015-11-25 15:09:45 -0800753status_t Parcel::writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val,
754 status_t(Parcel::*write_func)(const T&)) {
755 if (val.get() == nullptr) {
756 return this->writeInt32(-1);
757 }
758
759 return unsafeWriteTypedVector(*val, write_func);
760}
761
762template<typename T>
763status_t Parcel::writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val,
764 status_t(Parcel::*write_func)(T)) {
765 if (val.get() == nullptr) {
766 return this->writeInt32(-1);
767 }
768
769 return unsafeWriteTypedVector(*val, write_func);
770}
771
772template<typename T>
Christopher Wiley97f048d2015-11-19 06:49:05 -0800773status_t Parcel::readParcelableVector(std::vector<T>* val) const {
Casey Dahlinb9872622015-11-25 15:09:45 -0800774 return unsafeReadTypedVector<T, Parcelable>(val, &Parcel::readParcelable);
775}
776
777template<typename T>
778status_t Parcel::readParcelableVector(std::unique_ptr<std::vector<std::unique_ptr<T>>>* val) const {
Colin Cross4c62b4f2016-09-27 13:58:30 -0700779 const size_t start = dataPosition();
Casey Dahlinb9872622015-11-25 15:09:45 -0800780 int32_t size;
781 status_t status = readInt32(&size);
782 val->reset();
783
784 if (status != OK || size < 0) {
785 return status;
786 }
787
788 setDataPosition(start);
Janis Danisevskisf26a3ab2016-05-20 18:10:04 +0100789 val->reset(new std::vector<std::unique_ptr<T>>());
Casey Dahlinb9872622015-11-25 15:09:45 -0800790
Janis Danisevskisf26a3ab2016-05-20 18:10:04 +0100791 status = unsafeReadTypedVector(val->get(), &Parcel::readParcelable<T>);
Casey Dahlinb9872622015-11-25 15:09:45 -0800792
793 if (status != OK) {
794 val->reset();
795 }
796
797 return status;
798}
799
800template<typename T>
801status_t Parcel::readParcelable(std::unique_ptr<T>* parcelable) const {
Colin Cross4c62b4f2016-09-27 13:58:30 -0700802 const size_t start = dataPosition();
Casey Dahlinb9872622015-11-25 15:09:45 -0800803 int32_t present;
804 status_t status = readInt32(&present);
805 parcelable->reset();
806
807 if (status != OK || !present) {
808 return status;
809 }
810
811 setDataPosition(start);
812 parcelable->reset(new T());
813
814 status = readParcelable(parcelable->get());
815
816 if (status != OK) {
817 parcelable->reset();
818 }
819
820 return status;
821}
822
823template<typename T>
824status_t Parcel::writeNullableParcelable(const std::unique_ptr<T>& parcelable) {
825 return writeRawNullableParcelable(parcelable.get());
Christopher Wiley97f048d2015-11-19 06:49:05 -0800826}
827
828template<typename T>
829status_t Parcel::writeParcelableVector(const std::vector<T>& val) {
Casey Dahlinb9872622015-11-25 15:09:45 -0800830 return unsafeWriteTypedVector<T,const Parcelable&>(val, &Parcel::writeParcelable);
831}
832
833template<typename T>
834status_t Parcel::writeParcelableVector(const std::unique_ptr<std::vector<std::unique_ptr<T>>>& val) {
835 if (val.get() == nullptr) {
836 return this->writeInt32(-1);
837 }
838
839 return unsafeWriteTypedVector(*val, &Parcel::writeParcelable);
Christopher Wiley97f048d2015-11-19 06:49:05 -0800840}
841
Mathias Agopian8683fca2012-08-12 19:37:16 -0700842// ---------------------------------------------------------------------------
843
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800844inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel)
845{
846 parcel.print(to);
847 return to;
848}
849
850// ---------------------------------------------------------------------------
851
852// Generic acquire and release of objects.
853void acquire_object(const sp<ProcessState>& proc,
Ian Pedowitz68803072015-10-22 22:08:10 +0000854 const flat_binder_object& obj, const void* who);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800855void release_object(const sp<ProcessState>& proc,
Ian Pedowitz68803072015-10-22 22:08:10 +0000856 const flat_binder_object& obj, const void* who);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800857
858void flatten_binder(const sp<ProcessState>& proc,
859 const sp<IBinder>& binder, flat_binder_object* out);
860void flatten_binder(const sp<ProcessState>& proc,
861 const wp<IBinder>& binder, flat_binder_object* out);
862status_t unflatten_binder(const sp<ProcessState>& proc,
863 const flat_binder_object& flat, sp<IBinder>* out);
864status_t unflatten_binder(const sp<ProcessState>& proc,
865 const flat_binder_object& flat, wp<IBinder>* out);
866
867}; // namespace android
868
869// ---------------------------------------------------------------------------
870
871#endif // ANDROID_PARCEL_H