Add a name->feature lookup method

... which is useful for Gfxstream to receive a string of feature
enables/disables.

Bug: b/277618864
Test: cvd start --gpu_mode=gfxstream
Change-Id: I5ee6ba159c6ad4951839db5dac0fca87527b6bfd
GitOrigin-RevId: eecdb3d3c118ff96c1e93f825887239aa4b631bb
diff --git a/host-common/feature_control.cpp b/host-common/feature_control.cpp
index 37b92d4..ce01c8b 100644
--- a/host-common/feature_control.cpp
+++ b/host-common/feature_control.cpp
@@ -97,3 +97,26 @@
 
     return it->second.c_str();
 }
+
+
+Feature feature_from_name(const char* name) {
+    if (name == nullptr) {
+        return kFeature_unknown;
+    }
+
+    static const std::unordered_map<std::string, Feature>* const sNameToFeature = [] {
+        return new std::unordered_map<std::string, Feature>({
+#define FEATURE_CONTROL_ITEM(item, idx) { #item, kFeature_##item },
+#include "FeatureControlDefHost.h"
+#include "FeatureControlDefGuest.h"
+#undef FEATURE_CONTROL_ITEM
+        });
+    }();
+
+    auto it = sNameToFeature->find(std::string(name));
+    if (it == sNameToFeature->end()) {
+        return kFeature_unknown;
+    }
+
+    return it->second;
+}
\ No newline at end of file
diff --git a/host-common/include/host-common/feature_control.h b/host-common/include/host-common/feature_control.h
index 07746af..6e466d4 100644
--- a/host-common/include/host-common/feature_control.h
+++ b/host-common/include/host-common/feature_control.h
@@ -51,5 +51,6 @@
 void feature_update_from_server();
 
 const char* feature_name(Feature feature);
+Feature feature_from_name(const char* name);
 
 ANDROID_END_HEADER