Consistently deal with onRegistration() transport errors.

In all cases, we remove the registered callback from our
internal state when a call into it fails.

We also register death recipients for each of the registered
callbacks.

Because of this, a registration callback failing should be
an extremely rare event: it can only happen if a callback
is attempted right after the process dies, but before we have
processed the death notification.

Therefore, log registration callbacks failing as errors, as
it may mean there's more going on.

Bug: 31632518
Bug: 34643534
Test: hidl_test; adb shell stop; manually killing processes with
listeners
Change-Id: I73be10c2c56d1a343f875960535a165531b5c235
diff --git a/ServiceManager.h b/ServiceManager.h
index 349ef5d..0161009 100644
--- a/ServiceManager.h
+++ b/ServiceManager.h
@@ -47,6 +47,8 @@
     virtual void serviceDied(uint64_t cookie, const wp<IBase>& who);
 private:
     bool remove(const wp<IBase>& who);
+    bool removePackageListener(const wp<IBase>& who);
+    bool removeServiceListener(const wp<IBase>& who);
     size_t countExistingService() const;
     void forEachExistingService(std::function<void(const HidlService *)> f) const;
     void forEachServiceEntry(std::function<void(const HidlService *)> f) const;
@@ -74,10 +76,11 @@
         void insertService(std::unique_ptr<HidlService> &&service);
 
         void addPackageListener(sp<IServiceNotification> listener);
+        bool removePackageListener(const wp<IBase>& who);
 
         void sendPackageRegistrationNotification(
             const hidl_string &fqName,
-            const hidl_string &instanceName) const;
+            const hidl_string &instanceName);
 
     private:
         InstanceMap mInstanceMap{};