checkapi: allow adding @Deprecated
@JavaPassthrough(annotation="@Deprecated") is now considered as a
compatible change. Checkapi ignores it.
Bug: 174327111
Test: aidl_unittests
Change-Id: I3e43736732929baf63393b3c0bf2bdcaf412e84e
diff --git a/aidl_checkapi.cpp b/aidl_checkapi.cpp
index 9d9387c..d752f44 100644
--- a/aidl_checkapi.cpp
+++ b/aidl_checkapi.cpp
@@ -32,6 +32,7 @@
using android::base::Error;
using android::base::Result;
+using android::base::StartsWith;
using std::map;
using std::set;
using std::string;
@@ -61,9 +62,15 @@
};
vector<string> annotations;
for (const AidlAnnotation& annotation : node.GetAnnotations()) {
- if (kIgnoreAnnotations.find(annotation.GetType()) == kIgnoreAnnotations.end()) {
- annotations.push_back(annotation.ToString());
+ if (kIgnoreAnnotations.find(annotation.GetType()) != kIgnoreAnnotations.end()) {
+ continue;
}
+ auto annotation_string = annotation.ToString();
+ // adding @Deprecated (with optional args) is okay
+ if (StartsWith(annotation_string, "@JavaPassthrough(annotation=\"@Deprecated")) {
+ continue;
+ }
+ annotations.push_back(annotation_string);
}
return annotations;
}
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 2a5ee16..7bf63d9 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -1989,6 +1989,17 @@
EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_));
}
+TEST_F(AidlTestCompatibleChanges, OkayToDeprecate) {
+ io_delegate_.SetFileContents("old/p/Foo.aidl",
+ "package p;"
+ "parcelable Foo {}");
+ io_delegate_.SetFileContents("new/p/Foo.aidl",
+ "package p;"
+ "@JavaPassthrough(annotation=\"@Deprecated\")"
+ "parcelable Foo {}");
+ EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_));
+}
+
TEST_F(AidlTestCompatibleChanges, NewFieldOfNewType) {
io_delegate_.SetFileContents("old/p/Data.aidl",
"package p;"