Snap for 7910331 from ca457ce0d9b4666a269b42bb76e06106753ad101 to mainline-neuralnetworks-release
Change-Id: I603ff30e2fe337d9aeeec7ee73cce2cdd9ab06dd
diff --git a/aidl_to_java.cpp b/aidl_to_java.cpp
index 40b01d5..04888fd 100644
--- a/aidl_to_java.cpp
+++ b/aidl_to_java.cpp
@@ -731,11 +731,11 @@
}},
{"IBinder[]",
[](const CodeGeneratorContext& c) {
- c.writer << c.var << " = " << c.parcel << ".createBinderArray();\n";
+ c.writer << c.parcel << ".readBinderArray(" << c.var << ");\n";
}},
{"FileDescriptor[]",
[](const CodeGeneratorContext& c) {
- c.writer << c.var << " = " << c.parcel << ".createRawFileDescriptorArray();\n";
+ c.writer << c.parcel << ".readRawFileDescriptorArray(" << c.var << ");\n";
}},
{"ParcelFileDescriptor",
[](const CodeGeneratorContext& c) {
diff --git a/build/aidl_interface.go b/build/aidl_interface.go
index 251d0d6..80ba3d6 100644
--- a/build/aidl_interface.go
+++ b/build/aidl_interface.go
@@ -40,8 +40,10 @@
langCpp = "cpp"
langJava = "java"
langNdk = "ndk"
- langNdkPlatform = "ndk_platform"
langRust = "rust"
+ // TODO(b/161456198) remove the NDK platform backend as the 'platform' variant of the NDK
+ // backend serves the same purpose.
+ langNdkPlatform = "ndk_platform"
currentVersion = "current"
)
@@ -380,19 +382,18 @@
Cpp struct {
CommonNativeBackendProperties
}
- // Backend of the compiler generating code for C++ clients using
- // libbinder_ndk (stable C interface to system's libbinder)
- // When enabled, this creates a target called "<name>-ndk"
- // (for apps) and "<name>-ndk_platform" (for platform usage).
+ // Backend of the compiler generating code for C++ clients using libbinder_ndk
+ // (stable C interface to system's libbinder) When enabled, this creates a target
+ // called "<name>-V<ver>-ndk" (for both apps and platform) and
+ // "<name>-V<ver>-ndk_platform" (for platform only).
+ // TODO(b/161456198): remove the ndk_platform backend as the ndk backend can serve
+ // the same purpose.
Ndk struct {
CommonNativeBackendProperties
- // Currently, all ndk-supported interfaces generate two variants:
- // - ndk - for apps to use, against an NDK
- // - ndk_platform - for the platform to use
- //
- // This adds an option to disable the 'ndk' variant in cases where APIs
- // only available in the platform version work.
+ // If set to false, the ndk backend is exclusive to platform and is not
+ // available to applications. Default is true (i.e. available to both
+ // applications and platform).
Apps_enabled *bool
}
// Backend of the compiler generating code for Rust clients.
@@ -426,25 +427,27 @@
func (i *aidlInterface) shouldGenerateJavaBackend() bool {
// explicitly true if not specified to give early warning to devs
- return i.properties.Backend.Java.Enabled == nil || *i.properties.Backend.Java.Enabled
+ return proptools.BoolDefault(i.properties.Backend.Java.Enabled, true)
}
func (i *aidlInterface) shouldGenerateCppBackend() bool {
// explicitly true if not specified to give early warning to devs
- return i.properties.Backend.Cpp.Enabled == nil || *i.properties.Backend.Cpp.Enabled
+ return proptools.BoolDefault(i.properties.Backend.Cpp.Enabled, true)
}
func (i *aidlInterface) shouldGenerateNdkBackend() bool {
// explicitly true if not specified to give early warning to devs
+ return proptools.BoolDefault(i.properties.Backend.Ndk.Enabled, true)
return i.properties.Backend.Ndk.Enabled == nil || *i.properties.Backend.Ndk.Enabled
}
+// Returns whether the ndk backend supports applications or not. Default is `true`. `false` is
+// returned only when `apps_enabled` is explicitly set to false. Note that the ndk_platform backend
+// (which will be removed in the future) is not affected by this. In other words, it is always
+// exclusive for the platform, as its name clearly shows.
func (i *aidlInterface) shouldGenerateAppNdkBackend() bool {
- if !i.shouldGenerateNdkBackend() {
- return false
- }
- // explicitly true if not specified to give early warning to devs
- return i.properties.Backend.Ndk.Apps_enabled == nil || *i.properties.Backend.Ndk.Apps_enabled
+ return i.shouldGenerateNdkBackend() &&
+ proptools.BoolDefault(i.properties.Backend.Ndk.Apps_enabled, true)
}
func (i *aidlInterface) shouldGenerateRustBackend() bool {
@@ -685,7 +688,7 @@
nextVersion := i.nextVersion()
shouldGenerateLangBackendMap := map[string]bool{
langCpp: i.shouldGenerateCppBackend(),
- langNdk: i.shouldGenerateAppNdkBackend(),
+ langNdk: i.shouldGenerateNdkBackend(),
langNdkPlatform: i.shouldGenerateNdkBackend(),
langJava: i.shouldGenerateJavaBackend(),
langRust: i.shouldGenerateRustBackend()}
diff --git a/build/aidl_interface_backends.go b/build/aidl_interface_backends.go
index 79b6625..6c778af 100644
--- a/build/aidl_interface_backends.go
+++ b/build/aidl_interface_backends.go
@@ -97,6 +97,19 @@
var cpp_std *string
var hostSupported *bool
var addCflags []string
+ targetProp := ccTargetProperties{
+ // Currently necessary for host builds
+ // TODO(b/31559095): bionic on host should define this
+ // TODO(b/146436251): default isn't applied because the module is created
+ // in PreArchMutators, when import behavior becomes explicit, the logic can
+ // be moved back to LoadHook
+ Host: hostProperties{Cflags: []string{
+ "-D__INTRODUCED_IN(n)=",
+ "-D__assert(a,b,c)=",
+ // We want all the APIs to be available on the host.
+ "-D__ANDROID_API__=10000"}},
+ Darwin: darwinProperties{Enabled: proptools.BoolPtr(false)},
+ }
if lang == langCpp {
importExportDependencies = append(importExportDependencies, "libbinder", "libutils")
@@ -105,23 +118,27 @@
}
hostSupported = i.properties.Host_supported
minSdkVersion = i.properties.Backend.Cpp.Min_sdk_version
- } else if lang == langNdk {
+ } else if lang == langNdk || lang == langNdkPlatform {
importExportDependencies = append(importExportDependencies, "libbinder_ndk")
+ nonAppProps := imageProperties{
+ Cflags: []string{"-DBINDER_STABILITY_SUPPORT"},
+ }
if genTrace {
sharedLibDependency = append(sharedLibDependency, "libandroid")
+ nonAppProps.Exclude_shared_libs = []string{"libandroid"}
+ nonAppProps.Header_libs = []string{"libandroid_aidltrace"}
+ nonAppProps.Shared_libs = []string{"libcutils"}
}
- sdkVersion = proptools.StringPtr("current")
- stl = proptools.StringPtr("c++_shared")
+ targetProp.Platform = nonAppProps
+ targetProp.Vendor = nonAppProps
+ targetProp.Product = nonAppProps
minSdkVersion = i.properties.Backend.Ndk.Min_sdk_version
- } else if lang == langNdkPlatform {
- importExportDependencies = append(importExportDependencies, "libbinder_ndk")
- if genTrace {
- headerLibs = append(headerLibs, "libandroid_aidltrace")
- sharedLibDependency = append(sharedLibDependency, "libcutils")
- }
hostSupported = i.properties.Host_supported
- addCflags = append(addCflags, "-DBINDER_STABILITY_SUPPORT")
- minSdkVersion = i.properties.Backend.Ndk.Min_sdk_version
+ if lang == langNdk && i.shouldGenerateAppNdkBackend() {
+ sdkVersion = proptools.StringPtr("current")
+ // Don't worry! This maps to libc++.so for the platform variant.
+ stl = proptools.StringPtr("c++_shared")
+ }
} else {
panic("Unrecognized language: " + lang)
}
@@ -145,19 +162,6 @@
productAvailable = nil
}
- if lang == langNdk {
- // TODO(b/121157555): when the NDK variant is its own variant, these wouldn't interact,
- // but we can't create a vendor or product version of an NDK variant
- //
- // nil (unspecified) is used instead of false so that this can't conflict with
- // 'vendor: true', for instance.
- vendorAvailable = nil
- odmAvailable = nil
- productAvailable = nil
- overrideVndkProperties.Vndk.Enabled = proptools.BoolPtr(false)
- overrideVndkProperties.Vndk.Support_system_process = proptools.BoolPtr(false)
- }
-
mctx.CreateModule(aidlImplementationGeneratorFactory, &nameProperties{
Name: proptools.StringPtr(cppModuleGen + "-generator"),
}, &aidlImplementationGeneratorProperties{
@@ -186,19 +190,8 @@
Apex_available: commonProperties.Apex_available,
Min_sdk_version: minSdkVersion,
UseApexNameMacro: true,
- Target: ccTargetProperties{
- // Currently necessary for host builds
- // TODO(b/31559095): bionic on host should define this
- // TODO(b/146436251): default isn't applied because the module is created
- // in PreArchMutators, when import behavior becomes explicit, the logic can
- // be moved back to LoadHook
- Host: hostProperties{Cflags: []string{
- "-D__INTRODUCED_IN(n)=",
- "-D__assert(a,b,c)=",
- // We want all the APIs to be available on the host.
- "-D__ANDROID_API__=10000"}},
- Darwin: perTargetProperties{Enabled: proptools.BoolPtr(false)}},
- Tidy: proptools.BoolPtr(true),
+ Target: targetProp,
+ Tidy: proptools.BoolPtr(true),
// Do the tidy check only for the generated headers
Tidy_flags: []string{"--header-filter=" + android.PathForOutput(mctx).String() + ".*"},
Tidy_checks_as_errors: []string{"*"},
@@ -303,7 +296,7 @@
Defaults: []string{"aidl-rust-module-defaults"},
Host_supported: i.properties.Host_supported,
Apex_available: i.properties.Backend.Rust.Apex_available,
- Target: rustTargetProperties{Darwin: perTargetProperties{Enabled: proptools.BoolPtr(false)}},
+ Target: rustTargetProperties{Darwin: darwinProperties{Enabled: proptools.BoolPtr(false)}},
}, &rust.SourceProviderProperties{
Source_stem: proptools.StringPtr(versionedRustName),
}, &aidlRustSourceProviderProperties{
diff --git a/build/properties.go b/build/properties.go
index 69914ed..1b302a9 100644
--- a/build/properties.go
+++ b/build/properties.go
@@ -21,17 +21,28 @@
type hostProperties struct {
Cflags []string
}
-type perTargetProperties struct {
+
+type darwinProperties struct {
Enabled *bool
}
+type imageProperties struct {
+ Shared_libs []string
+ Header_libs []string
+ Exclude_shared_libs []string
+ Cflags []string
+}
+
type ccTargetProperties struct {
- Host hostProperties
- Darwin perTargetProperties
+ Host hostProperties
+ Darwin darwinProperties
+ Platform imageProperties
+ Vendor imageProperties
+ Product imageProperties
}
type rustTargetProperties struct {
- Darwin perTargetProperties
+ Darwin darwinProperties
}
type ccProperties struct {
diff --git a/generate_cpp.cpp b/generate_cpp.cpp
index fcc27b6..619a2f2 100644
--- a/generate_cpp.cpp
+++ b/generate_cpp.cpp
@@ -1227,6 +1227,13 @@
} else {
out << " { ::android::Parcelable::Stability::STABILITY_LOCAL }";
}
+ } else if (auto type = variable->GetType().GetDefinedType(); type) {
+ if (auto enum_type = type->AsEnumDeclaration(); enum_type) {
+ if (!variable->GetType().IsArray()) {
+ // if an enum doesn't have explicit default value, do zero-initialization
+ out << " = " << cppType << "(0)";
+ }
+ }
}
out << ";\n";
diff --git a/generate_ndk.cpp b/generate_ndk.cpp
index c87c5c6..ca8d66c 100644
--- a/generate_ndk.cpp
+++ b/generate_ndk.cpp
@@ -1046,6 +1046,13 @@
}
if (variable->GetDefaultValue()) {
out << " = " << variable->ValueString(ConstantValueDecorator);
+ } else if (auto type = variable->GetType().GetDefinedType(); type) {
+ if (auto enum_type = type->AsEnumDeclaration(); enum_type) {
+ if (!variable->GetType().IsArray()) {
+ // if an enum doesn't have explicit default value, do zero-initialization
+ out << " = " << NdkNameOf(types, variable->GetType(), StorageMode::STACK) << "(0)";
+ }
+ }
}
out << ";\n";
}
diff --git a/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h b/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h
index 795c81a..bfd1e58 100644
--- a/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h
+++ b/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h
@@ -46,9 +46,9 @@
::std::vector<int32_t> shouldContainThreeFs;
int32_t f = int32_t(0);
::std::string shouldBeJerry;
- ::android::aidl::tests::ByteEnum shouldBeByteBar;
- ::android::aidl::tests::IntEnum shouldBeIntBar;
- ::android::aidl::tests::LongEnum shouldBeLongBar;
+ ::android::aidl::tests::ByteEnum shouldBeByteBar = ::android::aidl::tests::ByteEnum(0);
+ ::android::aidl::tests::IntEnum shouldBeIntBar = ::android::aidl::tests::IntEnum(0);
+ ::android::aidl::tests::LongEnum shouldBeLongBar = ::android::aidl::tests::LongEnum(0);
::std::vector<::android::aidl::tests::ByteEnum> shouldContainTwoByteFoos;
::std::vector<::android::aidl::tests::IntEnum> shouldContainTwoIntFoos;
::std::vector<::android::aidl::tests::LongEnum> shouldContainTwoLongFoos;
@@ -80,16 +80,16 @@
::std::vector<int64_t> int64_1 = ::std::vector<int64_t>({1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L});
int32_t hexInt32_pos_1 = int32_t(1);
int32_t hexInt64_pos_1 = int32_t(1);
- ::android::aidl::tests::ConstantExpressionEnum const_exprs_1;
- ::android::aidl::tests::ConstantExpressionEnum const_exprs_2;
- ::android::aidl::tests::ConstantExpressionEnum const_exprs_3;
- ::android::aidl::tests::ConstantExpressionEnum const_exprs_4;
- ::android::aidl::tests::ConstantExpressionEnum const_exprs_5;
- ::android::aidl::tests::ConstantExpressionEnum const_exprs_6;
- ::android::aidl::tests::ConstantExpressionEnum const_exprs_7;
- ::android::aidl::tests::ConstantExpressionEnum const_exprs_8;
- ::android::aidl::tests::ConstantExpressionEnum const_exprs_9;
- ::android::aidl::tests::ConstantExpressionEnum const_exprs_10;
+ ::android::aidl::tests::ConstantExpressionEnum const_exprs_1 = ::android::aidl::tests::ConstantExpressionEnum(0);
+ ::android::aidl::tests::ConstantExpressionEnum const_exprs_2 = ::android::aidl::tests::ConstantExpressionEnum(0);
+ ::android::aidl::tests::ConstantExpressionEnum const_exprs_3 = ::android::aidl::tests::ConstantExpressionEnum(0);
+ ::android::aidl::tests::ConstantExpressionEnum const_exprs_4 = ::android::aidl::tests::ConstantExpressionEnum(0);
+ ::android::aidl::tests::ConstantExpressionEnum const_exprs_5 = ::android::aidl::tests::ConstantExpressionEnum(0);
+ ::android::aidl::tests::ConstantExpressionEnum const_exprs_6 = ::android::aidl::tests::ConstantExpressionEnum(0);
+ ::android::aidl::tests::ConstantExpressionEnum const_exprs_7 = ::android::aidl::tests::ConstantExpressionEnum(0);
+ ::android::aidl::tests::ConstantExpressionEnum const_exprs_8 = ::android::aidl::tests::ConstantExpressionEnum(0);
+ ::android::aidl::tests::ConstantExpressionEnum const_exprs_9 = ::android::aidl::tests::ConstantExpressionEnum(0);
+ ::android::aidl::tests::ConstantExpressionEnum const_exprs_10 = ::android::aidl::tests::ConstantExpressionEnum(0);
::std::string addString1 = ::std::string("hello world!");
::std::string addString2 = ::std::string("The quick brown fox jumps over the lazy dog.");
int32_t shouldSetBit0AndBit2 = int32_t(0);
diff --git a/tests/golden_output/aidl-test-interface-ndk_platform-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h b/tests/golden_output/aidl-test-interface-ndk_platform-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h
index 01fd7a3..b665af5 100644
--- a/tests/golden_output/aidl-test-interface-ndk_platform-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h
+++ b/tests/golden_output/aidl-test-interface-ndk_platform-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h
@@ -27,9 +27,9 @@
std::vector<int32_t> shouldContainThreeFs;
int32_t f = 0;
std::string shouldBeJerry;
- ::aidl::android::aidl::tests::ByteEnum shouldBeByteBar;
- ::aidl::android::aidl::tests::IntEnum shouldBeIntBar;
- ::aidl::android::aidl::tests::LongEnum shouldBeLongBar;
+ ::aidl::android::aidl::tests::ByteEnum shouldBeByteBar = ::aidl::android::aidl::tests::ByteEnum(0);
+ ::aidl::android::aidl::tests::IntEnum shouldBeIntBar = ::aidl::android::aidl::tests::IntEnum(0);
+ ::aidl::android::aidl::tests::LongEnum shouldBeLongBar = ::aidl::android::aidl::tests::LongEnum(0);
std::vector<::aidl::android::aidl::tests::ByteEnum> shouldContainTwoByteFoos;
std::vector<::aidl::android::aidl::tests::IntEnum> shouldContainTwoIntFoos;
std::vector<::aidl::android::aidl::tests::LongEnum> shouldContainTwoLongFoos;
@@ -61,16 +61,16 @@
std::vector<int64_t> int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
int32_t hexInt32_pos_1 = 1;
int32_t hexInt64_pos_1 = 1;
- ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_1;
- ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_2;
- ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_3;
- ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_4;
- ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_5;
- ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_6;
- ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_7;
- ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_8;
- ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_9;
- ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_10;
+ ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_1 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
+ ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_2 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
+ ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_3 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
+ ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_4 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
+ ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_5 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
+ ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_6 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
+ ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_7 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
+ ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_8 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
+ ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_9 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
+ ::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_10 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
std::string addString1 = "hello world!";
std::string addString2 = "The quick brown fox jumps over the lazy dog.";
int32_t shouldSetBit0AndBit2 = 0;