adb: add adb_get_feature_set.

Extract a feature set getter function from commandline.cpp.

Change-Id: I30a3eb0b060a88379e29be16264637816e378978
diff --git a/adb_client.cpp b/adb_client.cpp
index bbc4dc7..db9b710 100644
--- a/adb_client.cpp
+++ b/adb_client.cpp
@@ -295,3 +295,27 @@
     adb_close(fd);
     return true;
 }
+
+std::string format_host_command(const char* command, TransportType type, const char* serial) {
+    if (serial) {
+        return android::base::StringPrintf("host-serial:%s:%s", serial, command);
+    }
+
+    const char* prefix = "host";
+    if (type == kTransportUsb) {
+        prefix = "host-usb";
+    } else if (type == kTransportLocal) {
+        prefix = "host-local";
+    }
+    return android::base::StringPrintf("%s:%s", prefix, command);
+}
+
+bool adb_get_feature_set(FeatureSet* feature_set, std::string* error) {
+    std::string result;
+    if (adb_query(format_host_command("features", __adb_transport, __adb_serial), &result, error)) {
+        *feature_set = StringToFeatureSet(result);
+        return true;
+    }
+    feature_set->clear();
+    return false;
+}