Merge branch 'security-aosp-qt-release' into int/10/fp2

* security-aosp-qt-release:
  Add automatic default value for primitive type fields

Change-Id: I994a557dc62e4474bb3e7306e420674222e8a42b
diff --git a/Android.bp b/Android.bp
index e60468e..14f2d00 100644
--- a/Android.bp
+++ b/Android.bp
@@ -221,7 +221,9 @@
     manifest: "tests/java_app/AndroidManifest.xml",
     resource_dirs: ["tests/java_app/resources"],
     srcs: [
-        "tests/android/aidl/tests/*.aidl",
+        "tests/android/aidl/tests/ITestService.aidl",
+        "tests/android/aidl/tests/INamedCallback.aidl",
+        "tests/android/aidl/tests/StructuredParcelable.aidl",
         "tests/java_app/src/android/aidl/tests/NullableTests.java",
         "tests/java_app/src/android/aidl/tests/SimpleParcelable.java",
         "tests/java_app/src/android/aidl/tests/TestFailException.java",
@@ -263,4 +265,4 @@
             gen_log: true,
         },
     },
-}
\ No newline at end of file
+}
diff --git a/aidl.cpp b/aidl.cpp
index 8314271..25609c0 100644
--- a/aidl.cpp
+++ b/aidl.cpp
@@ -232,7 +232,14 @@
   }
 
   // Encode that the output file depends on aidl input files.
-  writer->Write("%s : \\\n", output_file.c_str());
+  if (defined_type.AsUnstructuredParcelable() != nullptr &&
+      options.TargetLanguage() == Options::Language::JAVA) {
+    // Legacy behavior. For parcelable declarations in Java, don't emit output file as
+    // the dependency target. b/141372861
+    writer->Write(" : \\\n");
+  } else {
+    writer->Write("%s : \\\n", output_file.c_str());
+  }
   writer->Write("  %s", Join(source_aidl, " \\\n  ").c_str());
   writer->Write("\n");
 
@@ -769,8 +776,13 @@
                          io_delegate);
         success = true;
       } else if (lang == Options::Language::JAVA) {
-        success =
-            java::generate_java(output_file_name, defined_type, &java_types, io_delegate, options);
+        if (defined_type->AsUnstructuredParcelable() != nullptr) {
+          // Legacy behavior. For parcelable declarations in Java, don't generate output file.
+          success = true;
+        } else {
+          success =
+              java::generate_java(output_file_name, defined_type, &java_types, io_delegate, options);
+        }
       } else {
         LOG(FATAL) << "Should not reach here" << endl;
         return 1;
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 3c5c641..7cf8172 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -55,7 +55,14 @@
   p/IFoo.aidl
 )";
 
-const char kExpectedParcelableDepFileContents[] =
+const char kExpectedParcelableDeclarationDepFileContents[] =
+    R"( : \
+  p/Foo.aidl
+
+p/Foo.aidl :
+)";
+
+const char kExpectedStructuredParcelableDepFileContents[] =
     R"(place/for/output/p/Foo.java : \
   p/Foo.aidl
 
@@ -571,7 +578,7 @@
   EXPECT_EQ(actual_dep_file_contents, kExpectedNinjaDepFileContents);
 }
 
-TEST_F(AidlTest, WritesTrivialDependencyFileForParcelable) {
+TEST_F(AidlTest, WritesTrivialDependencyFileForParcelableDeclaration) {
   // The SDK uses aidl to decide whether a .aidl file is a parcelable.  It does
   // this by calling aidl with every .aidl file it finds, then parsing the
   // generated dependency files.  Those that reference .java output files are
@@ -587,7 +594,35 @@
   EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_));
   string actual_dep_file_contents;
   EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents));
-  EXPECT_EQ(actual_dep_file_contents, kExpectedParcelableDepFileContents);
+  EXPECT_EQ(actual_dep_file_contents, kExpectedParcelableDeclarationDepFileContents);
+}
+
+TEST_F(AidlTest, WritesDependencyFileForStructuredParcelable) {
+  vector<string> args = {
+    "aidl",
+    "--structured",
+    "-o place/for/output",
+    "-d dep/file/path",
+    "p/Foo.aidl"};
+  Options options = Options::From(args);
+  io_delegate_.SetFileContents(options.InputFiles().front(), "package p; parcelable Foo {int a;}");
+  EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_));
+  string actual_dep_file_contents;
+  EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents));
+  EXPECT_EQ(actual_dep_file_contents, kExpectedStructuredParcelableDepFileContents);
+}
+
+TEST_F(AidlTest, NoJavaOutputForParcelableDeclaration) {
+ vector<string> args = {
+    "aidl",
+    "--lang=java",
+    "-o place/for/output",
+    "p/Foo.aidl"};
+  Options options = Options::From(args);
+  io_delegate_.SetFileContents(options.InputFiles().front(), "package p; parcelable Foo;");
+  EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_));
+  string output_file_contents;
+  EXPECT_FALSE(io_delegate_.GetWrittenContents(options.OutputFile(), &output_file_contents));
 }
 
 /* not working until type_namespace.h is fixed
diff --git a/generate_java.cpp b/generate_java.cpp
index 777d530..0d96203 100644
--- a/generate_java.cpp
+++ b/generate_java.cpp
@@ -63,14 +63,6 @@
   return true;
 }
 
-bool generate_java_parcel_declaration(const std::string& filename, const IoDelegate& io_delegate) {
-  CodeWriterPtr code_writer = io_delegate.GetCodeWriter(filename);
-  *code_writer
-      << "// This file is intentionally left blank as placeholder for parcel declaration.\n";
-
-  return true;
-}
-
 bool generate_java(const std::string& filename, const AidlDefinedType* defined_type,
                    JavaTypeNamespace* types, const IoDelegate& io_delegate,
                    const Options& options) {
@@ -79,11 +71,6 @@
     return generate_java_parcel(filename, parcelable, types->typenames_, io_delegate);
   }
 
-  const AidlParcelable* parcelable_decl = defined_type->AsParcelable();
-  if (parcelable_decl != nullptr) {
-    return generate_java_parcel_declaration(filename, io_delegate);
-  }
-
   const AidlInterface* interface = defined_type->AsInterface();
   if (interface != nullptr) {
     return generate_java_interface(filename, interface, types, io_delegate, options);