Merge "Reland "Check transport before registering.""
diff --git a/transport/HidlBinderSupport.cpp b/transport/HidlBinderSupport.cpp
index f3af124..02d10d0 100644
--- a/transport/HidlBinderSupport.cpp
+++ b/transport/HidlBinderSupport.cpp
@@ -171,22 +171,6 @@
         return status;
     }
 
-    // Skip over fat response headers.  Not used (or propagated) in native code.
-    if (exception == Status::EX_HAS_REPLY_HEADER) {
-        // Note that the header size includes the 4 byte size field.
-        const int32_t header_start = parcel.dataPosition();
-        int32_t header_size;
-        status = parcel.readInt32(&header_size);
-        if (status != OK) {
-            s->setFromStatusT(status);
-            return status;
-        }
-        parcel.setDataPosition(header_start + header_size);
-        // And fat response headers are currently only used when there are no
-        // exceptions, so act like there was no error.
-        exception = Status::EX_NONE;
-    }
-
     if (exception == Status::EX_NONE) {
         *s = Status::ok();
         return status;
diff --git a/transport/HidlLazyUtils.cpp b/transport/HidlLazyUtils.cpp
index 8e3fdf3..08ed676 100644
--- a/transport/HidlLazyUtils.cpp
+++ b/transport/HidlLazyUtils.cpp
@@ -181,6 +181,11 @@
     mImpl = std::make_shared<details::LazyServiceRegistrarImpl>();
 }
 
+LazyServiceRegistrar& LazyServiceRegistrar::getInstance() {
+    static auto registrarInstance = new LazyServiceRegistrar();
+    return *registrarInstance;
+}
+
 status_t LazyServiceRegistrar::registerService(
     const sp<::android::hidl::base::V1_0::IBase>& service, const std::string& name) {
     return mImpl->registerService(service, name);
diff --git a/transport/include/hidl/HidlLazyUtils.h b/transport/include/hidl/HidlLazyUtils.h
index 2205daa..257de98 100644
--- a/transport/include/hidl/HidlLazyUtils.h
+++ b/transport/include/hidl/HidlLazyUtils.h
@@ -29,12 +29,13 @@
 /** Exits when all HALs registered through this object have 0 clients */
 class LazyServiceRegistrar {
    public:
-    LazyServiceRegistrar();
-    status_t registerService(const sp<::android::hidl::base::V1_0::IBase>& service,
-                             const std::string& name = "default");
+     LazyServiceRegistrar();
+     static LazyServiceRegistrar& getInstance();
+     status_t registerService(const sp<::android::hidl::base::V1_0::IBase>& service,
+                              const std::string& name = "default");
 
    private:
-    std::shared_ptr<details::LazyServiceRegistrarImpl> mImpl;
+     std::shared_ptr<details::LazyServiceRegistrarImpl> mImpl;
 };
 
 }  // namespace hardware
diff --git a/transport/include/hidl/LegacySupport.h b/transport/include/hidl/LegacySupport.h
index 0a9feee..fdc5a48 100644
--- a/transport/include/hidl/LegacySupport.h
+++ b/transport/include/hidl/LegacySupport.h
@@ -91,15 +91,6 @@
     return defaultPassthroughServiceImplementation<Interface>("default", maxThreads);
 }
 
-// Make LazyServiceRegistrar static so that multiple calls to
-// registerLazyPassthroughServiceImplementation work as expected: each HAL is registered and the
-// process only exits once all HALs have 0 clients.
-static inline std::shared_ptr<LazyServiceRegistrar> getOrCreateLazyServiceRegistrar() {
-    using android::hardware::LazyServiceRegistrar;
-    static auto serviceCounter(std::make_shared<LazyServiceRegistrar>());
-    return serviceCounter;
-}
-
 /**
  * Registers a passthrough service implementation that exits when there are 0 clients.
  *
@@ -112,10 +103,11 @@
 __attribute__((warn_unused_result)) status_t registerLazyPassthroughServiceImplementation(
     const std::string& name = "default") {
     return details::registerPassthroughServiceImplementation<Interface>(
-        [](const sp<Interface>& service, const std::string& name) {
-            return getOrCreateLazyServiceRegistrar()->registerService(service, name);
-        },
-        name);
+            [](const sp<Interface>& service, const std::string& name) {
+                using android::hardware::LazyServiceRegistrar;
+                return LazyServiceRegistrar::getInstance().registerService(service, name);
+            },
+            name);
 }
 
 /**