blob: f07e7e642ce3e62bb0a3db672b338dc61c1a3aa4 [file] [log] [blame]
Jiyong Park3656c3c2018-08-01 20:02:01 +09001/*
Will McVickerd7d18df2019-09-12 13:40:50 -07002 * Copyright (C) 2018, The Android Open Source Project
3 *
Jiyong Park3656c3c2018-08-01 20:02:01 +09004 * 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#include "aidl.h"
Jiyong Park3656c3c2018-08-01 20:02:01 +090018
19#include <map>
20#include <string>
21#include <vector>
22
Jiyong Park0cf03b12020-07-22 19:36:34 +090023#include <android-base/result.h>
Jiyong Parkf7534672019-08-12 22:06:22 +090024#include <android-base/strings.h>
Jooyung Hanb8a97772021-01-19 01:27:38 +090025#include <gtest/gtest.h>
Jiyong Parkf7534672019-08-12 22:06:22 +090026
Jooyung Han1f56b702021-02-11 13:16:15 +090027#include "aidl_dumpapi.h"
28#include "aidl_language.h"
29#include "import_resolver.h"
30#include "logging.h"
31#include "options.h"
32
Jiyong Park3656c3c2018-08-01 20:02:01 +090033namespace android {
34namespace aidl {
35
Jiyong Park0cf03b12020-07-22 19:36:34 +090036using android::base::Error;
37using android::base::Result;
Jooyung Han00073272020-11-27 14:20:20 +090038using android::base::StartsWith;
Jiyong Park3656c3c2018-08-01 20:02:01 +090039using std::map;
40using std::set;
41using std::string;
42using std::vector;
43
Jooyung Hanb8a97772021-01-19 01:27:38 +090044static std::string Dump(const AidlDefinedType& type) {
Jooyung Han1f56b702021-02-11 13:16:15 +090045 string code;
46 CodeWriterPtr out = CodeWriter::ForString(&code);
47 DumpVisitor visitor(*out);
48 type.DispatchVisit(visitor);
49 out->Close();
50 return code;
Jooyung Hanb8a97772021-01-19 01:27:38 +090051}
52
53// Uses each type's Dump() and GTest utility(EqHelper).
54static bool CheckEquality(const AidlDefinedType& older, const AidlDefinedType& newer) {
55 using testing::internal::EqHelper;
56 auto older_file = older.GetLocation().GetFile();
57 auto newer_file = newer.GetLocation().GetFile();
58 auto result = EqHelper::Compare(older_file.data(), newer_file.data(), Dump(older), Dump(newer));
59 if (!result) {
60 AIDL_ERROR(newer) << result.failure_message();
61 }
62 return result;
63}
64
Jooyung Han69ea4ba2020-10-29 15:33:37 +090065static vector<string> get_strict_annotations(const AidlAnnotatable& node) {
Steven Moreland7b6a7d92020-04-20 22:00:33 -070066 // This must be symmetrical (if you can add something, you must be able to
67 // remove it). The reason is that we have no way of knowing which interface a
68 // server serves and which interface a client serves (e.g. a callback
69 // interface). Note that this is being overly lenient. It makes sense for
70 // newer code to start accepting nullable things. However, here, we don't know
71 // if the client of an interface or the server of an interface is newer.
72 //
73 // Here are two examples to demonstrate this:
74 // - a new implementation might change so that it no longer returns null
75 // values (remove @nullable)
76 // - a new implementation might start accepting null values (add @nullable)
77 static const set<AidlAnnotation::Type> kIgnoreAnnotations{
78 AidlAnnotation::Type::NULLABLE,
Jooyung Han69ea4ba2020-10-29 15:33:37 +090079 // @JavaDerive doesn't affect read/write
Jooyung Han90345002020-10-23 15:28:53 +090080 AidlAnnotation::Type::JAVA_DERIVE,
Jeongik Chad0a10272020-08-06 16:33:36 +090081 AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE,
Jooyung Han69ea4ba2020-10-29 15:33:37 +090082 // @Backing for a enum type is checked by the enum checker
83 AidlAnnotation::Type::BACKING,
84 // @RustDerive doesn't affect read/write
85 AidlAnnotation::Type::RUST_DERIVE,
Jooyung Hanf8dbbcc2020-12-26 03:05:55 +090086 AidlAnnotation::Type::SUPPRESS_WARNINGS,
Steven Moreland7b6a7d92020-04-20 22:00:33 -070087 };
Jooyung Han69ea4ba2020-10-29 15:33:37 +090088 vector<string> annotations;
Steven Moreland7b6a7d92020-04-20 22:00:33 -070089 for (const AidlAnnotation& annotation : node.GetAnnotations()) {
Jooyung Han00073272020-11-27 14:20:20 +090090 if (kIgnoreAnnotations.find(annotation.GetType()) != kIgnoreAnnotations.end()) {
91 continue;
Steven Moreland7b6a7d92020-04-20 22:00:33 -070092 }
Jooyung Han00073272020-11-27 14:20:20 +090093 auto annotation_string = annotation.ToString();
94 // adding @Deprecated (with optional args) is okay
95 if (StartsWith(annotation_string, "@JavaPassthrough(annotation=\"@Deprecated")) {
96 continue;
97 }
98 annotations.push_back(annotation_string);
Steven Moreland7b6a7d92020-04-20 22:00:33 -070099 }
100 return annotations;
101}
102
Jiyong Park3656c3c2018-08-01 20:02:01 +0900103static bool have_compatible_annotations(const AidlAnnotatable& older,
104 const AidlAnnotatable& newer) {
Jooyung Han69ea4ba2020-10-29 15:33:37 +0900105 vector<string> olderAnnotations = get_strict_annotations(older);
106 vector<string> newerAnnotations = get_strict_annotations(newer);
107 sort(olderAnnotations.begin(), olderAnnotations.end());
108 sort(newerAnnotations.begin(), newerAnnotations.end());
Jeongik Cha3271ffa2018-12-04 15:19:20 +0900109 if (olderAnnotations != newerAnnotations) {
Jiyong Park3656c3c2018-08-01 20:02:01 +0900110 const string from = older.ToString().empty() ? "(empty)" : older.ToString();
111 const string to = newer.ToString().empty() ? "(empty)" : newer.ToString();
112 AIDL_ERROR(newer) << "Changed annotations: " << from << " to " << to;
113 return false;
114 }
115 return true;
116}
117
118static bool are_compatible_types(const AidlTypeSpecifier& older, const AidlTypeSpecifier& newer) {
119 bool compatible = true;
Jooyung Han965e31d2020-11-27 12:30:16 +0900120 if (older.Signature() != newer.Signature()) {
121 AIDL_ERROR(newer) << "Type changed: " << older.Signature() << " to " << newer.Signature()
122 << ".";
Jiyong Park3656c3c2018-08-01 20:02:01 +0900123 compatible = false;
124 }
125 compatible &= have_compatible_annotations(older, newer);
126 return compatible;
127}
128
Jooyung Han829ec7c2020-12-02 12:07:36 +0900129static bool are_compatible_constants(const AidlDefinedType& older, const AidlDefinedType& newer) {
Jooyung Han3f347ca2020-12-01 12:41:50 +0900130 bool compatible = true;
131
132 map<string, AidlConstantDeclaration*> new_constdecls;
133 for (const auto& c : newer.GetConstantDeclarations()) {
134 new_constdecls[c->GetName()] = &*c;
135 }
136
137 for (const auto& old_c : older.GetConstantDeclarations()) {
138 const auto found = new_constdecls.find(old_c->GetName());
139 if (found == new_constdecls.end()) {
140 AIDL_ERROR(old_c) << "Removed constant declaration: " << older.GetCanonicalName() << "."
141 << old_c->GetName();
142 compatible = false;
143 continue;
144 }
145
146 const auto new_c = found->second;
147 compatible &= are_compatible_types(old_c->GetType(), new_c->GetType());
148
Jooyung Hanfdaae1d2020-12-14 13:16:15 +0900149 const string old_value = old_c->GetValue().Literal();
150 const string new_value = new_c->GetValue().Literal();
Jooyung Han3f347ca2020-12-01 12:41:50 +0900151 if (old_value != new_value) {
152 AIDL_ERROR(newer) << "Changed constant value: " << older.GetCanonicalName() << "."
153 << old_c->GetName() << " from " << old_value << " to " << new_value << ".";
154 compatible = false;
155 }
156 }
157 return compatible;
158}
159
Jiyong Park3656c3c2018-08-01 20:02:01 +0900160static bool are_compatible_interfaces(const AidlInterface& older, const AidlInterface& newer) {
161 bool compatible = true;
Jiyong Park3656c3c2018-08-01 20:02:01 +0900162
163 map<string, AidlMethod*> new_methods;
164 for (const auto& m : newer.AsInterface()->GetMethods()) {
165 new_methods.emplace(m->Signature(), m.get());
166 }
167
168 for (const auto& old_m : older.AsInterface()->GetMethods()) {
169 const auto found = new_methods.find(old_m->Signature());
170 if (found == new_methods.end()) {
Steven Moreland4ee68632018-12-14 15:52:46 -0800171 AIDL_ERROR(old_m) << "Removed or changed method: " << older.GetCanonicalName() << "."
Jiyong Park3656c3c2018-08-01 20:02:01 +0900172 << old_m->Signature();
173 compatible = false;
174 continue;
175 }
176
177 // Compare IDs to detect method reordering. IDs are assigned by their
178 // textual order, so if there is an ID mismatch, that means reordering
179 // has happened.
180 const auto new_m = found->second;
Steven Moreland4ee68632018-12-14 15:52:46 -0800181
182 if (old_m->IsOneway() != new_m->IsOneway()) {
183 AIDL_ERROR(new_m) << "Oneway attribute " << (old_m->IsOneway() ? "removed" : "added") << ": "
184 << older.GetCanonicalName() << "." << old_m->Signature();
185 compatible = false;
186 }
187
Jiyong Park3656c3c2018-08-01 20:02:01 +0900188 if (old_m->GetId() != new_m->GetId()) {
189 AIDL_ERROR(new_m) << "Transaction ID changed: " << older.GetCanonicalName() << "."
190 << old_m->Signature() << " is changed from " << old_m->GetId() << " to "
191 << new_m->GetId() << ".";
192 compatible = false;
193 }
194
195 compatible &= are_compatible_types(old_m->GetType(), new_m->GetType());
196
197 const auto& old_args = old_m->GetArguments();
198 const auto& new_args = new_m->GetArguments();
199 // this is guaranteed because arguments are part of AidlMethod::Signature()
Steven Moreland21780812020-09-11 01:29:45 +0000200 AIDL_FATAL_IF(old_args.size() != new_args.size(), old_m);
Jiyong Park3656c3c2018-08-01 20:02:01 +0900201 for (size_t i = 0; i < old_args.size(); i++) {
202 const AidlArgument& old_a = *(old_args.at(i));
203 const AidlArgument& new_a = *(new_args.at(i));
204 compatible &= are_compatible_types(old_a.GetType(), new_a.GetType());
205
206 if (old_a.GetDirection() != new_a.GetDirection()) {
207 AIDL_ERROR(new_m) << "Direction changed: " << old_a.GetDirectionSpecifier() << " to "
208 << new_a.GetDirectionSpecifier() << ".";
209 compatible = false;
210 }
211 }
212 }
Jiyong Parka428d212018-08-29 22:26:30 +0900213
Jooyung Han3f347ca2020-12-01 12:41:50 +0900214 compatible = are_compatible_constants(older, newer) && compatible;
Jiyong Parka428d212018-08-29 22:26:30 +0900215
Jiyong Park3656c3c2018-08-01 20:02:01 +0900216 return compatible;
217}
218
Jooyung Han636fd2f2020-10-22 11:33:45 +0900219static bool HasZeroEnumerator(const AidlEnumDeclaration& enum_decl) {
220 return std::any_of(enum_decl.GetEnumerators().begin(), enum_decl.GetEnumerators().end(),
221 [&](const unique_ptr<AidlEnumerator>& enumerator) {
Jooyung Hanfdaae1d2020-12-14 13:16:15 +0900222 return enumerator->GetValue()->Literal() == "0";
Jooyung Han636fd2f2020-10-22 11:33:45 +0900223 });
224}
225
Jooyung Han829ec7c2020-12-02 12:07:36 +0900226static bool are_compatible_parcelables(const AidlDefinedType& older, const AidlTypenames&,
227 const AidlDefinedType& newer,
Jooyung Han636fd2f2020-10-22 11:33:45 +0900228 const AidlTypenames& new_types) {
Jiyong Park3656c3c2018-08-01 20:02:01 +0900229 const auto& old_fields = older.GetFields();
230 const auto& new_fields = newer.GetFields();
231 if (old_fields.size() > new_fields.size()) {
232 // you can add new fields only at the end
233 AIDL_ERROR(newer) << "Number of fields in " << older.GetCanonicalName() << " is reduced from "
234 << old_fields.size() << " to " << new_fields.size() << ".";
235 return false;
236 }
Devin Moorec7e47a32020-08-07 10:55:25 -0700237 if (newer.IsFixedSize() && old_fields.size() != new_fields.size()) {
238 AIDL_ERROR(newer) << "Number of fields in " << older.GetCanonicalName() << " is changed from "
239 << old_fields.size() << " to " << new_fields.size()
240 << ". This is an incompatible change for FixedSize types.";
241 return false;
242 }
Jiyong Park3656c3c2018-08-01 20:02:01 +0900243
244 bool compatible = true;
245 for (size_t i = 0; i < old_fields.size(); i++) {
Jiyong Parka468e2a2018-08-29 21:25:18 +0900246 const auto& old_field = old_fields.at(i);
247 const auto& new_field = new_fields.at(i);
248 compatible &= are_compatible_types(old_field->GetType(), new_field->GetType());
Jiyong Park3656c3c2018-08-01 20:02:01 +0900249
Jooyung Hanfdaae1d2020-12-14 13:16:15 +0900250 string old_value = old_field->GetDefaultValue() ? old_field->GetDefaultValue()->Literal() : "";
251 string new_value = new_field->GetDefaultValue() ? new_field->GetDefaultValue()->Literal() : "";
Jiyong Parka468e2a2018-08-29 21:25:18 +0900252 if (old_value != new_value) {
Steven Moreland370ed342020-04-28 18:14:39 -0700253 AIDL_ERROR(new_field) << "Changed default value: " << old_value << " to " << new_value << ".";
254 compatible = false;
255 }
256 }
257
Jiyong Parkb07d9932020-05-15 12:56:54 +0900258 // Reordering of fields is an incompatible change.
259 for (size_t i = 0; i < new_fields.size(); i++) {
260 const auto& new_field = new_fields.at(i);
261 auto found = std::find_if(old_fields.begin(), old_fields.end(), [&new_field](const auto& f) {
262 return new_field->GetName() == f->GetName();
263 });
264 if (found != old_fields.end()) {
265 size_t old_index = std::distance(old_fields.begin(), found);
266 if (old_index != i) {
267 AIDL_ERROR(new_field) << "Reordered " << new_field->GetName() << " from " << old_index
268 << " to " << i << ".";
269 compatible = false;
270 }
271 }
272 }
273
Steven Moreland370ed342020-04-28 18:14:39 -0700274 for (size_t i = old_fields.size(); i < new_fields.size(); i++) {
275 const auto& new_field = new_fields.at(i);
Jooyung Han53fb4242020-12-17 16:03:49 +0900276 if (new_field->HasUsefulDefaultValue()) {
Jooyung Han636fd2f2020-10-22 11:33:45 +0900277 continue;
278 }
279
280 // enum can't be nullable, but it's okay if it has 0 as a valid enumerator.
281 if (const auto& enum_decl = new_types.GetEnumDeclaration(new_field->GetType());
282 enum_decl != nullptr) {
283 if (HasZeroEnumerator(*enum_decl)) {
284 continue;
285 }
286
287 // TODO(b/142893595): Rephrase the message: "provide a default value or make sure ..."
288 AIDL_ERROR(new_field) << "Field '" << new_field->GetName() << "' of enum '"
289 << enum_decl->GetName()
290 << "' can't be initialized as '0'. Please make sure '"
291 << enum_decl->GetName() << "' has '0' as a valid value.";
292 compatible = false;
293 continue;
294 }
295
296 // Old API versions may suffer from the issue presented here. There is
297 // only a finite number in Android, which we must allow indefinitely.
298 struct HistoricalException {
299 std::string canonical;
300 std::string field;
301 };
302 static std::vector<HistoricalException> exceptions = {
303 {"android.net.DhcpResultsParcelable", "serverHostName"},
304 {"android.net.ResolverParamsParcel", "resolverOptions"},
305 };
306 bool excepted = false;
307 for (const HistoricalException& exception : exceptions) {
308 if (older.GetCanonicalName() == exception.canonical &&
309 new_field->GetName() == exception.field) {
310 excepted = true;
311 break;
312 }
313 }
314 if (excepted) continue;
315
316 AIDL_ERROR(new_field)
317 << "Field '" << new_field->GetName()
318 << "' does not have a useful default in some backends. Please either provide a default "
319 "value for this field or mark the field as @nullable. This value or a null value will "
320 "be used automatically when an old version of this parcelable is sent to a process "
321 "which understands a new version of this parcelable. In order to make sure your code "
322 "continues to be backwards compatible, make sure the default or null value does not "
323 "cause a semantic change to this parcelable.";
324 compatible = false;
Jiyong Park3656c3c2018-08-01 20:02:01 +0900325 }
Jooyung Han3f347ca2020-12-01 12:41:50 +0900326
327 compatible = are_compatible_constants(older, newer) && compatible;
328
Jiyong Park3656c3c2018-08-01 20:02:01 +0900329 return compatible;
330}
331
Daniel Norman85aed542019-08-21 12:01:14 -0700332static bool are_compatible_enums(const AidlEnumDeclaration& older,
333 const AidlEnumDeclaration& newer) {
334 if (!are_compatible_types(older.GetBackingType(), newer.GetBackingType())) {
335 AIDL_ERROR(newer) << "Changed backing types.";
336 return false;
337 }
338
339 std::map<std::string, const AidlConstantValue*> old_enum_map;
340 for (const auto& enumerator : older.GetEnumerators()) {
341 old_enum_map[enumerator->GetName()] = enumerator->GetValue();
342 }
343 std::map<std::string, const AidlConstantValue*> new_enum_map;
344 for (const auto& enumerator : newer.GetEnumerators()) {
345 new_enum_map[enumerator->GetName()] = enumerator->GetValue();
346 }
347
348 bool compatible = true;
349 for (const auto& [name, value] : old_enum_map) {
350 if (new_enum_map.find(name) == new_enum_map.end()) {
351 AIDL_ERROR(newer) << "Removed enumerator from " << older.GetCanonicalName() << ": " << name;
352 compatible = false;
353 continue;
354 }
Jooyung Hanfdaae1d2020-12-14 13:16:15 +0900355 const string old_value = old_enum_map[name]->Literal();
356 const string new_value = new_enum_map[name]->Literal();
Daniel Norman85aed542019-08-21 12:01:14 -0700357 if (old_value != new_value) {
358 AIDL_ERROR(newer) << "Changed enumerator value: " << older.GetCanonicalName() << "::" << name
359 << " from " << old_value << " to " << new_value << ".";
360 compatible = false;
361 }
362 }
363 return compatible;
364}
365
Jiyong Park0cf03b12020-07-22 19:36:34 +0900366static Result<AidlTypenames> load_from_dir(const Options& options, const IoDelegate& io_delegate,
367 const std::string& dir) {
368 AidlTypenames typenames;
369 for (const auto& file : io_delegate.ListFiles(dir)) {
370 if (!android::base::EndsWith(file, ".aidl")) continue;
371 if (internals::load_and_validate_aidl(file, options, io_delegate, &typenames,
372 nullptr /* imported_files */) != AidlError::OK) {
373 AIDL_ERROR(file) << "Failed to read.";
374 return Error();
375 }
376 }
377 return typenames;
378}
379
Jiyong Park3656c3c2018-08-01 20:02:01 +0900380bool check_api(const Options& options, const IoDelegate& io_delegate) {
Steven Moreland21780812020-09-11 01:29:45 +0000381 AIDL_FATAL_IF(!options.IsStructured(), AIDL_LOCATION_HERE);
382 AIDL_FATAL_IF(options.InputFiles().size() != 2, AIDL_LOCATION_HERE)
383 << "--checkapi requires two inputs "
384 << "but got " << options.InputFiles().size();
Jiyong Park0cf03b12020-07-22 19:36:34 +0900385 auto old_tns = load_from_dir(options, io_delegate, options.InputFiles().at(0));
386 if (!old_tns.ok()) {
Jiyong Park3656c3c2018-08-01 20:02:01 +0900387 return false;
388 }
Jiyong Park0cf03b12020-07-22 19:36:34 +0900389 auto new_tns = load_from_dir(options, io_delegate, options.InputFiles().at(1));
390 if (!new_tns.ok()) {
Jiyong Park3656c3c2018-08-01 20:02:01 +0900391 return false;
392 }
Jiyong Parkf7534672019-08-12 22:06:22 +0900393
Jooyung Hanb8a97772021-01-19 01:27:38 +0900394 const Options::CheckApiLevel level = options.GetCheckApiLevel();
395
Jiyong Park0cf03b12020-07-22 19:36:34 +0900396 std::vector<AidlDefinedType*> old_types = old_tns->AllDefinedTypes();
397 std::vector<AidlDefinedType*> new_types = new_tns->AllDefinedTypes();
Jiyong Park3656c3c2018-08-01 20:02:01 +0900398
Jooyung Hanb8a97772021-01-19 01:27:38 +0900399 bool compatible = true;
400
401 if (level == Options::CheckApiLevel::EQUAL) {
402 std::set<string> old_type_names;
403 for (const auto t : old_types) {
404 old_type_names.insert(t->GetCanonicalName());
405 }
406 for (const auto new_type : new_types) {
407 const auto found = old_type_names.find(new_type->GetCanonicalName());
408 if (found == old_type_names.end()) {
409 AIDL_ERROR(new_type) << "Added type: " << new_type->GetCanonicalName();
410 compatible = false;
411 continue;
412 }
413 }
414 }
415
Jiyong Park3656c3c2018-08-01 20:02:01 +0900416 map<string, AidlDefinedType*> new_map;
417 for (const auto t : new_types) {
418 new_map.emplace(t->GetCanonicalName(), t);
419 }
420
Jiyong Park3656c3c2018-08-01 20:02:01 +0900421 for (const auto old_type : old_types) {
422 const auto found = new_map.find(old_type->GetCanonicalName());
423 if (found == new_map.end()) {
424 AIDL_ERROR(old_type) << "Removed type: " << old_type->GetCanonicalName();
425 compatible = false;
426 continue;
427 }
428 const auto new_type = found->second;
429
Jooyung Hanb8a97772021-01-19 01:27:38 +0900430 if (level == Options::CheckApiLevel::EQUAL) {
431 if (!CheckEquality(*old_type, *new_type)) {
432 compatible = false;
433 }
434 continue;
435 }
436
Devin Mooredb7ac512020-08-07 11:17:36 -0700437 if (!have_compatible_annotations(*old_type, *new_type)) {
438 compatible = false;
439 }
Daniel Norman85aed542019-08-21 12:01:14 -0700440 if (old_type->AsInterface() != nullptr) {
441 if (new_type->AsInterface() == nullptr) {
442 AIDL_ERROR(new_type) << "Type mismatch: " << old_type->GetCanonicalName()
443 << " is changed from " << old_type->GetPreprocessDeclarationName()
444 << " to " << new_type->GetPreprocessDeclarationName();
445 compatible = false;
446 continue;
447 }
Jiyong Park3656c3c2018-08-01 20:02:01 +0900448 compatible &=
449 are_compatible_interfaces(*(old_type->AsInterface()), *(new_type->AsInterface()));
Daniel Norman85aed542019-08-21 12:01:14 -0700450 } else if (old_type->AsStructuredParcelable() != nullptr) {
451 if (new_type->AsStructuredParcelable() == nullptr) {
452 AIDL_ERROR(new_type) << "Parcelable" << new_type->GetCanonicalName()
453 << " is not structured. ";
454 compatible = false;
455 continue;
456 }
Jooyung Han636fd2f2020-10-22 11:33:45 +0900457 compatible &= are_compatible_parcelables(*(old_type->AsStructuredParcelable()), *old_tns,
458 *(new_type->AsStructuredParcelable()), *new_tns);
Jooyung Han2946afc2020-10-05 20:29:16 +0900459 } else if (old_type->AsUnionDeclaration() != nullptr) {
460 if (new_type->AsUnionDeclaration() == nullptr) {
461 AIDL_ERROR(new_type) << "Type mismatch: " << old_type->GetCanonicalName()
462 << " is changed from " << old_type->GetPreprocessDeclarationName()
463 << " to " << new_type->GetPreprocessDeclarationName();
464 compatible = false;
465 continue;
466 }
Jooyung Han636fd2f2020-10-22 11:33:45 +0900467 compatible &= are_compatible_parcelables(*(old_type->AsUnionDeclaration()), *old_tns,
468 *(new_type->AsUnionDeclaration()), *new_tns);
Daniel Norman85aed542019-08-21 12:01:14 -0700469 } else if (old_type->AsEnumDeclaration() != nullptr) {
470 if (new_type->AsEnumDeclaration() == nullptr) {
471 AIDL_ERROR(new_type) << "Type mismatch: " << old_type->GetCanonicalName()
472 << " is changed from " << old_type->GetPreprocessDeclarationName()
473 << " to " << new_type->GetPreprocessDeclarationName();
474 compatible = false;
475 continue;
476 }
477 compatible &=
478 are_compatible_enums(*(old_type->AsEnumDeclaration()), *(new_type->AsEnumDeclaration()));
479 } else {
480 AIDL_ERROR(old_type) << "Unsupported type " << old_type->GetPreprocessDeclarationName()
481 << " for " << old_type->GetCanonicalName();
482 compatible = false;
Jiyong Park3656c3c2018-08-01 20:02:01 +0900483 }
484 }
485
486 return compatible;
487}
488
489} // namespace aidl
490} // namespace android