add test for binder inheritance.

Test: hidl_test
Test: `make hidl_test_java` compiles
Change-Id: Ie9217b79e369f2a1e7a7c9ed02524b17e3fc8b7f
diff --git a/tests/inheritance/1.0/default/Android.bp b/tests/inheritance/1.0/default/Android.bp
new file mode 100644
index 0000000..d97bd83
--- /dev/null
+++ b/tests/inheritance/1.0/default/Android.bp
@@ -0,0 +1,21 @@
+
+
+cc_library_shared {
+    name: "android.hardware.tests.inheritance@1.0-impl",
+    relative_install_path: "hw",
+    srcs: [
+        "Fetcher.cpp",
+        "Parent.cpp",
+        "Child.cpp",
+    ],
+
+    shared_libs: [
+        "libbase",
+        "libhidl",
+        "libhwbinder",
+        "liblog",
+        "libutils",
+        "android.hardware.tests.inheritance@1.0",
+    ],
+
+}
diff --git a/tests/inheritance/1.0/default/Child.cpp b/tests/inheritance/1.0/default/Child.cpp
new file mode 100644
index 0000000..66720b3
--- /dev/null
+++ b/tests/inheritance/1.0/default/Child.cpp
@@ -0,0 +1,42 @@
+#define LOG_TAG "hidl_test"
+#include <android-base/logging.h>
+
+#include "Child.h"
+
+namespace android {
+namespace hardware {
+namespace tests {
+namespace inheritance {
+namespace V1_0 {
+namespace implementation {
+
+// Methods from ::android::hardware::tests::inheritance::V1_0::IGrandparent follow.
+Return<void> Child::doGrandparent()  {
+    ALOGI("SERVER(Bar) Child::doGrandparent");
+    return Void();
+}
+
+// Methods from ::android::hardware::tests::inheritance::V1_0::IParent follow.
+Return<void> Child::doParent()  {
+    ALOGI("SERVER(Bar) Child::doParent");
+    return Void();
+}
+
+
+// Methods from ::android::hardware::tests::inheritance::V1_0::IChild follow.
+Return<void> Child::doChild()  {
+    ALOGI("SERVER(Bar) Child::doChild");
+    return Void();
+}
+
+
+IChild* HIDL_FETCH_IChild(const char* /* name */) {
+    return new Child();
+}
+
+} // namespace implementation
+}  // namespace V1_0
+}  // namespace inheritance
+}  // namespace tests
+}  // namespace hardware
+}  // namespace android
diff --git a/tests/inheritance/1.0/default/Child.h b/tests/inheritance/1.0/default/Child.h
new file mode 100644
index 0000000..0d34e83
--- /dev/null
+++ b/tests/inheritance/1.0/default/Child.h
@@ -0,0 +1,44 @@
+#ifndef HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Child_H_
+#define HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Child_H_
+
+#include <android/hardware/tests/inheritance/1.0/IChild.h>
+#include <hidl/Status.h>
+
+#include <hidl/MQDescriptor.h>
+namespace android {
+namespace hardware {
+namespace tests {
+namespace inheritance {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::tests::inheritance::V1_0::IParent;
+using ::android::hardware::tests::inheritance::V1_0::IChild;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+struct Child : public IChild {
+    // Methods from ::android::hardware::tests::inheritance::V1_0::IGrandparent follow.
+    Return<void> doGrandparent()  override;
+
+    // Methods from ::android::hardware::tests::inheritance::V1_0::IParent follow.
+    Return<void> doParent()  override;
+
+    // Methods from ::android::hardware::tests::inheritance::V1_0::IChild follow.
+    Return<void> doChild()  override;
+
+};
+
+extern "C" IChild* HIDL_FETCH_IChild(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace inheritance
+}  // namespace tests
+}  // namespace hardware
+}  // namespace android
+
+#endif  // HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Child_H_
diff --git a/tests/inheritance/1.0/default/Fetcher.cpp b/tests/inheritance/1.0/default/Fetcher.cpp
new file mode 100644
index 0000000..28dffaa
--- /dev/null
+++ b/tests/inheritance/1.0/default/Fetcher.cpp
@@ -0,0 +1,58 @@
+
+#define LOG_TAG "hidl_test"
+
+#include "Fetcher.h"
+#include <android-base/logging.h>
+#include <inttypes.h>
+
+namespace android {
+namespace hardware {
+namespace tests {
+namespace inheritance {
+namespace V1_0 {
+namespace implementation {
+
+Fetcher::Fetcher() {
+    mPrecious = IChild::getService("local child", true);
+    CHECK(!mPrecious->isRemote());
+}
+
+template <typename CB>
+Return<void> selectService(bool sendRemote, CB &_hidl_cb, sp<IChild> &local) {
+    sp<IChild> toSend;
+    if (sendRemote) {
+        toSend = IChild::getService("child");
+        if (!toSend->isRemote()) {
+            return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE);
+        }
+    } else {
+        toSend = local;
+    }
+    ALOGI("SERVER(Fetcher) selectService returning %p", toSend.get());
+    _hidl_cb(toSend);
+    return Void();
+}
+
+// Methods from ::android::hardware::tests::inheritance::V1_0::IFetcher follow.
+Return<void> Fetcher::getGrandparent(bool sendRemote, getGrandparent_cb _hidl_cb)  {
+    return selectService(sendRemote, _hidl_cb, mPrecious);
+}
+
+Return<void> Fetcher::getParent(bool sendRemote, getParent_cb _hidl_cb)  {
+    return selectService(sendRemote, _hidl_cb, mPrecious);
+}
+
+Return<void> Fetcher::getChild(bool sendRemote, getChild_cb _hidl_cb)  {
+    return selectService(sendRemote, _hidl_cb, mPrecious);
+}
+
+IFetcher* HIDL_FETCH_IFetcher(const char* /* name */) {
+    return new Fetcher();
+}
+
+} // namespace implementation
+}  // namespace V1_0
+}  // namespace inheritance
+}  // namespace tests
+}  // namespace hardware
+}  // namespace android
diff --git a/tests/inheritance/1.0/default/Fetcher.h b/tests/inheritance/1.0/default/Fetcher.h
new file mode 100644
index 0000000..d389853
--- /dev/null
+++ b/tests/inheritance/1.0/default/Fetcher.h
@@ -0,0 +1,45 @@
+#ifndef HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Fetcher_H_
+#define HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Fetcher_H_
+
+#include "Child.h"
+#include <android/hardware/tests/inheritance/1.0/IFetcher.h>
+#include <hidl/Status.h>
+
+#include <hidl/MQDescriptor.h>
+namespace android {
+namespace hardware {
+namespace tests {
+namespace inheritance {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::tests::inheritance::V1_0::IFetcher;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+struct Fetcher : public IFetcher {
+
+    Fetcher();
+
+    // Methods from ::android::hardware::tests::inheritance::V1_0::IFetcher follow.
+    Return<void> getGrandparent(bool sendRemote, getGrandparent_cb _hidl_cb)  override;
+    Return<void> getParent(bool sendRemote, getParent_cb _hidl_cb)  override;
+    Return<void> getChild(bool sendRemote, getChild_cb _hidl_cb)  override;
+
+private:
+    sp<IChild> mPrecious;
+};
+
+extern "C" IFetcher* HIDL_FETCH_IFetcher(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace inheritance
+}  // namespace tests
+}  // namespace hardware
+}  // namespace android
+
+#endif  // HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Fetcher_H_
diff --git a/tests/inheritance/1.0/default/Grandparent.cpp b/tests/inheritance/1.0/default/Grandparent.cpp
new file mode 100644
index 0000000..c53dc87
--- /dev/null
+++ b/tests/inheritance/1.0/default/Grandparent.cpp
@@ -0,0 +1,29 @@
+#define LOG_TAG "hidl_test"
+#include <android-base/logging.h>
+
+#include "Grandparent.h"
+
+namespace android {
+namespace hardware {
+namespace tests {
+namespace inheritance {
+namespace V1_0 {
+namespace implementation {
+
+// Methods from ::android::hardware::tests::inheritance::V1_0::IGrandparent follow.
+Return<void> Grandparent::doGrandparent()  {
+    ALOGI("SERVER(Bar) Grandparent::doGrandparent");
+    return Void();
+}
+
+
+IGrandparent* HIDL_FETCH_IGrandparent(const char* /* name */) {
+    return new Grandparent();
+}
+
+} // namespace implementation
+}  // namespace V1_0
+}  // namespace inheritance
+}  // namespace tests
+}  // namespace hardware
+}  // namespace android
diff --git a/tests/inheritance/1.0/default/Grandparent.h b/tests/inheritance/1.0/default/Grandparent.h
new file mode 100644
index 0000000..e1113bf
--- /dev/null
+++ b/tests/inheritance/1.0/default/Grandparent.h
@@ -0,0 +1,37 @@
+#ifndef HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Grandparent_H_
+#define HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Grandparent_H_
+
+#include <android/hardware/tests/inheritance/1.0/IGrandparent.h>
+#include <hidl/Status.h>
+
+#include <hidl/MQDescriptor.h>
+namespace android {
+namespace hardware {
+namespace tests {
+namespace inheritance {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::tests::inheritance::V1_0::IGrandparent;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+struct Grandparent : public IGrandparent {
+    // Methods from ::android::hardware::tests::inheritance::V1_0::IGrandparent follow.
+    Return<void> doGrandparent()  override;
+
+};
+
+extern "C" IGrandparent* HIDL_FETCH_IGrandparent(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace inheritance
+}  // namespace tests
+}  // namespace hardware
+}  // namespace android
+
+#endif  // HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Grandparent_H_
diff --git a/tests/inheritance/1.0/default/Parent.cpp b/tests/inheritance/1.0/default/Parent.cpp
new file mode 100644
index 0000000..bdd20c9
--- /dev/null
+++ b/tests/inheritance/1.0/default/Parent.cpp
@@ -0,0 +1,35 @@
+#define LOG_TAG "hidl_test"
+#include <android-base/logging.h>
+
+#include "Parent.h"
+
+namespace android {
+namespace hardware {
+namespace tests {
+namespace inheritance {
+namespace V1_0 {
+namespace implementation {
+
+// Methods from ::android::hardware::tests::inheritance::V1_0::IGrandparent follow.
+Return<void> Parent::doGrandparent()  {
+    ALOGI("SERVER(Bar) Parent::doGrandparent");
+    return Void();
+}
+
+// Methods from ::android::hardware::tests::inheritance::V1_0::IParent follow.
+Return<void> Parent::doParent()  {
+    ALOGI("SERVER(Bar) Parent::doParent");
+    return Void();
+}
+
+
+IParent* HIDL_FETCH_IParent(const char* /* name */) {
+    return new Parent();
+}
+
+} // namespace implementation
+}  // namespace V1_0
+}  // namespace inheritance
+}  // namespace tests
+}  // namespace hardware
+}  // namespace android
diff --git a/tests/inheritance/1.0/default/Parent.h b/tests/inheritance/1.0/default/Parent.h
new file mode 100644
index 0000000..2e07fdc
--- /dev/null
+++ b/tests/inheritance/1.0/default/Parent.h
@@ -0,0 +1,40 @@
+#ifndef HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Parent_H_
+#define HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Parent_H_
+
+#include <android/hardware/tests/inheritance/1.0/IParent.h>
+#include <hidl/Status.h>
+
+#include <hidl/MQDescriptor.h>
+namespace android {
+namespace hardware {
+namespace tests {
+namespace inheritance {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::tests::inheritance::V1_0::IParent;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+struct Parent : public IParent {
+    // Methods from ::android::hardware::tests::inheritance::V1_0::IGrandparent follow.
+    Return<void> doGrandparent()  override;
+
+    // Methods from ::android::hardware::tests::inheritance::V1_0::IParent follow.
+    Return<void> doParent()  override;
+
+};
+
+extern "C" IParent* HIDL_FETCH_IParent(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace inheritance
+}  // namespace tests
+}  // namespace hardware
+}  // namespace android
+
+#endif  // HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Parent_H_