Merge cherrypicks of [2476230, 2476289, 2476272, 2476118, 2475997, 2476251, 2476119, 2476341, 2476252, 2476290, 2476232, 2476274, 2475999, 2476343, 2476275, 2476216, 2476381, 2476256, 2476000, 2476362, 2476345, 2476364, 2476234, 2476346, 2476347, 2476365, 2476276, 2476219, 2476277, 2476402, 2476348, 2476235, 2476383, 2476257, 2476278, 2476236, 2476350, 2476351, 2476307, 2476403, 2476308, 2476258] into oc-release

Change-Id: I3f43b54320d5428efd9522360bf0f73410ea5fbb
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 397c09c..05b282b 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -1590,16 +1590,23 @@
     out << "default:\n{\n";
     out.indent();
 
-    out << "return onTransact(\n";
+    if (iface->isIBase()) {
+        out << "(void)_hidl_flags;\n";
+        out << "return ::android::UNKNOWN_TRANSACTION;\n";
+    } else {
+        out << "return ";
+        out << gIBaseFqName.getInterfaceStubFqName().cppName();
+        out << "::onTransact(\n";
 
-    out.indent();
-    out.indent();
+        out.indent();
+        out.indent();
 
-    out << "_hidl_code, _hidl_data, _hidl_reply, "
-        << "_hidl_flags, _hidl_cb);\n";
+        out << "_hidl_code, _hidl_data, _hidl_reply, "
+            << "_hidl_flags, _hidl_cb);\n";
 
-    out.unindent();
-    out.unindent();
+        out.unindent();
+        out.unindent();
+    }
 
     out.unindent();
     out << "}\n";
diff --git a/test/hidl_test_client.cpp b/test/hidl_test_client.cpp
index 957e802..e9868e8 100644
--- a/test/hidl_test_client.cpp
+++ b/test/hidl_test_client.cpp
@@ -17,6 +17,8 @@
 #include <android/hardware/tests/foo/1.0/BsSimple.h>
 #include <android/hardware/tests/foo/1.0/BpHwSimple.h>
 #include <android/hardware/tests/bar/1.0/IBar.h>
+#include <android/hardware/tests/bar/1.0/BpHwBar.h>
+#include <android/hardware/tests/bar/1.0/BnHwBar.h>
 #include <android/hardware/tests/bar/1.0/IComplicated.h>
 #include <android/hardware/tests/bar/1.0/IImportRules.h>
 #include <android/hardware/tests/baz/1.0/IBaz.h>
@@ -1554,6 +1556,35 @@
     EXPECT_TRUE(e1 != e3);
 }
 
+TEST_F(HidlTest, InvalidTransactionTest) {
+    using ::android::hardware::tests::bar::V1_0::BnHwBar;
+    using ::android::hardware::tests::bar::V1_0::BpHwBar;
+    using ::android::hardware::IBinder;
+    using ::android::hardware::Parcel;
+    using ::android::status_t;
+    using ::android::OK;
+
+    Parcel request, reply;
+    sp<IBinder> binder;
+    status_t status = request.writeInterfaceToken(::android::hardware::tests::bar::V1_0::IBar::descriptor);
+
+    EXPECT_EQ(status, OK);
+
+    if (mode == BINDERIZED) {
+        EXPECT_TRUE(bar->isRemote());
+        binder = ::android::hardware::toBinder<IBar, BpHwBar>(bar);
+    } else {
+        // For a local test, just wrap the implementation with a BnHwBar
+        binder = new BnHwBar(bar);
+    }
+
+    status = binder->transact(1234, request, &reply);
+
+    EXPECT_EQ(status, ::android::UNKNOWN_TRANSACTION);
+    // Try another call, to make sure nothing is messed up
+    EXPECT_OK(bar->thisIsNew());
+}
+
 #if HIDL_RUN_POINTER_TESTS
 
 TEST_F(HidlTest, PassAGraphTest) {