Move g(Bn|Bs)ConstructorMap's into cpp.

These were originally used to store IFoo::descriptor ->
constructor maps for HIDL code in order to create the
appropriate objects when receiving a binder in HIDL,
but due to static linking of these libraries in recovery
mode, they were moved into functions which create the
static variables and return them (getBnConstructorMap
and getBsConstructorMap). However, old prebuilts still
reference these old variables. In order to remove them,
prebuilt rebuilds need to not reference them, so here,
I have removed all references to them in headers.

Bug: 69122224
Bug: 69408124 # in preparation for this bug
Test: boot Pixel 2, hidl_test
Change-Id: I681d4895f7784bc080e01f4fae2be318ba8d6c0f
diff --git a/transport/HidlBinderSupport.cpp b/transport/HidlBinderSupport.cpp
index f6c7bff..015d607 100644
--- a/transport/HidlBinderSupport.cpp
+++ b/transport/HidlBinderSupport.cpp
@@ -18,6 +18,8 @@
 
 #include <hidl/HidlBinderSupport.h>
 
+#include <InternalStatic.h>  // TODO(b/69122224): remove this include, for getOrCreateCachedBinder
+
 // C includes
 #include <unistd.h>
 
@@ -196,6 +198,42 @@
     return status;
 }
 
+sp<IBinder> getOrCreateCachedBinder(::android::hidl::base::V1_0::IBase* ifacePtr) {
+    LOG_ALWAYS_FATAL_IF(ifacePtr->isRemote(),
+                        "getOrCreateCachedBinder does not have a way to construct remote binders");
+
+    std::string descriptor = details::getDescriptor(ifacePtr);
+    if (descriptor.empty()) {
+        // interfaceDescriptor fails
+        return nullptr;
+    }
+
+    // for get + set
+    std::unique_lock<std::mutex> _lock = details::gBnMap.lock();
+
+    wp<BHwBinder> wBnObj = details::gBnMap.getLocked(ifacePtr, nullptr);
+    sp<IBinder> sBnObj = wBnObj.promote();
+
+    if (sBnObj == nullptr) {
+        auto func = details::getBnConstructorMap().get(descriptor, nullptr);
+        if (!func) {
+            // TODO(b/69122224): remove this static variable when prebuilts updated
+            func = details::gBnConstructorMap.get(descriptor, nullptr);
+            if (!func) {
+                return nullptr;
+            }
+        }
+
+        sBnObj = sp<IBinder>(func(static_cast<void*>(ifacePtr)));
+
+        if (sBnObj != nullptr) {
+            details::gBnMap.setLocked(ifacePtr, static_cast<BHwBinder*>(sBnObj.get()));
+        }
+    }
+
+    return sBnObj;
+}
+
 static bool gThreadPoolConfigured = false;
 
 void configureBinderRpcThreadpool(size_t maxThreads, bool callerWillJoin) {