blob: be3e9b389d5f5abed5aa69df82a8f4bc46efdc9b [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
Casey Dahlin451ff582015-10-19 18:12:18 -070020#include <vector>
21
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <cutils/native_handle.h>
23#include <utils/Errors.h>
24#include <utils/RefBase.h>
25#include <utils/String16.h>
26#include <utils/Vector.h>
Mathias Agopian8683fca2012-08-12 19:37:16 -070027#include <utils/Flattenable.h>
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -080028#include <linux/binder.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029
30// ---------------------------------------------------------------------------
31namespace android {
32
Mathias Agopiane1424282013-07-29 21:24:40 -070033template <typename T> class Flattenable;
Mathias Agopian8683fca2012-08-12 19:37:16 -070034template <typename T> class LightFlattenable;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035class IBinder;
Brad Fitzpatrick70081a12010-07-27 09:49:11 -070036class IPCThreadState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037class ProcessState;
38class String8;
39class TextOutput;
40
Mathias Agopiane1424282013-07-29 21:24:40 -070041class Parcel {
Serban Constantinescuf683e012013-11-05 16:53:55 +000042 friend class IPCThreadState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043public:
Jeff Brown5707dbf2011-09-23 21:17:56 -070044 class ReadableBlob;
45 class WritableBlob;
46
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047 Parcel();
48 ~Parcel();
49
50 const uint8_t* data() const;
51 size_t dataSize() const;
52 size_t dataAvail() const;
53 size_t dataPosition() const;
54 size_t dataCapacity() const;
Dianne Hackborn8938ed22011-09-28 23:19:47 -040055
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056 status_t setDataSize(size_t size);
57 void setDataPosition(size_t pos) const;
58 status_t setDataCapacity(size_t size);
59
60 status_t setData(const uint8_t* buffer, size_t len);
61
Andreas Huber51faf462011-04-13 10:21:56 -070062 status_t appendFrom(const Parcel *parcel,
63 size_t start, size_t len);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064
Jeff Brown13b16042014-11-11 16:44:25 -080065 bool allowFds() const;
Dianne Hackborn7746cc32011-10-03 21:09:35 -070066 bool pushAllowFds(bool allowFds);
67 void restoreAllowFds(bool lastValue);
Dianne Hackborn8938ed22011-09-28 23:19:47 -040068
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 bool hasFileDescriptors() const;
70
Brad Fitzpatrick702ea9d2010-06-18 13:07:53 -070071 // Writes the RPC header.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080072 status_t writeInterfaceToken(const String16& interface);
Brad Fitzpatricka877cd82010-07-07 16:06:39 -070073
Brad Fitzpatrick702ea9d2010-06-18 13:07:53 -070074 // Parses the RPC header, returning true if the interface name
75 // in the header matches the expected interface from the caller.
Brad Fitzpatrick70081a12010-07-27 09:49:11 -070076 //
77 // Additionally, enforceInterface does part of the work of
78 // propagating the StrictMode policy mask, populating the current
79 // IPCThreadState, which as an optimization may optionally be
80 // passed in.
Brad Fitzpatricka877cd82010-07-07 16:06:39 -070081 bool enforceInterface(const String16& interface,
Brad Fitzpatrick70081a12010-07-27 09:49:11 -070082 IPCThreadState* threadState = NULL) const;
Brad Fitzpatrick702ea9d2010-06-18 13:07:53 -070083 bool checkInterface(IBinder*) const;
Mathias Agopian83c04462009-05-22 19:00:22 -070084
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085 void freeData();
86
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -080087private:
88 const binder_size_t* objects() const;
89
90public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091 size_t objectsCount() const;
92
93 status_t errorCheck() const;
94 void setError(status_t err);
95
96 status_t write(const void* data, size_t len);
97 void* writeInplace(size_t len);
98 status_t writeUnpadded(const void* data, size_t len);
99 status_t writeInt32(int32_t val);
Dan Stoza41a0f2f2014-12-01 10:01:10 -0800100 status_t writeUint32(uint32_t val);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101 status_t writeInt64(int64_t val);
Ronghua Wu2d13afd2015-03-16 11:11:07 -0700102 status_t writeUint64(uint64_t val);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103 status_t writeFloat(float val);
104 status_t writeDouble(double val);
105 status_t writeCString(const char* str);
106 status_t writeString8(const String8& str);
107 status_t writeString16(const String16& str);
108 status_t writeString16(const char16_t* str, size_t len);
109 status_t writeStrongBinder(const sp<IBinder>& val);
110 status_t writeWeakBinder(const wp<IBinder>& val);
Marco Nelissen5c0106e2013-10-16 10:57:51 -0700111 status_t writeInt32Array(size_t len, const int32_t *val);
Marco Nelissenf0190bf2014-03-13 14:17:40 -0700112 status_t writeByteArray(size_t len, const uint8_t *val);
Casey Dahlind6848f52015-10-15 15:44:59 -0700113 status_t writeBool(bool val);
114 status_t writeChar(char16_t val);
115 status_t writeByte(int8_t val);
Mathias Agopiane1424282013-07-29 21:24:40 -0700116
Casey Dahlin451ff582015-10-19 18:12:18 -0700117 status_t writeByteVector(const std::vector<int8_t>& val);
118 status_t writeInt32Vector(const std::vector<int32_t>& val);
119 status_t writeInt64Vector(const std::vector<int64_t>& val);
120 status_t writeFloatVector(const std::vector<float>& val);
121 status_t writeDoubleVector(const std::vector<double>& val);
122 status_t writeBoolVector(const std::vector<bool>& val);
123 status_t writeCharVector(const std::vector<char16_t>& val);
124 status_t writeString16Vector(const std::vector<String16>& val);
125
Mathias Agopiane1424282013-07-29 21:24:40 -0700126 template<typename T>
127 status_t write(const Flattenable<T>& val);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800128
Mathias Agopian8683fca2012-08-12 19:37:16 -0700129 template<typename T>
130 status_t write(const LightFlattenable<T>& val);
131
132
Mathias Agopiana47f02a2009-05-21 16:29:38 -0700133 // Place a native_handle into the parcel (the native_handle's file-
134 // descriptors are dup'ed, so it is safe to delete the native_handle
Casey Dahlin451ff582015-10-19 18:12:18 -0700135 // when this function returns).
Mathias Agopiana47f02a2009-05-21 16:29:38 -0700136 // Doesn't take ownership of the native_handle.
137 status_t writeNativeHandle(const native_handle* handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138
139 // Place a file descriptor into the parcel. The given fd must remain
140 // valid for the lifetime of the parcel.
Jeff Brown93ff1f92011-11-04 19:01:44 -0700141 // The Parcel does not take ownership of the given fd unless you ask it to.
142 status_t writeFileDescriptor(int fd, bool takeOwnership = false);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143
144 // Place a file descriptor into the parcel. A dup of the fd is made, which
145 // will be closed once the parcel is destroyed.
146 status_t writeDupFileDescriptor(int fd);
Jeff Brown5707dbf2011-09-23 21:17:56 -0700147
148 // Writes a blob to the parcel.
149 // If the blob is small, then it is stored in-place, otherwise it is
Jeff Brown13b16042014-11-11 16:44:25 -0800150 // transferred by way of an anonymous shared memory region. Prefer sending
151 // immutable blobs if possible since they may be subsequently transferred between
152 // processes without further copying whereas mutable blobs always need to be copied.
Jeff Brown5707dbf2011-09-23 21:17:56 -0700153 // The caller should call release() on the blob after writing its contents.
Jeff Brown13b16042014-11-11 16:44:25 -0800154 status_t writeBlob(size_t len, bool mutableCopy, WritableBlob* outBlob);
155
156 // Write an existing immutable blob file descriptor to the parcel.
157 // This allows the client to send the same blob to multiple processes
158 // as long as it keeps a dup of the blob file descriptor handy for later.
159 status_t writeDupImmutableBlobFileDescriptor(int fd);
Jeff Brown5707dbf2011-09-23 21:17:56 -0700160
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800161 status_t writeObject(const flat_binder_object& val, bool nullMetaData);
162
Brad Fitzpatrick837a0d02010-07-13 15:33:35 -0700163 // Like Parcel.java's writeNoException(). Just writes a zero int32.
164 // Currently the native implementation doesn't do any of the StrictMode
165 // stack gathering and serialization that the Java implementation does.
166 status_t writeNoException();
167
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800168 void remove(size_t start, size_t amt);
169
170 status_t read(void* outData, size_t len) const;
171 const void* readInplace(size_t len) const;
172 int32_t readInt32() const;
173 status_t readInt32(int32_t *pArg) const;
Dan Stoza41a0f2f2014-12-01 10:01:10 -0800174 uint32_t readUint32() const;
175 status_t readUint32(uint32_t *pArg) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800176 int64_t readInt64() const;
177 status_t readInt64(int64_t *pArg) const;
Ronghua Wu2d13afd2015-03-16 11:11:07 -0700178 uint64_t readUint64() const;
179 status_t readUint64(uint64_t *pArg) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800180 float readFloat() const;
181 status_t readFloat(float *pArg) const;
182 double readDouble() const;
183 status_t readDouble(double *pArg) const;
Andreas Huber84a6d042009-08-17 13:33:27 -0700184 intptr_t readIntPtr() const;
185 status_t readIntPtr(intptr_t *pArg) const;
Casey Dahlind6848f52015-10-15 15:44:59 -0700186 bool readBool() const;
187 status_t readBool(bool *pArg) const;
188 char16_t readChar() const;
189 status_t readChar(char16_t *pArg) const;
190 int8_t readByte() const;
191 status_t readByte(int8_t *pArg) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800192
193 const char* readCString() const;
194 String8 readString8() const;
195 String16 readString16() const;
Casey Dahlin451ff582015-10-19 18:12:18 -0700196 status_t readString16(String16* pArg) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800197 const char16_t* readString16Inplace(size_t* outLen) const;
198 sp<IBinder> readStrongBinder() const;
199 wp<IBinder> readWeakBinder() const;
Mathias Agopiane1424282013-07-29 21:24:40 -0700200
Casey Dahlin451ff582015-10-19 18:12:18 -0700201 status_t readByteVector(std::vector<int8_t>* val) const;
202 status_t readInt32Vector(std::vector<int32_t>* val) const;
203 status_t readInt64Vector(std::vector<int64_t>* val) const;
204 status_t readFloatVector(std::vector<float>* val) const;
205 status_t readDoubleVector(std::vector<double>* val) const;
206 status_t readBoolVector(std::vector<bool>* val) const;
207 status_t readCharVector(std::vector<char16_t>* val) const;
208 status_t readString16Vector(std::vector<String16>* val) const;
209
Mathias Agopiane1424282013-07-29 21:24:40 -0700210 template<typename T>
211 status_t read(Flattenable<T>& val) const;
Brad Fitzpatrick837a0d02010-07-13 15:33:35 -0700212
Mathias Agopian8683fca2012-08-12 19:37:16 -0700213 template<typename T>
214 status_t read(LightFlattenable<T>& val) const;
215
Brad Fitzpatrick837a0d02010-07-13 15:33:35 -0700216 // Like Parcel.java's readExceptionCode(). Reads the first int32
217 // off of a Parcel's header, returning 0 or the negative error
218 // code on exceptions, but also deals with skipping over rich
219 // response headers. Callers should use this to read & parse the
220 // response headers rather than doing it by hand.
221 int32_t readExceptionCode() const;
222
Mathias Agopiana47f02a2009-05-21 16:29:38 -0700223 // Retrieve native_handle from the parcel. This returns a copy of the
224 // parcel's native_handle (the caller takes ownership). The caller
225 // must free the native_handle with native_handle_close() and
226 // native_handle_delete().
227 native_handle* readNativeHandle() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800228
229
230 // Retrieve a file descriptor from the parcel. This returns the raw fd
231 // in the parcel, which you do not own -- use dup() to get your own copy.
232 int readFileDescriptor() const;
Jeff Brown5707dbf2011-09-23 21:17:56 -0700233
234 // Reads a blob from the parcel.
235 // The caller should call release() on the blob after reading its contents.
236 status_t readBlob(size_t len, ReadableBlob* outBlob) const;
237
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800238 const flat_binder_object* readObject(bool nullMetaData) const;
239
240 // Explicitly close all file descriptors in the parcel.
241 void closeFileDescriptors();
Dianne Hackborn7e790af2014-11-11 12:22:53 -0800242
243 // Debugging: get metrics on current allocations.
244 static size_t getGlobalAllocSize();
245 static size_t getGlobalAllocCount();
246
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800247private:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800248 typedef void (*release_func)(Parcel* parcel,
249 const uint8_t* data, size_t dataSize,
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800250 const binder_size_t* objects, size_t objectsSize,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800251 void* cookie);
252
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800253 uintptr_t ipcData() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800254 size_t ipcDataSize() const;
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800255 uintptr_t ipcObjects() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800256 size_t ipcObjectsCount() const;
257 void ipcSetDataReference(const uint8_t* data, size_t dataSize,
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800258 const binder_size_t* objects, size_t objectsCount,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800259 release_func relFunc, void* relCookie);
260
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800261public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800262 void print(TextOutput& to, uint32_t flags = 0) const;
Jeff Brown5707dbf2011-09-23 21:17:56 -0700263
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800264private:
265 Parcel(const Parcel& o);
266 Parcel& operator=(const Parcel& o);
267
268 status_t finishWrite(size_t len);
269 void releaseObjects();
270 void acquireObjects();
271 status_t growData(size_t len);
272 status_t restartWrite(size_t desired);
273 status_t continueWrite(size_t desired);
Serban Constantinescuf683e012013-11-05 16:53:55 +0000274 status_t writePointer(uintptr_t val);
275 status_t readPointer(uintptr_t *pArg) const;
276 uintptr_t readPointer() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800277 void freeDataNoInit();
278 void initState();
279 void scanForFds() const;
280
Andreas Huber84a6d042009-08-17 13:33:27 -0700281 template<class T>
282 status_t readAligned(T *pArg) const;
283
284 template<class T> T readAligned() const;
285
286 template<class T>
287 status_t writeAligned(T val);
288
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800289 status_t mError;
290 uint8_t* mData;
291 size_t mDataSize;
292 size_t mDataCapacity;
293 mutable size_t mDataPos;
Arve Hjønnevåg84e625a2014-01-28 20:12:59 -0800294 binder_size_t* mObjects;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800295 size_t mObjectsSize;
296 size_t mObjectsCapacity;
297 mutable size_t mNextObjectHint;
298
299 mutable bool mFdsKnown;
300 mutable bool mHasFds;
Dianne Hackborn8938ed22011-09-28 23:19:47 -0400301 bool mAllowFds;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800302
303 release_func mOwner;
304 void* mOwnerCookie;
Jeff Brown5707dbf2011-09-23 21:17:56 -0700305
306 class Blob {
307 public:
308 Blob();
309 ~Blob();
310
Jeff Brown13b16042014-11-11 16:44:25 -0800311 void clear();
Jeff Brown5707dbf2011-09-23 21:17:56 -0700312 void release();
313 inline size_t size() const { return mSize; }
Jeff Brown13b16042014-11-11 16:44:25 -0800314 inline int fd() const { return mFd; };
315 inline bool isMutable() const { return mMutable; }
Jeff Brown5707dbf2011-09-23 21:17:56 -0700316
317 protected:
Jeff Brown13b16042014-11-11 16:44:25 -0800318 void init(int fd, void* data, size_t size, bool isMutable);
Jeff Brown5707dbf2011-09-23 21:17:56 -0700319
Jeff Brown13b16042014-11-11 16:44:25 -0800320 int mFd; // owned by parcel so not closed when released
Jeff Brown5707dbf2011-09-23 21:17:56 -0700321 void* mData;
322 size_t mSize;
Jeff Brown13b16042014-11-11 16:44:25 -0800323 bool mMutable;
Jeff Brown5707dbf2011-09-23 21:17:56 -0700324 };
325
Mathias Agopiane1424282013-07-29 21:24:40 -0700326 class FlattenableHelperInterface {
327 protected:
328 ~FlattenableHelperInterface() { }
329 public:
330 virtual size_t getFlattenedSize() const = 0;
331 virtual size_t getFdCount() const = 0;
332 virtual status_t flatten(void* buffer, size_t size, int* fds, size_t count) const = 0;
333 virtual status_t unflatten(void const* buffer, size_t size, int const* fds, size_t count) = 0;
334 };
335
336 template<typename T>
337 class FlattenableHelper : public FlattenableHelperInterface {
338 friend class Parcel;
339 const Flattenable<T>& val;
340 explicit FlattenableHelper(const Flattenable<T>& val) : val(val) { }
341
342 public:
343 virtual size_t getFlattenedSize() const {
344 return val.getFlattenedSize();
345 }
346 virtual size_t getFdCount() const {
347 return val.getFdCount();
348 }
349 virtual status_t flatten(void* buffer, size_t size, int* fds, size_t count) const {
350 return val.flatten(buffer, size, fds, count);
351 }
352 virtual status_t unflatten(void const* buffer, size_t size, int const* fds, size_t count) {
353 return const_cast<Flattenable<T>&>(val).unflatten(buffer, size, fds, count);
354 }
355 };
356 status_t write(const FlattenableHelperInterface& val);
357 status_t read(FlattenableHelperInterface& val) const;
358
Jeff Brown5707dbf2011-09-23 21:17:56 -0700359public:
360 class ReadableBlob : public Blob {
361 friend class Parcel;
362 public:
363 inline const void* data() const { return mData; }
Jeff Brown13b16042014-11-11 16:44:25 -0800364 inline void* mutableData() { return isMutable() ? mData : NULL; }
Jeff Brown5707dbf2011-09-23 21:17:56 -0700365 };
366
367 class WritableBlob : public Blob {
368 friend class Parcel;
369 public:
370 inline void* data() { return mData; }
371 };
Dan Sandleraa5c2342015-04-10 10:08:45 -0400372
373private:
Adrian Roosd5c3a1c2015-10-22 16:12:53 -0700374 size_t mOpenAshmemSize;
Dan Sandleraa5c2342015-04-10 10:08:45 -0400375
376public:
Adrian Roos0aba1c92015-10-22 16:46:12 -0700377 // TODO: Remove once ABI can be changed.
Dan Sandleraa5c2342015-04-10 10:08:45 -0400378 size_t getBlobAshmemSize() const;
Adrian Roosd5c3a1c2015-10-22 16:12:53 -0700379 size_t getOpenAshmemSize() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800380};
381
382// ---------------------------------------------------------------------------
383
Mathias Agopian8683fca2012-08-12 19:37:16 -0700384template<typename T>
Mathias Agopiane1424282013-07-29 21:24:40 -0700385status_t Parcel::write(const Flattenable<T>& val) {
386 const FlattenableHelper<T> helper(val);
387 return write(helper);
388}
389
390template<typename T>
Mathias Agopian8683fca2012-08-12 19:37:16 -0700391status_t Parcel::write(const LightFlattenable<T>& val) {
Mathias Agopiane1424282013-07-29 21:24:40 -0700392 size_t size(val.getFlattenedSize());
Mathias Agopian8683fca2012-08-12 19:37:16 -0700393 if (!val.isFixedSize()) {
394 status_t err = writeInt32(size);
395 if (err != NO_ERROR) {
396 return err;
397 }
398 }
Mathias Agopian20985172012-08-31 14:25:22 -0700399 if (size) {
400 void* buffer = writeInplace(size);
Mathias Agopiane1424282013-07-29 21:24:40 -0700401 if (buffer == NULL)
402 return NO_MEMORY;
403 return val.flatten(buffer, size);
Mathias Agopian20985172012-08-31 14:25:22 -0700404 }
405 return NO_ERROR;
Mathias Agopian8683fca2012-08-12 19:37:16 -0700406}
407
408template<typename T>
Mathias Agopiane1424282013-07-29 21:24:40 -0700409status_t Parcel::read(Flattenable<T>& val) const {
410 FlattenableHelper<T> helper(val);
411 return read(helper);
412}
413
414template<typename T>
Mathias Agopian8683fca2012-08-12 19:37:16 -0700415status_t Parcel::read(LightFlattenable<T>& val) const {
416 size_t size;
417 if (val.isFixedSize()) {
Mathias Agopiane1424282013-07-29 21:24:40 -0700418 size = val.getFlattenedSize();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700419 } else {
420 int32_t s;
421 status_t err = readInt32(&s);
422 if (err != NO_ERROR) {
423 return err;
424 }
425 size = s;
426 }
Mathias Agopian20985172012-08-31 14:25:22 -0700427 if (size) {
428 void const* buffer = readInplace(size);
429 return buffer == NULL ? NO_MEMORY :
430 val.unflatten(buffer, size);
431 }
432 return NO_ERROR;
Mathias Agopian8683fca2012-08-12 19:37:16 -0700433}
434
435// ---------------------------------------------------------------------------
436
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800437inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel)
438{
439 parcel.print(to);
440 return to;
441}
442
443// ---------------------------------------------------------------------------
444
445// Generic acquire and release of objects.
446void acquire_object(const sp<ProcessState>& proc,
Adrian Roos0aba1c92015-10-22 16:46:12 -0700447 const flat_binder_object& obj, const void* who);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800448void release_object(const sp<ProcessState>& proc,
Adrian Roos0aba1c92015-10-22 16:46:12 -0700449 const flat_binder_object& obj, const void* who);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800450
451void flatten_binder(const sp<ProcessState>& proc,
452 const sp<IBinder>& binder, flat_binder_object* out);
453void flatten_binder(const sp<ProcessState>& proc,
454 const wp<IBinder>& binder, flat_binder_object* out);
455status_t unflatten_binder(const sp<ProcessState>& proc,
456 const flat_binder_object& flat, sp<IBinder>* out);
457status_t unflatten_binder(const sp<ProcessState>& proc,
458 const flat_binder_object& flat, wp<IBinder>* out);
459
460}; // namespace android
461
462// ---------------------------------------------------------------------------
463
464#endif // ANDROID_PARCEL_H