1 /*
2  * Copyright (C) 2015 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 <vector>
20 
21 #include <utils/Errors.h>
22 #include <utils/String16.h>
23 
24 #include <binder/Common.h>
25 
26 namespace android {
27 
28 class Parcel;
29 
30 #if defined(__clang__)
31 #pragma clang diagnostic push
32 #pragma clang diagnostic ignored "-Wweak-vtables"
33 #endif
34 
35 // Abstract interface of all parcelables.
36 class LIBBINDER_EXPORTED Parcelable {
37 public:
38     virtual ~Parcelable() = default;
39 
40     Parcelable() = default;
41     Parcelable(const Parcelable&) = default;
42 
43     // Write |this| parcelable to the given |parcel|.  Keep in mind that
44     // implementations of writeToParcel must be manually kept in sync
45     // with readFromParcel and the Java equivalent versions of these methods.
46     //
47     // Returns android::OK on success and an appropriate error otherwise.
48     virtual status_t writeToParcel(Parcel* parcel) const = 0;
49 
50     // Read data from the given |parcel| into |this|.  After readFromParcel
51     // completes, |this| should have equivalent state to the object that
52     // wrote itself to the parcel.
53     //
54     // Returns android::OK on success and an appropriate error otherwise.
55     virtual status_t readFromParcel(const Parcel* parcel) = 0;
56 
57     // WARNING: for use by auto-generated code only (AIDL). Should not be used
58     // manually, or there is a risk of breaking CTS, GTS, VTS, or CTS-on-GSI
59     // tests.
60     enum class Stability : int32_t {
61         STABILITY_LOCAL,
62         STABILITY_VINTF, // corresponds to @VintfStability
63     };
64 
65     // 'Stable' means this parcelable is guaranteed to be stable for multiple
66     // years.
67     // It must be guaranteed by setting stability field in aidl_interface.
68     // WARNING: getStability() is only expected to be overridden by auto-generated
69     // code. Returns true if this parcelable is stable.
getStability()70     virtual Stability getStability() const { return Stability::STABILITY_LOCAL; }
71 };  // class Parcelable
72 
73 #if defined(__clang__)
74 #pragma clang diagnostic pop
75 #endif
76 
77 }  // namespace android
78