From 3f347ca3625b82dea5207919fe1816da3924a49a Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Tue, 1 Dec 2020 12:41:50 +0900 Subject: support const in parcelable/union const values are now available in parcelable/union as well as interface. Bug: 173225412 Test: CtsNdkBinderTestCases Test: aidl_unittests Test: aidl_integration_test Change-Id: Ifab53c6b0e6674710f1206b7d2e2ca677d5430c6 --- aidl_checkapi.cpp | 61 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 24 deletions(-) (limited to 'aidl_checkapi.cpp') diff --git a/aidl_checkapi.cpp b/aidl_checkapi.cpp index d752f449..2dfbdae9 100644 --- a/aidl_checkapi.cpp +++ b/aidl_checkapi.cpp @@ -101,6 +101,39 @@ static bool are_compatible_types(const AidlTypeSpecifier& older, const AidlTypeS return compatible; } +template +static bool are_compatible_constants(const TypeWithConstants& older, + const TypeWithConstants& newer) { + bool compatible = true; + + map new_constdecls; + for (const auto& c : newer.GetConstantDeclarations()) { + new_constdecls[c->GetName()] = &*c; + } + + for (const auto& old_c : older.GetConstantDeclarations()) { + const auto found = new_constdecls.find(old_c->GetName()); + if (found == new_constdecls.end()) { + AIDL_ERROR(old_c) << "Removed constant declaration: " << older.GetCanonicalName() << "." + << old_c->GetName(); + compatible = false; + continue; + } + + const auto new_c = found->second; + compatible &= are_compatible_types(old_c->GetType(), new_c->GetType()); + + const string old_value = old_c->ValueString(AidlConstantValueDecorator); + const string new_value = new_c->ValueString(AidlConstantValueDecorator); + if (old_value != new_value) { + AIDL_ERROR(newer) << "Changed constant value: " << older.GetCanonicalName() << "." + << old_c->GetName() << " from " << old_value << " to " << new_value << "."; + compatible = false; + } + } + return compatible; +} + static bool are_compatible_interfaces(const AidlInterface& older, const AidlInterface& newer) { bool compatible = true; @@ -155,31 +188,8 @@ static bool are_compatible_interfaces(const AidlInterface& older, const AidlInte } } - map new_constdecls; - for (const auto& c : newer.AsInterface()->GetConstantDeclarations()) { - new_constdecls.emplace(c->GetName(), c.get()); - } + compatible = are_compatible_constants(older, newer) && compatible; - for (const auto& old_c : older.AsInterface()->GetConstantDeclarations()) { - const auto found = new_constdecls.find(old_c->GetName()); - if (found == new_constdecls.end()) { - AIDL_ERROR(old_c) << "Removed constant declaration: " << older.GetCanonicalName() << "." - << old_c->GetName(); - compatible = false; - continue; - } - - const auto new_c = found->second; - compatible &= are_compatible_types(old_c->GetType(), new_c->GetType()); - - const string old_value = old_c->ValueString(AidlConstantValueDecorator); - const string new_value = new_c->ValueString(AidlConstantValueDecorator); - if (old_value != new_value) { - AIDL_ERROR(newer) << "Changed constant value: " << older.GetCanonicalName() << "." - << old_c->GetName() << " from " << old_value << " to " << new_value << "."; - compatible = false; - } - } return compatible; } @@ -310,6 +320,9 @@ static bool are_compatible_parcelables(const ParcelableType& older, const AidlTy "cause a semantic change to this parcelable."; compatible = false; } + + compatible = are_compatible_constants(older, newer) && compatible; + return compatible; } -- cgit v1.2.3