Allow parcelable defined from framework in stable aidl
To use stable aidl, every parcelable must be a structured parcelable.
But there is a need for the parcelable class defined in framework.
In this case, parcelable with @JavaOnlyStableParcelable is allowed.
For example,
- Foo.aidl:
@JavaOnlyStableParcelable parcelable Foo;
aidl --structured Foo.aidl succeed
Bug: 126469673
Test: m -j
Test: aidl with @JavaOnlyStableParcelable and --structured option
Change-Id: I634646e6d08746316477877600e496f2189a3f40
diff --git a/aidl_language.cpp b/aidl_language.cpp
index d4d26b8..9ee3d05 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -72,8 +72,10 @@
static const string kUtf8InCpp("utf8InCpp");
static const string kUnsupportedAppUsage("UnsupportedAppUsage");
static const string kSystemApi("SystemApi");
+static const string kStableParcelable("JavaOnlyStableParcelable");
-static const set<string> kAnnotationNames{kNullable, kUtf8InCpp, kUnsupportedAppUsage, kSystemApi};
+static const set<string> kAnnotationNames{kNullable, kUtf8InCpp, kUnsupportedAppUsage, kSystemApi,
+ kStableParcelable};
AidlAnnotation* AidlAnnotation::Parse(const AidlLocation& location, const string& name) {
if (kAnnotationNames.find(name) == kAnnotationNames.end()) {
@@ -120,6 +122,10 @@
return HasAnnotation(annotations_, kSystemApi);
}
+bool AidlAnnotatable::IsStableParcelable() const {
+ return HasAnnotation(annotations_, kStableParcelable);
+}
+
string AidlAnnotatable::ToString() const {
vector<string> ret;
for (const auto& a : annotations_) {
@@ -621,6 +627,24 @@
}
}
+bool AidlParcelable::CheckValid(const AidlTypenames&) const {
+ static const std::set<string> allowed{kStableParcelable};
+ for (const auto& v : GetAnnotations()) {
+ if (allowed.find(v.GetName()) == allowed.end()) {
+ std::ostringstream stream;
+ stream << "Unstructured parcelable can contain only";
+ for (const string& kv : allowed) {
+ stream << " " << kv;
+ }
+ stream << ".";
+ AIDL_ERROR(this) << stream.str();
+ return false;
+ }
+ }
+
+ return true;
+}
+
void AidlParcelable::Write(CodeWriter* writer) const {
writer->Write("parcelable %s ;\n", GetName().c_str());
}