Merge cherrypicks of [17395476] into rvc-platform-release.
Change-Id: I10c22cbab8da6717c0f961bc4c0d189c817b9418
diff --git a/generate_cpp.cpp b/generate_cpp.cpp
index bbee9b3..b9b2d12 100644
--- a/generate_cpp.cpp
+++ b/generate_cpp.cpp
@@ -1118,6 +1118,9 @@
out << " = " << cppType << "(0)";
}
}
+ } else if (AidlTypenames::IsPrimitiveTypename(variable->GetType().GetName()) &&
+ !variable->GetType().IsArray()) {
+ out << " = {}";
}
out << ";\n";
diff --git a/generate_ndk.cpp b/generate_ndk.cpp
index 0efd7eb..d8a29aa 100644
--- a/generate_ndk.cpp
+++ b/generate_ndk.cpp
@@ -886,6 +886,9 @@
out << " = " << NdkNameOf(types, variable->GetType(), StorageMode::STACK) << "(0)";
}
}
+ } else if (AidlTypenames::IsPrimitiveTypename(variable->GetType().GetName()) &&
+ !variable->GetType().IsArray()) {
+ out << " = {}";
}
out << ";\n";
}
diff --git a/tests/android/aidl/tests/StructuredParcelable.aidl b/tests/android/aidl/tests/StructuredParcelable.aidl
index 28046e2..0908782 100644
--- a/tests/android/aidl/tests/StructuredParcelable.aidl
+++ b/tests/android/aidl/tests/StructuredParcelable.aidl
@@ -158,5 +158,16 @@
// String expressions
@utf8InCpp String addString1 = "hello" + " world!";
@utf8InCpp String addString2 = "The quick brown fox jumps " + "over the lazy dog.";
+
+ // primitive types will be initialized with {}.
+ boolean aBoolean;
+ byte aByte;
+ char aChar;
+ int anInt;
+ long aLong;
+ float aFloat;
+ double aDouble;
+ // arrays are not primitive type.
+ int[] anIntArray;
}