hwservicemanager: remove unsafe casts

Version x.(y+1) of a service must inherit from version x.y, so the
information of supported versions is already contained in the interface
chain. Because of this, we no longer need to parse interface names, we
can store interfaces using the version as a key, and we no longer need a
multimap.

Bug: 34085897
Test: hidl_test

Change-Id: I6a2ed9899ef1cb9a7ea37b6a3e8092fb9f09544d
diff --git a/ServiceManager.h b/ServiceManager.h
index 92f0782..3319648 100644
--- a/ServiceManager.h
+++ b/ServiceManager.h
@@ -4,7 +4,6 @@
 #include <android/hidl/manager/1.0/IServiceManager.h>
 #include <hidl/Status.h>
 #include <hidl/MQDescriptor.h>
-#include <map>
 #include <unordered_map>
 
 #include "HidlService.h"
@@ -18,7 +17,6 @@
 using ::android::hardware::hidl_death_recipient;
 using ::android::hardware::hidl_vec;
 using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_version;
 using ::android::hardware::Return;
 using ::android::hardware::Void;
 using ::android::hidl::base::V1_0::IBase;
@@ -47,7 +45,7 @@
 private:
     bool remove(const wp<IBase>& who);
 
-    using InstanceMap = std::multimap<
+    using InstanceMap = std::unordered_map<
             std::string, // instance name e.x. "manager"
             std::unique_ptr<HidlService>
         >;
@@ -57,26 +55,15 @@
         const InstanceMap &getInstanceMap() const;
 
         /**
-         * Finds a HidlService which supports the desired version. If none,
+         * Finds a HidlService with the desired name. If none,
          * returns nullptr. HidlService::getService() might also be nullptr
          * if there are registered IServiceNotification objects for it. Return
          * value should be treated as a temporary reference.
          */
-        HidlService *lookupSupporting(
-            const std::string &name,
-            const hidl_version &version);
-        const HidlService *lookupSupporting(
-            const std::string &name,
-            const hidl_version &version) const;
-        /**
-         * Finds a HidlService which is exactly the desired version. If none,
-         * returns nullptr. HidlService::getService() might also be nullptr
-         * if there are registered IServiceNotification objects for it. Return
-         * value should be treated as a temporary reference.
-         */
-        HidlService *lookupExact(
-            const std::string &name,
-            const hidl_version &version);
+        HidlService *lookup(
+            const std::string &name);
+        const HidlService *lookup(
+            const std::string &name) const;
 
         void insertService(std::unique_ptr<HidlService> &&service);
 
@@ -97,11 +84,11 @@
      * is single-threaded.
      *
      * e.x.
-     * mServiceMap["android.hidl.manager::IServiceManager"]["manager"]
+     * mServiceMap["android.hidl.manager@1.0::IServiceManager"]["manager"]
      *     -> HidlService object
      */
     std::unordered_map<
-        std::string, // package::interface e.x. "android.hidl.manager::IServiceManager"
+        std::string, // package::interface e.x. "android.hidl.manager@1.0::IServiceManager"
         PackageInterfaceMap
     > mServiceMap;
 };