Version vendor libprotobuf-cpp-* libraries

Vendor prebuilts reference the protobuf runtime libraries, but the
runtime libraries do not have a stable ABI.  Add a version suffix
to the names of the libraries when used by vendor modules so that
old versions can be left in place when the protobuf version is
updated.

Also adds a test that verifies that the library names match the
version number to ensure the version number gets updated when
protobuf is updated.

Bug: 117607748
Test: libprotobuf_vendor_suffix_test
Change-Id: Iee5bbe95cb898f8ab552028f32e4b40d67f54f23
diff --git a/vendor_suffix_test.cpp b/vendor_suffix_test.cpp
new file mode 100644
index 0000000..bd06422
--- /dev/null
+++ b/vendor_suffix_test.cpp
@@ -0,0 +1,42 @@
+#include <link.h>
+
+#include <string>
+#include <vector>
+
+#include <android-base/stringprintf.h>
+
+#include <gtest/gtest.h>
+
+#include <google/protobuf/message_lite.h>
+
+TEST(vendor_suffix, suffix) {
+    std::vector<std::string> libs;
+    dl_iterate_phdr([](dl_phdr_info* info, size_t, void* data) -> int {
+        auto local_libs = static_cast<decltype(&libs)>(data);
+        std::string name = info->dlpi_name;
+        size_t libprotobuf = name.find("libprotobuf-cpp");
+        if (libprotobuf != name.npos) {
+            local_libs->push_back(name.substr(libprotobuf, name.size()));
+        }
+        return 0;
+    }, &libs);
+
+    std::sort(libs.begin(), libs.end());
+
+    std::string version = android::base::StringPrintf("-%d.%d.%d",
+       GOOGLE_PROTOBUF_VERSION / 1000000,
+       GOOGLE_PROTOBUF_VERSION / 1000 % 1000,
+       GOOGLE_PROTOBUF_VERSION % 1000);
+
+    std::string suffix = GOOGLE_PROTOBUF_VERSION_SUFFIX;
+    if (suffix != "") {
+        version += "-" + suffix;
+    }
+
+    std::vector<std::string> expect = {
+        "libprotobuf-cpp-full" + version + ".so",
+        "libprotobuf-cpp-lite" + version + ".so",
+    };
+
+    ASSERT_EQ(expect, libs);
+}