Add a structured parcelable to a versioned test

This is a preparation to add a meaningful test to reveal the bug.

The parcelable Foo is empty in V1 and has a member in V2, which we need
to support as a compatible change.

Bug: 186632725
Test: aidl_unittests
Test: aidl_integration_test
Change-Id: I053906132c7266484d43c44df57460b357c4fc2e
diff --git a/aidl_api/aidl-test-versioned-interface/1/.hash b/aidl_api/aidl-test-versioned-interface/1/.hash
index e802595..62b59a3 100644
--- a/aidl_api/aidl-test-versioned-interface/1/.hash
+++ b/aidl_api/aidl-test-versioned-interface/1/.hash
@@ -1 +1 @@
-796b4ab269d476662bed4ab57092ed000e48d5d7
+4b32bf2134c87894404e935d52c5c64886f23215
diff --git a/aidl_api/aidl-test-versioned-interface/1/android/aidl/versioned/tests/Foo.aidl b/aidl_api/aidl-test-versioned-interface/1/android/aidl/versioned/tests/Foo.aidl
new file mode 100644
index 0000000..da1c01b
--- /dev/null
+++ b/aidl_api/aidl-test-versioned-interface/1/android/aidl/versioned/tests/Foo.aidl
@@ -0,0 +1,20 @@
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
+// edit this file. It looks like you are doing that because you have modified
+// an AIDL interface in a backward-incompatible way, e.g., deleting a function
+// from an interface or a field from a parcelable and it broke the build. That
+// breakage is intended.
+//
+// You must not make a backward incompatible changes to the AIDL files built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.aidl.versioned.tests;
+parcelable Foo {
+}
diff --git a/aidl_api/aidl-test-versioned-interface/1/android/aidl/versioned/tests/IFooInterface.aidl b/aidl_api/aidl-test-versioned-interface/1/android/aidl/versioned/tests/IFooInterface.aidl
index ca832b9..c9256ff 100644
--- a/aidl_api/aidl-test-versioned-interface/1/android/aidl/versioned/tests/IFooInterface.aidl
+++ b/aidl_api/aidl-test-versioned-interface/1/android/aidl/versioned/tests/IFooInterface.aidl
@@ -19,4 +19,5 @@
 interface IFooInterface {
   void originalApi();
   @utf8InCpp String acceptUnionAndReturnString(in android.aidl.versioned.tests.BazUnion u);
+  void callWithFoo(out android.aidl.versioned.tests.Foo outFoo);
 }
diff --git a/aidl_api/aidl-test-versioned-interface/2/.hash b/aidl_api/aidl-test-versioned-interface/2/.hash
index dd11e30..6abdf06 100644
--- a/aidl_api/aidl-test-versioned-interface/2/.hash
+++ b/aidl_api/aidl-test-versioned-interface/2/.hash
@@ -1 +1 @@
-508a201b25adaf663c1928022a02d0fe86edb6fe
+4a2144685c9079cf47c4289b697db9b8117fe4db
diff --git a/aidl_api/aidl-test-versioned-interface/2/android/aidl/versioned/tests/Foo.aidl b/aidl_api/aidl-test-versioned-interface/2/android/aidl/versioned/tests/Foo.aidl
new file mode 100644
index 0000000..bd8beb6
--- /dev/null
+++ b/aidl_api/aidl-test-versioned-interface/2/android/aidl/versioned/tests/Foo.aidl
@@ -0,0 +1,21 @@
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
+// edit this file. It looks like you are doing that because you have modified
+// an AIDL interface in a backward-incompatible way, e.g., deleting a function
+// from an interface or a field from a parcelable and it broke the build. That
+// breakage is intended.
+//
+// You must not make a backward incompatible changes to the AIDL files built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.aidl.versioned.tests;
+parcelable Foo {
+  int intDefault42 = 42;
+}
diff --git a/aidl_api/aidl-test-versioned-interface/2/android/aidl/versioned/tests/IFooInterface.aidl b/aidl_api/aidl-test-versioned-interface/2/android/aidl/versioned/tests/IFooInterface.aidl
index d9c2446..a801572 100644
--- a/aidl_api/aidl-test-versioned-interface/2/android/aidl/versioned/tests/IFooInterface.aidl
+++ b/aidl_api/aidl-test-versioned-interface/2/android/aidl/versioned/tests/IFooInterface.aidl
@@ -19,5 +19,6 @@
 interface IFooInterface {
   void originalApi();
   @utf8InCpp String acceptUnionAndReturnString(in android.aidl.versioned.tests.BazUnion u);
+  void callWithFoo(out android.aidl.versioned.tests.Foo outFoo);
   void newApi();
 }
