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