• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <android/binder_parcel.h>
20 
21 #include <sys/cdefs.h>
22 
23 #include <binder/Parcel.h>
24 #include "ibinder_internal.h"
25 
26 struct AParcel {
getAParcel27     const ::android::Parcel* get() const { return mParcel; }
getAParcel28     ::android::Parcel* get() { return mParcel; }
29 
AParcelAParcel30     explicit AParcel(AIBinder* binder) : AParcel(binder, new ::android::Parcel, true /*owns*/) {}
AParcelAParcel31     AParcel(AIBinder* binder, ::android::Parcel* parcel, bool owns)
32         : mBinder(binder), mParcel(parcel), mOwns(owns) {}
33 
~AParcelAParcel34     ~AParcel() {
35         if (mOwns) {
36             delete mParcel;
37         }
38     }
39 
readOnlyAParcel40     static const AParcel readOnly(AIBinder* binder, const ::android::Parcel* parcel) {
41         return AParcel(binder, const_cast<::android::Parcel*>(parcel), false);
42     }
43 
getBinderAParcel44     const AIBinder* getBinder() { return mBinder; }
45 
46    private:
47     // This object is associated with a calls to a specific AIBinder object. This is used for sanity
48     // checking to make sure that a parcel is one that is expected.
49     const AIBinder* mBinder;
50 
51     ::android::Parcel* mParcel;
52     bool mOwns;
53 };
54