Make UidRangeParcel frozen

older c++ interface has a problem with newer parcelable in specific
case. to prevent problem, make the problematic parcelable frozen

Test: atest aidl_unittests
Bug: 186720556
Change-Id: I955ed7dbc07c6e4064fa2175e068ec9ce67044bb
diff --git a/aidl_checkapi.cpp b/aidl_checkapi.cpp
index 08d1798..47733c1 100644
--- a/aidl_checkapi.cpp
+++ b/aidl_checkapi.cpp
@@ -262,6 +262,15 @@
     return false;
   }
 
+  // android.net.UidRangeParcel should be frozen to prevent breakage in legacy (b/186720556)
+  if (older.GetCanonicalName() == "android.net.UidRangeParcel" &&
+      old_fields.size() != new_fields.size()) {
+    AIDL_ERROR(newer) << "Number of fields in " << older.GetCanonicalName() << " is changed from "
+                      << old_fields.size() << " to " << new_fields.size()
+                      << ". But it is forbidden because of legacy support.";
+    return false;
+  }
+
   bool compatible = true;
   for (size_t i = 0; i < old_fields.size(); i++) {
     const auto& old_field = old_fields.at(i);
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 0e3a235..1e81de7 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -2691,6 +2691,21 @@
   EXPECT_EQ(expected_stderr, GetCapturedStderr());
 }
 
+TEST_F(AidlTestIncompatibleChanges, UidRangeParcelAddedField) {
+  const string expected_stderr =
+      "ERROR: new/android/net/UidRangeParcel.aidl:1.32-47: Number of fields in "
+      "android.net.UidRangeParcel is changed from 1 to 2. "
+      "But it is forbidden because of legacy support.\n";
+  io_delegate_.SetFileContents("old/android/net/UidRangeParcel.aidl",
+                               "package android.net; parcelable UidRangeParcel { int A = 1; }");
+  io_delegate_.SetFileContents(
+      "new/android/net/UidRangeParcel.aidl",
+      "package android.net; parcelable UidRangeParcel { int A = 1; int B = 2; }");
+  CaptureStderr();
+  EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_));
+  EXPECT_EQ(expected_stderr, GetCapturedStderr());
+}
+
 TEST_F(AidlTestIncompatibleChanges, FixedSizeRemovedField) {
   const string expected_stderr =
       "ERROR: new/p/Foo.aidl:1.33-37: Number of fields in p.Foo is reduced from 2 to 1.\n";