diff --git a/aidl_api/aidl-test-versioned-interface/current/android/aidl/versioned/tests/Foo.aidl b/aidl_api/aidl-test-versioned-interface/current/android/aidl/versioned/tests/Foo.aidl
new file mode 100644
index 0000000..dad05e6
--- /dev/null
+++ b/aidl_api/aidl-test-versioned-interface/current/android/aidl/versioned/tests/Foo.aidl
@@ -0,0 +1,22 @@
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+//     the interface (from the latest frozen version), the build system will
+//     prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.aidl.versioned.tests;
+parcelable Foo {
+  int intDefault42 = 42;
+}
diff --git a/aidl_api/aidl-test-versioned-interface/current/android/aidl/versioned/tests/IFooInterface.aidl b/aidl_api/aidl-test-versioned-interface/current/android/aidl/versioned/tests/IFooInterface.aidl
index fa709a6..80f1c3a 100644
--- a/aidl_api/aidl-test-versioned-interface/current/android/aidl/versioned/tests/IFooInterface.aidl
+++ b/aidl_api/aidl-test-versioned-interface/current/android/aidl/versioned/tests/IFooInterface.aidl
@@ -20,5 +20,6 @@
 interface IFooInterface {
   void originalApi();
   @utf8InCpp String acceptUnionAndReturnString(in android.aidl.versioned.tests.BazUnion u);
+  void callWithFoo(out android.aidl.versioned.tests.Foo outFoo);
   void newApi();
 }
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index f1dce8d..0e3a235 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -283,6 +283,12 @@
   EXPECT_EQ(expected_stderr, GetCapturedStderr());
 }
 
+TEST_P(AidlTest, AcceptsEmptyParcelable) {
+  CaptureStderr();
+  EXPECT_NE(nullptr, Parse("Foo.aidl", "parcelable Foo {}", typenames_, GetLanguage()));
+  EXPECT_EQ("", GetCapturedStderr());
+}
+
 TEST_P(AidlTest, RejectsDuplicatedAnnotationParams) {
   const string method = "package a; interface IFoo { @UnsupportedAppUsage(foo=1, foo=2)void f(); }";
   const string expected_stderr = "ERROR: a/IFoo.aidl:1.56-62: Trying to redefine parameter foo.\n";
@@ -2004,6 +2010,19 @@
   EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_));
 }
 
+TEST_F(AidlTestCompatibleChanges, NewField2) {
+  io_delegate_.SetFileContents("old/p/Data.aidl",
+                               "package p;"
+                               "parcelable Data {"
+                               "}");
+  io_delegate_.SetFileContents("new/p/Data.aidl",
+                               "package p;"
+                               "parcelable Data {"
+                               "  int foo = 0;"
+                               "}");
+  EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_));
+}
+
 TEST_F(AidlTestCompatibleChanges, NewEnumerator) {
   io_delegate_.SetFileContents("old/p/Enum.aidl",
                                "package p;"
diff --git a/tests/aidl_test_client_versioned_interface.cpp b/tests/aidl_test_client_versioned_interface.cpp
index da9cf0a..07ac29e 100644
--- a/tests/aidl_test_client_versioned_interface.cpp
+++ b/tests/aidl_test_client_versioned_interface.cpp
@@ -44,7 +44,7 @@
 }
 
 TEST_F(VersionedInterfaceTest, getInterfaceHash) {
-  EXPECT_EQ("796b4ab269d476662bed4ab57092ed000e48d5d7", versioned->getInterfaceHash());
+  EXPECT_EQ("4b32bf2134c87894404e935d52c5c64886f23215", versioned->getInterfaceHash());
 }
 
 TEST_F(VersionedInterfaceTest, noProblemWhenPassingAUnionWithOldField) {
diff --git a/tests/aidl_test_service.cpp b/tests/aidl_test_service.cpp
index a4b3c48..23ff693 100644
--- a/tests/aidl_test_service.cpp
+++ b/tests/aidl_test_service.cpp
@@ -638,6 +638,10 @@
     }
     return Status::ok();
   }
+  Status callWithFoo(::android::aidl::versioned::tests::Foo* outFoo) override {
+    (void)outFoo;
+    return Status::ok();
+  }
 };
 
 class LoggableInterfaceService : public android::aidl::loggable::BnLoggableInterface {
diff --git a/tests/java/src/android/aidl/service/TestServiceServer.java b/tests/java/src/android/aidl/service/TestServiceServer.java
index 7b0feeb..9812818 100644
--- a/tests/java/src/android/aidl/service/TestServiceServer.java
+++ b/tests/java/src/android/aidl/service/TestServiceServer.java
@@ -33,12 +33,9 @@
 import android.aidl.tests.extension.ExtendableParcelable;
 import android.aidl.tests.extension.MyExt;
 import android.aidl.versioned.tests.BazUnion;
+import android.aidl.versioned.tests.Foo;
 import android.aidl.versioned.tests.IFooInterface;
-import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
 import android.os.Binder;
-import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Parcel;
 import android.os.ParcelFileDescriptor;
@@ -47,15 +44,11 @@
 import android.os.ServiceManager;
 import android.os.ServiceSpecificException;
 import android.util.Log;
-import java.io.File;
 import java.io.FileDescriptor;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 public class TestServiceServer extends ITestService.Stub {
   public static void main(String[] args) {
@@ -79,6 +72,8 @@
       throw new IllegalArgumentException();
     }
     @Override
+    public void callWithFoo(Foo outFoo) {}
+    @Override
     public final int getInterfaceVersion() {
       return IFooInterface.VERSION;
     }
diff --git a/tests/java/src/android/aidl/tests/TestVersionedInterface.java b/tests/java/src/android/aidl/tests/TestVersionedInterface.java
index 5113d48..4923607 100644
--- a/tests/java/src/android/aidl/tests/TestVersionedInterface.java
+++ b/tests/java/src/android/aidl/tests/TestVersionedInterface.java
@@ -52,7 +52,7 @@
 
     @Test
     public void testGetInterfaceHash() throws RemoteException {
-      assertThat(service.getInterfaceHash(), is("796b4ab269d476662bed4ab57092ed000e48d5d7"));
+      assertThat(service.getInterfaceHash(), is("4b32bf2134c87894404e935d52c5c64886f23215"));
     }
 
     @Rule public ExpectedException expectedException = ExpectedException.none();
diff --git a/tests/rust/test_client.rs b/tests/rust/test_client.rs
index a5f9f6c..0004748 100644
--- a/tests/rust/test_client.rs
+++ b/tests/rust/test_client.rs
@@ -623,7 +623,7 @@
     let hash = service.getInterfaceHash();
     assert_eq!(
         hash.as_ref().map(String::as_str),
-        Ok("796b4ab269d476662bed4ab57092ed000e48d5d7")
+        Ok("4b32bf2134c87894404e935d52c5c64886f23215")
     );
 }
 
diff --git a/tests/rust/test_service.rs b/tests/rust/test_service.rs
index b66390b..7443b76 100644
--- a/tests/rust/test_service.rs
+++ b/tests/rust/test_service.rs
@@ -28,7 +28,8 @@
     self, BinderFeatures, Interface, ParcelFileDescriptor, SpIBinder,
 };
 use aidl_test_versioned_interface::aidl::android::aidl::versioned::tests::{
-    BazUnion::BazUnion, IFooInterface, IFooInterface::BnFooInterface, IFooInterface::BpFooInterface,
+    BazUnion::BazUnion, Foo::Foo, IFooInterface, IFooInterface::BnFooInterface,
+    IFooInterface::BpFooInterface,
 };
 use std::collections::HashMap;
 use std::sync::Mutex;
@@ -320,6 +321,9 @@
             BazUnion::IntNum(n) => Ok(n.to_string()),
         }
     }
+    fn callWithFoo(&self, _out_foo: &mut Foo) -> binder::Result<()> {
+        Ok(())
+    }
 }
 
 fn main() {
diff --git a/tests/versioned/android/aidl/versioned/tests/Foo.aidl b/tests/versioned/android/aidl/versioned/tests/Foo.aidl
new file mode 100644
index 0000000..acf7620
--- /dev/null
+++ b/tests/versioned/android/aidl/versioned/tests/Foo.aidl
@@ -0,0 +1,7 @@
+package android.aidl.versioned.tests;
+
+parcelable Foo {
+    // V1 is empty
+    // V2
+    int intDefault42 = 42;
+}
diff --git a/tests/versioned/android/aidl/versioned/tests/IFooInterface.aidl b/tests/versioned/android/aidl/versioned/tests/IFooInterface.aidl
index d8b88f6..a411da1 100644
--- a/tests/versioned/android/aidl/versioned/tests/IFooInterface.aidl
+++ b/tests/versioned/android/aidl/versioned/tests/IFooInterface.aidl
@@ -1,9 +1,11 @@
 package android.aidl.versioned.tests;
 import android.aidl.versioned.tests.BazUnion;
+import android.aidl.versioned.tests.Foo;
 interface IFooInterface {
     // V1
     void originalApi();
     @utf8InCpp String acceptUnionAndReturnString(in BazUnion u);
+    void callWithFoo(out Foo outFoo);
     // V2
     void newApi();
 }